view src/fdl/MetaLinda.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 source


/*
 * @(#)MetaLinda.java       1.1 06/04/01
 *
 * Copyright 2008  Shinji KONO
 * 

   Meta Lidna
     Trasport layer of Meta Linda API

 */

package fdl;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.LinkedList;

/**
 MetaLinda 
 *
 * @author Shinji Kono
 *

   meta tuple interface in Linda Server

 */

public class MetaLinda implements PSXLindaInterface {

	public TupleSpace ts;
	public FDLindaServ fds;
	public FederatedLinda fdl;
	public PSXLindaInterface next;
	public LinkedList<MetaReply> replies;

	public MetaLinda(TupleSpace ts,FDLindaServ fdl) {
		this.ts = ts;
		this.fds = fdl;
	}

	public PSXReply in(int id) {
		return null;
	}

	public void in(int id, PSXCallback callback) {
		replies.add(new MetaReply(PSX.PSX_IN,id,ts, callback));
	}

	public PSXReply ck(int id) {
		MetaReply r = new MetaReply(PSX.PSX_CHECK,id,ts);
		return r;
	}

	public void ck(int id, PSXCallback callback) {
		replies.add(new MetaReply(PSX.PSX_CHECK,id,ts,callback));
	}

	public PSXReply out(int id, ByteBuffer data,int size) {
		MetaReply r = new MetaReply(PSX.PSX_OUT,id,ts,data,null);
		replies.add(r);
		return r;
	}

	public PSXReply update(int id, ByteBuffer data,int size) {
		MetaReply r = new MetaReply(PSX.PSX_UPDATE,id,ts,data,null);
		return r;
	}

	public void update(int id, ByteBuffer data,int size,PSXCallback callback) {
		MetaReply r = new MetaReply(PSX.PSX_UPDATE,id,ts,data,callback);
		replies.add(r);
	}

	public PSXReply rd(int id) {
		MetaReply r = new MetaReply(PSX.PSX_RD,id,ts);
		return r;
	}

	public void rd(int id, PSXCallback callback) {
		replies.add(new MetaReply(PSX.PSX_RD,id,ts,callback));
	}

	public PSXLindaInterface add(PSXLindaInterface linda) {
		next = linda;
		return this;
	}

	public void send(ByteBuffer command,ByteBuffer data) {
	}

	public int sync() {
		return sync(0);
	}

	public int sync(long timeout) {
		fds.checkTuple(timeout);
		for(MetaReply r: replies) {
			if (r.ready()) {
				replies.remove();
			}
		}
		if (fdl!=null) {
			try {
				fdl.sync(timeout);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return 0;
	}
}


/* end */