+/EE360P
distributed systems
git clone https://git.julia.blue/+/EE360P
7910ba6
master
1package dist ; 2import java .util .*;import java .io .*; 3public class MyProcess implements MsgHandler { 4public int myId ; 5public int n ;// number of neighbors including myself 6public int N ;// total number of nodes in the system 7public MsgHandler app =null ;// upper layer 8MsgHandler comm =null ;// lower layer 9public boolean debug =true ; 10public boolean appFinished =false ; 11//public Properties prop = new Properties(); 12public List <Integer >neighbors =new ArrayList <Integer >(); 13public MyProcess (MsgHandler initComm ) { 14comm =initComm ; 15myId =comm .getMyId (); 16neighbors =comm .getNeighbors (); 17n =neighbors .size () +1 ; 18N =n ;// total number as known to me 19//prop = comm.getProp(); 20 } 21public void init (MsgHandler app ){ 22this .app =app ; 23comm .init (this ); 24 } 25public synchronized void handleMsg (Msg m ,int src ,String tag ){} 26// public synchronized void executeMsg(Msg m) { 27// handleMsg(m, m.src, m.tag); 28// notifyAll(); 29// //if (app != null) app.executeMsg(m); 30// } 31public void sendMsg (int destId ,Object ...objects ) { 32comm .sendMsg (destId ,objects ); 33//if (debug) System.out.println("Process "+ myId + " sends " + objects + " to " + destId); 34 } 35public void sendMsg (List <Integer >destIds ,Object ...objects ) { 36for (int i :destIds ) 37if (i !=myId ) 38sendMsg (i ,objects ); 39 } 40//public void broadcastMsg(String tag, int msg) { 41//sendMsg(neighbors, tag, msg); 42//} 43public synchronized int getMyId () {return myId ; } 44//public Properties getProp() { return prop;} 45public synchronized void myWait () { 46try {wait (); 47 }catch (InterruptedException e ) { 48System .err .println (e ); 49 } 50 } 51public static void println (String s ) { 52System .out .println (s ); 53 } 54public List <Integer >getNeighbors () {return comm .getNeighbors (); } 55public void close () { 56comm .close (); 57 } 58public void turnPassive () { 59comm .turnPassive (); 60 } 61}