package org.webpieces.frontend.api;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import org.webpieces.asyncserver.api.AsyncServerManager;
import org.webpieces.asyncserver.api.AsyncServerMgrFactory;
import org.webpieces.data.api.BufferPool;
import org.webpieces.frontend.impl.FrontEndServerManagerImpl;
import org.webpieces.nio.api.ChannelManager;
import org.webpieces.nio.api.ChannelManagerFactory;
import org.webpieces.util.threading.NamedThreadFactory;
public abstract class HttpFrontendFactory {
/**
*
* @param id Use for logging and also file recording names
* @param threadPoolSize The size of the threadpool, although all data comes in order as we
* use the SessionExecutorImpl found in webpieces
*
* @return
*/
public static HttpFrontendManager createFrontEnd(String id, int threadPoolSize, ScheduledExecutorService timer, BufferPool pool) {
Executor executor = Executors.newFixedThreadPool(threadPoolSize, new NamedThreadFactory(id));
ChannelManagerFactory factory = ChannelManagerFactory.createFactory();
ChannelManager chanMgr = factory.createMultiThreadedChanMgr(id, pool, executor);
AsyncServerManager svrMgr = AsyncServerMgrFactory.createAsyncServer(chanMgr);
return createFrontEnd(svrMgr, timer, pool);
}
public static HttpFrontendManager createFrontEnd(AsyncServerManager svrManager, ScheduledExecutorService svc, BufferPool bufferPool) {
return new FrontEndServerManagerImpl(svrManager, svc, bufferPool);
}
}