view src/pathfinder/mergetest/NetworkSimulatorwithoutSeMa.java @ 153:6326e5ea4595

*** empty log message ***
author pin
date Sat, 23 Aug 2008 11:28:16 +0900
parents 34b15dfcb83e
children
line wrap: on
line source

package pathfinder.mergetest;

import java.util.LinkedList;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class NetworkSimulatorwithoutSeMa<P> extends NetworkSimulator<P> {
	/** Established connection */
	private LinkedList<ChannelSimulator<P>> connectedList;

	public NetworkSimulatorwithoutSeMa(){
		connectedList = new LinkedList<ChannelSimulator<P>>();
	}

	/**
	 * Request to connect.
	 * Client editor use this method to connect SeMa. 
	 * @param cs
	 */
	public ChannelSimulator<P> connect(){
		ChannelSimulator<P> cs;
		if (connectedList.isEmpty()){
			BlockingQueue<P> q = new LinkedBlockingQueue<P>();
			cs = new ChannelSimulator<P>(this, q, q);
		}else{
			BlockingQueue<P> rq = connectedList.getLast().getWriteQ();
			BlockingQueue<P> wq = new LinkedBlockingQueue<P>();
			connectedList.getFirst().setReadQ(wq);
			
/*			ChannelSimulator<P> lastcs = connectedList.getLast();
			BlockingQueue<P> rq = lastcs.getWriteQ();

			BlockingQueue<P> wq = new LinkedBlockingQueue<P>();
			ChannelSimulator<P> firstcs = connectedList.getFirst();
			firstcs.setReadQ(wq);
*/
			cs = new ChannelSimulator<P>(this, rq, wq);
		}

		connectedList.addLast(cs);
		return cs;
	}
	
	public ChannelSimulator<P> accept(){
		return null;
	}

	public boolean checkAllCS(){
		for(ChannelSimulator<P> cs: connectedList){
			if(!cs.readQisEmpty()) return false;
		}
		return true;
	}

	public ChannelSimulator<P> getAcceptedSession(int i) {
		// TODO Auto-generated method stub
		return connectedList.get(i);
	}
	
}