diff src/fdl/MetaLinda.java @ 26:d7d70edc9c7c

META_STOP worked.
author kono
date Wed, 20 Aug 2008 17:05:33 +0900
parents 330fa49bc4fd
children 1acf423ffdcb
line wrap: on
line diff
--- a/src/fdl/MetaLinda.java	Wed Aug 20 14:12:15 2008 +0900
+++ b/src/fdl/MetaLinda.java	Wed Aug 20 17:05:33 2008 +0900
@@ -32,7 +32,8 @@
 	public FDLindaServ fds;
 	public FederatedLinda fdl=null;
 	public PSXLinda next=null;
-	public LinkedList<MetaReply> replies = new LinkedList<MetaReply>();
+	private MetaReply replies=new MetaReply(0, 0, ts);
+	private MetaReply last=replies;
 
 	public MetaLinda(TupleSpace ts,FDLindaServ fds) {
 		this.ts = ts;
@@ -44,7 +45,12 @@
 	}
 
 	public void in(int id, PSXCallback callback) {
-		replies.add(new MetaReply(PSX.PSX_IN,id,ts, callback));
+		MetaReply r = new MetaReply(PSX.PSX_IN,id,ts, callback);
+		addReply(r);
+	}
+
+	private void addReply(MetaReply r) {
+		last.next = r; last = r;
 	}
 
 	public PSXReply ck(int id) {
@@ -53,12 +59,13 @@
 	}
 
 	public void ck(int id, PSXCallback callback) {
-		replies.add(new MetaReply(PSX.PSX_CHECK,id,ts,callback));
+		MetaReply r = new MetaReply(PSX.PSX_CHECK,id,ts,callback);
+		addReply(r);
 	}
 
 	public PSXReply out(int id, ByteBuffer data) {
 		MetaReply r = new MetaReply(PSX.PSX_OUT,id,ts,data,null);
-		replies.add(r);
+		addReply(r);
 		return r;
 	}
 
@@ -69,7 +76,7 @@
 
 	public void update(int id, ByteBuffer data,PSXCallback callback) {
 		MetaReply r = new MetaReply(PSX.PSX_UPDATE,id,ts,data,callback);
-		replies.add(r);
+		addReply(r);
 	}
 
 	public PSXReply rd(int id) {
@@ -78,7 +85,8 @@
 	}
 
 	public void rd(int id, PSXCallback callback) {
-		replies.add(new MetaReply(PSX.PSX_RD,id,ts,callback));
+		MetaReply r = new MetaReply(PSX.PSX_RD,id,ts,callback);
+		addReply(r);
 	}
 
 	public PSXLinda add(PSXLinda linda) {
@@ -93,10 +101,11 @@
 
 	public int sync(long timeout) {
 		fds.checkTuple(timeout);
-		for(MetaReply r: replies) {
-			if (r.ready()) {
-				replies.remove();
+		for(PSXReply r=replies;r!=null&&r.next!=null;r = r.next) {
+			if (r.next.ready()) {
+				r.next = r.next.next;
 			}
+			if(r!=null)	last = (MetaReply)r;
 		}
 		if (fdl!=null) {
 			try {