diff src/fdl/FederatedLinda.java @ 19:0243987383b7

Meta Protocol Engine and sample implementation of event logger. ComDebug_Client needs fixes.
author kono
date Tue, 19 Aug 2008 05:33:32 +0900
parents 609b288f47f9
children fac6e0073b1a
line wrap: on
line diff
--- a/src/fdl/FederatedLinda.java	Mon Aug 18 09:36:13 2008 +0900
+++ b/src/fdl/FederatedLinda.java	Tue Aug 19 05:33:32 2008 +0900
@@ -15,7 +15,6 @@
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
-import java.nio.CharBuffer;
 import java.nio.channels.ClosedSelectorException;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
@@ -46,7 +45,7 @@
 	public int tid;
 	public int seq;
 	public int qsize;
-	public PSXLinda linda;
+	public PSXLindaInterface linda;
 
 	public Selector selector;
 
@@ -68,12 +67,12 @@
 		seqHash =  new Hashtable<Integer, PSXReply>();
 	}
 
-	public PSXLinda open(String _host,int _port) 
+	public PSXLindaInterface open(String _host,int _port) 
 	throws IOException {
 		tid++;
 		// System.out.print("Tid = ");
 		// System.out.println(tid);
-		PSXLinda newlinda = new PSXLinda(this,tid,_host,_port);
+		PSXLindaInterface newlinda = new PSXLinda(this,tid,_host,_port);
 		linda = newlinda.add(linda);
 		return linda;
 	}
@@ -173,118 +172,6 @@
 		return key_num;
 	}
 
-	public int sync_com(long mtimeout) 
-	throws IOException {
-		int key_num = 0;
-		Set<SelectionKey> keys;
-
-		while (q_top != null){
-			PSXQueue c = q_top;
-			c.Send();
-			q_top = c.next;
-			// psx_free(c);
-			// q_top = c = t;
-			qsize--;
-		}
-
-		try {
-			key_num = selector.select(mtimeout);
-			keys = selector.selectedKeys();
-			for (SelectionKey key : keys) {
-				SocketChannel sock = (SocketChannel)key.channel();
-				chkCom(sock);
-			}
-		} catch (IOException e) {
-			e.printStackTrace();
-		} catch (ClosedSelectorException e) {
-			e.printStackTrace();
-		}
-
-		return key_num;
-	}
-
-//	should be in PSXLinda, but sock->linda is unknown here
-
-	private void chkCom(SocketChannel sock)  throws IOException {
-
-		int length;
-		ByteBuffer command = ByteBuffer.allocate(PSX.LINDA_HEADER_SIZE);
-		command.order(ByteOrder.BIG_ENDIAN);
-		debug = false;
-
-		sock.read(command);
-		command.rewind();
-		length =  command.getInt(PSX.LINDA_DATA_LENGTH_OFFSET);
-		if (length>0) {
-			ByteBuffer data = ByteBuffer.allocate(length);
-			int read = length;
-			if (debug) {
-				System.out.print("reading:");
-				System.out.println(length);
-			}
-
-			data.order(ByteOrder.BIG_ENDIAN);
-			while(read>0) {
-				read -= sock.read(data);
-			}
-			data.rewind();
-
-			if (debug) {
-				PSX.printCommand(command, data);
-			}
-			//if (debug_com) {
-			String comdata ="";
-			CharBuffer chardata = data.asCharBuffer();
-			comdata = chardata.toString();
-
-			//System.out.println("Com_data =>");
-			System.out.println(comdata);
-			//}
-			/***if (debug) {
-    	    	System.out.print("header:");
-    	    	for(int i=0;i<LINDA_HEADER_SIZE;i++) {
-    	    		System.out.println(command.get(i));
-    	    	}
-    	    	System.out.print("data:");
-    	    	for(int i=0;i<length;i++) {
-    	    		System.out.println(data.get(i));
-    	    	}
-    	    	data.rewind();
-    	    }***/
-
-			int rseq = command.getInt(PSX.LINDA_SEQ_OFFSET);
-			int mode = command.get(PSX.LINDA_MODE_OFFSET);
-			Integer a;
-			/***
-    	    if (debug) {
-    	    	System.out.print("mode = ");
-    	    	System.out.println(mode);
-    	    	System.out.print("seq = ");
-    	    	System.out.println(rseq);
-    	    }***/
-			try {
-				PSXReply r = seqHash.get((a = new Integer(rseq)));
-				seqHash.put(a, null);
-				if (debug) {
-					System.out.print("hash value = ");
-					System.out.println(a.hashCode());
-				}
-
-				r.setAnswer(mode,command,data);
-
-				if (r.callback != null ) {
-					r.callback.callback(data);
-				}
-			} catch (NullPointerException e ) {
-				if (debug) {
-					System.out.println("hashed reply not found");
-				}
-				// can't happen
-				return ;
-			}
-		}
-	}
-
 	private void chkServe(SocketChannel sock) 
 	throws IOException {
 		int length;
@@ -335,7 +222,7 @@
 	    }***/
 			try {
 				PSXReply r = seqHash.get((a = new Integer(rseq)));
-				seqHash.put(a, null); // should be clear or delete
+				seqHash.remove(a);
 				if (debug) {
 					System.out.print("hash value = ");
 					System.out.println(a.hashCode());