package org.craft.atom.rpc;

import lombok.Getter;
import lombok.Setter;

import org.craft.atom.protocol.rpc.model.RpcMessage;
import org.craft.atom.rpc.spi.RpcInvoker;
import org.craft.atom.rpc.spi.RpcProcessor;

/**
 * @author mindwind
 * @version 1.0, Aug 7, 2014
 */
public class DefaultRpcProcessor implements RpcProcessor {
		
	
	@Getter @Setter private RpcInvoker  invoker ;
	
	
	@Override
	public RpcMessage process(RpcMessage req) {
		RpcMessage rsp;
		try {
			rsp = invoker.invoke(req);
		} catch (RpcException e) {
			rsp = null; // TODO
		}
		
		return rsp;
	}
	

}

@@ -33,97 +33,451 @@
 ort 
-lombok.Getter;%0Aimport lombok.Setter;%0A%0Aimport org.craft.atom.protocol.rpc.model.RpcMessage
+java.util.concurrent.Callable;%0Aimport java.util.concurrent.ExecutionException;%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Future;%0Aimport java.util.concurrent.TimeUnit;%0Aimport java.util.concurrent.TimeoutException;%0A%0Aimport lombok.Getter;%0Aimport lombok.Setter;%0A%0Aimport org.craft.atom.protocol.rpc.model.RpcMessage;%0Aimport org.craft.atom.protocol.rpc.model.RpcMethod;%0Aimport org.craft.atom.rpc.spi.RpcExecutorFactory
 ;%0Aim
@@ -723,16 +723,23 @@
 er  
+       
 invoker 
 ;%0A%09%0A
@@ -738,51 +738,662 @@
 ker 
-;%0A%09%0A%09%0A%09@Override%0A%09public RpcMessage process
+       ;%0A%09@Getter @Setter private RpcExecutorFactory executorFactory;%0A%09%0A%09%0A%09@Override%0A%09public RpcMessage process(final RpcMessage req) %7B%0A%09%09ExecutorService executor = executor(req);%0A%09%09Future%3CRpcMessage%3E future = executor.submit(new Callable%3CRpcMessage%3E() %7B%0A%0A%09%09%09@Override%0A%09%09%09public RpcMessage call() throws Exception %7B%0A%09%09%09%09return process0(req);%0A%09%09%09%7D%0A%09%09%7D);%0A%09%09try %7B%0A%09%09%09return future.get(rpcTimeoutInMillis(req), TimeUnit.MILLISECONDS);%0A%09%09%7D catch (InterruptedException e) %7B%0A%09%09%09// TODO%0A%09%09%09return null;%0A%09%09%7D catch (ExecutionException e) %7B%0A%09%09%09// TODO%0A%09%09%09return null;%0A%09%09%7D catch (TimeoutException e) %7B%0A%09%09%09// TODO%0A%09%09%09return null;%0A%09%09%7D%0A%09%7D%0A%09%0A%09private RpcMessage process0
 (Rpc
@@ -1519,19 +1519,16 @@
 ODO%0A%09%09%7D%0A
-%09%09%0A
 %09%09return
@@ -1537,12 +1537,435 @@
 sp;%0A%09%7D%0A%09
+%0A%09private long rpcTimeoutInMillis(RpcMessage req) %7B%0A%09%09long timeout = req.getBody().getRpcOption().getRpcTimeoutInMillis();%0A%09%09if (timeout == 0) %7B timeout = Long.MAX_VALUE; %7D%0A%09%09return timeout;%0A%09%7D%0A%09%0A%09private ExecutorService executor(RpcMessage rm) %7B%0A%09%09Class%3C?%3E rpcInterface = rm.getBody().getRpcInterface();%0A%09%09RpcMethod rpcMethod = rm.getBody().getRpcMethod();%0A%09%09return executorFactory.getExecutor(rpcInterface, rpcMethod);%0A%09%7D
 %0A%0A%7D%0A

improve - use RpcExcutorFactory