package org.craft.atom.rpc;


import java.io.IOException;
import java.net.InetSocketAddress;

import lombok.Getter;
import lombok.Setter;

import org.craft.atom.io.IoAcceptor;
import org.craft.atom.io.IoHandler;
import org.craft.atom.nio.api.NioFactory;
import org.craft.atom.rpc.spi.RpcProcessor;
import org.craft.atom.rpc.spi.RpcProtocol;
import org.craft.atom.rpc.spi.RpcAcceptor;

/**
 * @author mindwind
 * @version 1.0, Aug 6, 2014
 */
public class DefaultRpcAcceptor implements RpcAcceptor {
	
	
	@Getter @Setter private RpcProcessor processor;
	@Getter @Setter private RpcProtocol  protocol ;


	@Override
	public void bind(String host, int port, int ioTimeoutInMillis) throws IOException {
		IoHandler  handler  = new RpcServerIoHandler(protocol, processor);
		IoAcceptor acceptor = NioFactory.newTcpAcceptorBuilder(handler).ioTimeoutInMillis(ioTimeoutInMillis).build();
		if (host != null) {
			acceptor.bind(new InetSocketAddress(host, port));
		} else {
			acceptor.bind(port);
		}
	}

}

@@ -235,22 +235,131 @@
 nio.
-api.NioFactory
+NioOrderedDirectChannelEventDispatcher;%0Aimport org.craft.atom.nio.api.NioFactory;%0Aimport org.craft.atom.rpc.spi.RpcAcceptor
 ;%0Aim
@@ -446,51 +446,8 @@
 col;
-%0Aimport org.craft.atom.rpc.spi.RpcAcceptor;
 %0A%0A/*
@@ -892,16 +892,27 @@
 handler)
+%0A%09%09%09%09%09%09%09%09%09%09
 .ioTimeo
@@ -940,16 +940,95 @@
 nMillis)
+%0A%09%09%09%09%09%09%09%09%09%09.dispatcher(new NioOrderedDirectChannelEventDispatcher())%0A%09%09%09%09%09%09%09%09%09%09
 .build()

improve - use direct nio dispatcher