+/EE360P

distributed systems

git clone https://git.julia.blue/+/EE360P

vijaygarg1init7910ba6

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