view rep/handler/REPHandlerInMerge.java @ 178:a097b1d619a1

*** empty log message ***
author pin
date Thu, 28 Aug 2008 22:04:48 +0900
parents 3dc194f5e28f
children 4d9b32666ed2
line wrap: on
line source

package rep.handler;

import java.io.IOException;
import java.nio.channels.SelectionKey;

import rep.Editor;
import rep.REPCommand;
import rep.SessionManager;
import rep.channel.ChannelSimulator;
import rep.channel.REPSocketChannel;
import rep.channel.SelectionKeySimulator;

public class REPHandlerInMerge implements REPHandler {

	private SessionManager manager;
	private int sid;

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

	public REPHandlerInMerge(int sid, SessionManager manager2) {
		this.manager = manager2;
		this.sid = sid;
	}

	public void handle(SelectionKey key) {
		//マージ中のエディタの前のエディタのコマンドをWaitingListに追加する
		REPSocketChannel<REPCommand> channel = (REPSocketChannel<REPCommand>) key.channel();
		REPCommand command = null;
		
		try {
			command = channel.read();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		if(command.sid == sid){
			Editor editor = manager.getEditor(channel);
			manager.addWaitingCommand(new PacketSet(channel, editor, command));
		}else{
			manager.manage(channel, command);
		}
	}

}