package com.amebame.triton.server;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.inject.Inject;
import javax.inject.Singleton;

import com.amebame.triton.config.TritonServerConfiguration;
import com.amebame.triton.util.NamedThreadFactory;

@Singleton
public class TritonServerContext {
	
	private TritonServerMethodMap methodMap;
	
	private ExecutorService executor;
	
	@Inject
	public TritonServerContext(TritonServerConfiguration config) {
		methodMap = new TritonServerMethodMap();
		executor = Executors.newFixedThreadPool(
				config.getNetty().getWorker(),
				new NamedThreadFactory("triton-worker-"));
	}
	
	/**
	 * Add server methods from the target object
	 * @param target
	 */
	public void addServerMethod(Object target) {
		methodMap.register(target);
	}
	
	/**
	 * Get server method by name
	 * @param name
	 * @return
	 */
	public TritonServerMethod getServerMethod(String name) {
		return methodMap.getMethod(name);
	}

	/**
	 * Get worker executor
	 * @return
	 */
	public ExecutorService getWorkerExecutor() {
		return executor;
	}
}

@@ -102,25 +102,118 @@
 current.
-Executors
+SynchronousQueue;%0Aimport java.util.concurrent.ThreadPoolExecutor;%0Aimport java.util.concurrent.TimeUnit
 ;%0A%0Aimpor
@@ -641,69 +641,139 @@
 r = 
-Executors.newFixedThreadPool(%0A%09%09%09%09config.getNetty().getWorker
+new ThreadPoolExecutor(%0A%09%09%09%091,%0A%09%09%09%09config.getNetty().getWorker(),%0A%09%09%09%0960L,%0A%09%09%09%09TimeUnit.SECONDS,%0A%09%09%09%09new SynchronousQueue%3CRunnable%3E
 (),%0A

Use SynchronousQueue as executor queue to enable expanding pools.