+/EE360P
distributed systems
git clone https://git.julia.blue/+/EE360P
7910ba6
master
1package snapshot ; 2import java .util .*; 3import dist .*; 4public class RecvCamera extends MyProcess implements Camera { 5Color myColor =Color .white ; 6boolean closed []; 7LinkedList chan [] =null ; 8int n =neighbors .size (); 9public RecvCamera (MsgHandler initComm ) { 10super (initComm ); 11closed =new boolean [n ];Arrays .fill (closed ,false ); 12chan =new LinkedList [n ]; 13for (int i =0 ;i <n ;i ++) 14chan [i ] =new LinkedList (); 15 } 16public synchronized void globalState () { 17myColor =Color .red ; 18 ((CamUser )app ).localState ();// record local State; 19sendMsg (neighbors ,"marker" ,myId );// send Markers 20 } 21public synchronized void handleMsg (Msg m ,int src ,String tag ) { 22int nid =neighbors .indexOf (src ); 23if (tag .equals ("marker" )) { 24if (myColor ==Color .white )globalState (); 25closed [nid ] =true ; 26if (isDone ()) 27for (int i =0 ;i <n ;i ++) 28System .out .println (chan [i ].toString ()); 29 }else {// application message 30if ((myColor ==Color .red ) && (!closed [nid ])) 31chan [nid ].add (m ); 32app .handleMsg (m ,src ,tag );// give it to app 33 } 34 } 35boolean isDone () { 36if (myColor ==Color .white )return false ; 37for (int i =0 ;i <n ;i ++) 38if (!closed [i ])return false ; 39return true ; 40 } 41}