package org.craft.atom.rpc;


import java.io.IOException;
import java.net.SocketAddress;

import lombok.Getter;
import lombok.Setter;

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

/**
 * @author mindwind
 * @version 1.0, Aug 6, 2014
 */
public class DefaultRpcAcceptor implements RpcAcceptor {
	
	
	@Getter         private int           ioTimeoutInMillis;
	@Getter         private int           connections      ;
	@Getter         private SocketAddress address          ;
	@Getter @Setter private RpcProcessor  processor        ;
	@Getter @Setter private RpcProtocol   protocol         ;
	@Getter @Setter private IoHandler     ioHandler        ;
	@Getter @Setter private IoAcceptor    ioAcceptor       ;
	
	
	// ~ ------------------------------------------------------------------------------------------------------------

	
	public DefaultRpcAcceptor() {}
	
	
	// ~ ------------------------------------------------------------------------------------------------------------
	

	@Override
	public void bind() throws IOException {
		ioHandler  = new RpcServerIoHandler(protocol, processor);
		ioAcceptor = NioFactory.newTcpAcceptorBuilder(ioHandler)
							   .channelSize(connections)
				               .ioTimeoutInMillis(ioTimeoutInMillis)
				               .dispatcher(new NioOrderedDirectChannelEventDispatcher())
				               .build();
		ioAcceptor.bind(address);
	}

	@Override
	public void setAddress(SocketAddress address) {
		this.address = address;
	}

	@Override
	public void setIoTimeoutInMillis(int ioTimeoutInMillis) {
		this.ioTimeoutInMillis = ioTimeoutInMillis;
	}

	@Override
	public void setConnections(int connections) {
		this.connections = connections;
	}

}

@@ -559,39 +559,39 @@
  %7B%0A%09%0A%09%0A%09@Getter 
-       
+@Setter
  private int    
@@ -617,39 +617,39 @@
 illis;%0A%09@Getter 
-       
+@Setter
  private int    
@@ -683,23 +683,23 @@
 @Getter 
-       
+@Setter
  private
@@ -1646,312 +1646,6 @@
 %09%7D%0A%0A
-%09@Override%0A%09public void setAddress(SocketAddress address) %7B%0A%09%09this.address = address;%0A%09%7D%0A%0A%09@Override%0A%09public void setIoTimeoutInMillis(int ioTimeoutInMillis) %7B%0A%09%09this.ioTimeoutInMillis = ioTimeoutInMillis;%0A%09%7D%0A%0A%09@Override%0A%09public void setConnections(int connections) %7B%0A%09%09this.connections = connections;%0A%09%7D%0A%0A
 %7D%0A

improve - use annotation replace setter method