view rep/handler/REPSessionManagerHandler.java @ 316:77f443f6dc9f

add session manager channel handler
author kono
date Tue, 07 Oct 2008 18:15:33 +0900
parents
children dfed28488274
line wrap: on
line source

package rep.handler;

import java.io.IOException;

import rep.Forwarder;
import rep.REPCommand;
import rep.Session;
import rep.SessionManager;
import rep.channel.REPSelectionKey;
import rep.channel.REPSocketChannel;

public class REPSessionManagerHandler implements REPHandler {

	private SessionManager manager;

	public REPSessionManagerHandler(SessionManager manager) {
		this.manager = manager;
	}

	public void cancel(REPSocketChannel<REPCommand> socketChannel) {
		manager.remove(socketChannel);
	}

	public void handle(REPSelectionKey<REPCommand> key) throws IOException {
		/*
		 * SessionManagerから来たコマンドは、Editor関係のコマンドは、
		 * sessionとeidを判定して、そのeditorにforwardしてやれば良い。
		 * 残りは、manager.manage() で処理する。
		 */
		REPSocketChannel<REPCommand> channel = key.channel1();
		REPCommand command = channel.read();
		System.out.println("REPHandlerImpl.handle() : command = " + command);
		Session s = manager.getSession(command.sid);
		Forwarder next = s.getForwarder(command.eid);
		if (next!=null) {
			next.send(command);
		} else {
			manager.manage(channel, command);
		}
	}

}