view rep/SessionList.java @ 1:3f5bf0255f5e

*** empty log message ***
author pin
date Wed, 21 Feb 2007 15:08:52 +0900
parents e41994ce73c7
children 02fa9a68d9a2
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<Integer, Session> session3 = new Hashtable<Integer, Session>();
	private int sessionID = 0;
	private int editorCount = 0;

	private SocketChannel smchannel;
	
	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();
		session3.put(sessionID, new Session(sessionID, string, channel));
		return sessionID; 
		
	}

	public void addEditor(SocketChannel channel, int sid, REPCommand repCmd) {
		int editorID = repCmd.eid;
		//editorCount++;
		//sessions.get(sid-1).add(channel);
		//sessions2.get(sid).add(channel);
		session3.get(sid).addEditor(editorID, 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);
		LinkedList <Editor> editorList = session3.get(repCmd.sid).getEditorList();
		for(Editor editor : editorList){
			SocketChannel channel = editor.getChannel();
			if(channel.equals(channel2)) {
				System.out.println("equals");
				continue;
			}
			REPPacketSend repSend = new REPPacketSend(channel);
			repSend.send(repCmd);
		}
	}

	public void addSessionManager(SocketChannel channel, REPCommand repCmd) {
		smchannel = channel;
		
	}

	public void sendAddedSession(REPCommand repCmd) {
		// TODO Auto-generated method stub
		repCmd.setCMD(REP.SMCMD_SESSION_JOIN);
		REPPacketSend repSend = new REPPacketSend(smchannel);
		//repSend.send(repCmd);
	}

}