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

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

package rep.handler;

import java.io.IOException;
import rep.Editor;
import rep.REPCommand;
import rep.Session;
import rep.SessionManager;
import rep.channel.REPSelectionKey;
import rep.channel.REPSocketChannel;

public class REPHandlerEditorInMerge implements REPHandler {

	private SessionManager manager;

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


	public void handle(REPSelectionKey<REPCommand> key) throws IOException {
		//マージ中のエディタの前のエディタのコマンドをWaitingListに追加する
		REPSocketChannel<REPCommand> channel = key.channel1();
		REPCommand command = channel.read();
		System.out.println("REPHandlerImpl.handle() : command = " + command);
		// if (manager.isMerging(command.sid()))...
		//    同じchannelで、merge中のsessionは一つは限らない。
		//    なので、sid をinstanceで持つのではだめ。
		Session s = manager.getSession(command.sid);
		Editor editor = s.getEditor(channel);
		manager.addWaitingCommand(new PacketSet(channel, editor, command));
	}

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