view rep/SessionList.java @ 0:e41994ce73c7

*** empty log message ***
author pin
date Tue, 13 Feb 2007 04:43:30 +0900
parents
children 3f5bf0255f5e
line wrap: on
line source

package rep;

import java.nio.channels.SocketChannel;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;

public class SessionList {
	
	//List<LinkedList<SocketChannel>> sessions = new LinkedList<LinkedList<SocketChannel>>();
	Hashtable<Integer, LinkedList<SocketChannel>> sessions2 = new Hashtable<Integer, LinkedList<SocketChannel>>();
	//Hashtable editors = new Hashtable();
	private int sessionID;

	private int editorCount;
	
	public void add(SocketChannel channel) {
		
	}

	public int getEditorNumber() {
		return 0;
		
	}

	public void add(SocketChannel channel, int sid) {
		
	}

	public int addSession(SocketChannel channel, String string) {
		sessionID++;
		sessions2.put(sessionID, new LinkedList<SocketChannel>());
		//sessions.add(new LinkedList<SocketChannel>());
		//return sessions2.size();
		return sessionID; 
		
	}

	public void addEditor(SocketChannel channel, int sid) {
		//editorCount++;
		//sessions.get(sid-1).add(channel);
		sessions2.get(sid).add(channel);
	}

	public int getSessionID(SocketChannel channel) {
		return 0;
	}

	public int getNumberOfEditor() {
		editorCount++;
		return editorCount;
	}

	public void sendCmd(SocketChannel channel2, REPCommand repCmd) {
		//int sessionID = repCmd.sid;
		LinkedList <SocketChannel> channelList = sessions2.get(repCmd.sid);
		for(SocketChannel channel : channelList){
			if(channel.equals(channel2)) {
				System.out.println("equals");
				continue;
			}
			REPPacketSend repSend = new REPPacketSend(channel);
			repSend.send(repCmd);
		}
	}

}