changeset 101:d671c78d3757 fuchita

share selector in FDLindaServe and FederatedLinda
author one
date Wed, 26 May 2010 15:57:23 +0900
parents 270093b61001
children 3b000c4a4d31
files src/fdl/FederatedLinda.java src/fdl/MetaLinda.java
diffstat 2 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/fdl/FederatedLinda.java	Wed May 26 15:45:56 2010 +0900
+++ b/src/fdl/FederatedLinda.java	Wed May 26 15:57:23 2010 +0900
@@ -17,6 +17,7 @@
 import java.nio.channels.ClosedSelectorException;
 import java.nio.channels.SelectionKey;
 import java.nio.channels.Selector;
+import java.nio.channels.spi.AbstractSelector;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.logging.Level;
@@ -49,20 +50,28 @@
 
 	public PSXQueue q_top,q_end;
 	public PSXReply r_top,r_end;
-	public Hashtable<Integer,PSXReply> seqHash;
+	public Hashtable<Integer,PSXReply> seqHash = new Hashtable<Integer, PSXReply>();
 
 	public static FederatedLinda init() {
 		FederatedLinda fdl = new FederatedLinda();
 		return fdl;
 	}
 
+	public static FederatedLinda init(Selector selector) {
+		FederatedLinda fdl = new FederatedLinda(selector);
+		return fdl;
+	}
+	
 	private FederatedLinda() {
 		try {
 			selector = Selector.open();
 		} catch (IOException e) {
 			e.printStackTrace();
 		}
-		seqHash =  new Hashtable<Integer, PSXReply>();
+	}
+
+	public FederatedLinda(Selector selector) {
+		this.selector = selector;
 	}
 
 	public PSXLinda open(String _host,int _port) 
@@ -222,6 +231,7 @@
 	public void wakeup() {
 		selector.wakeup();		
 	}
+
 }
 
 /* end */
--- a/src/fdl/MetaLinda.java	Wed May 26 15:45:56 2010 +0900
+++ b/src/fdl/MetaLinda.java	Wed May 26 15:57:23 2010 +0900
@@ -30,13 +30,14 @@
 
 	public TupleSpace ts;
 	public FDLindaServ fds;
-	public FederatedLinda fdl=FederatedLinda.init();
+	public FederatedLinda fdl;
 	public PSXLinda next=null;
 	public LinkedList<MetaReply> replies=new LinkedList<MetaReply>();
 
 	public MetaLinda(TupleSpace ts,FDLindaServ fds) {
 		this.ts = ts;
 		this.fds = fds;
+		fdl=FederatedLinda.init(fds.selector);
 	}
 
 	public PSXLinda open(String _host,int _port) 
@@ -115,7 +116,7 @@
 	 * Meta Sync with no wait
 	 */
 	public int sync() {
-		fdl.sync();
+		fdl.queueExec();
 		fds.checkTuple(); // fdl sync is also handled here
 		return metaSync();
 	}
@@ -125,7 +126,7 @@
 	 * @param timeout wait timeout msec, if 0 wait indefinitely
 	 */
 	public int sync(long timeout) {
-		fdl.sync();
+		fdl.queueExec();
 		fds.checkTuple(timeout); // fdl sync is also handled here
 		return metaSync();
 	}