// Path: elasticservice/src/main/java/elasticsearch/ElasticRestClient.java
// @Component
// public class ElasticRestClient extends AbstractFactoryBean<RestClient> {
//     private static Logger logger = Logger.getLogger(ElasticRestClient.class);
//     private ClusterFailureListener clusterFailureListener;
//     private volatile RestClient restClient;
//     private static List<String> hosts = new ArrayList<>();
//     private Sniffer sniffer;
// 
//     static {
//         hosts.add("10.128.161.107:9200");
//     }
// 
//     @Override
//     public Class<?> getObjectType() {
//         return RestClient.class;
//     }
// 
// 
//     @Override
//     public RestClient createInstance() throws Exception {
//         if (this.restClient != null) {
//             return this.restClient;
//         }
// 
//         HttpHost[] addresses = new HttpHost[hosts.size()];
//         for (int i = 0; i < hosts.size(); i++) {
//             addresses[i] = HttpHost.create(hosts.get(i));
//         }
// 
//         this.restClient = RestClient
//                 .builder(addresses)
//                 .setMaxRetryTimeoutMillis(ESConstants.RESTCLIENT_TIMEOUT)
//                 .build();
// 
// //        this.sniffer = Sniffer.builder(this.restClient)
// //                                 .setSniffIntervalMillis(60000).build();
// 
//         return this.restClient;
//     }
// 
//     @Override
//     protected void destroyInstance(RestClient instance) throws Exception {
//         try {
//             logger.info("Closing sniffer");
//             instance.close();
//             this.sniffer.close();
//         } catch (IOException e) {
//             logger.warn("Error during close sniffer", e);
//         }
//     }
// 
//     public void setHosts(List<String> hosts) {
//         this.hosts = hosts;
//     }
// }
// 
// Path: netty-http/src/main/java/http/worker/SearchWorker.java
// public class SearchWorker extends ThreadPoolExecutor {
//     private final static Logger logger = LoggerFactory.getLogger(SearchWorker.class);
//     private static SearchWorker instance;
// 
//     public SearchWorker(int size, String name, BlockingQueue blockingQueue) {
//         super(size, size+5, 0L, TimeUnit.MILLISECONDS, blockingQueue, new WorkerThread(name));
//     }
// 
//     @Override
//     protected void beforeExecute(Thread t, Runnable r) {
//         logger.info("start to exectue: " + t);
//         super.beforeExecute(t, r);
//     }
// 
//     @Override
//     protected void afterExecute(Runnable r, Throwable t) {
//         super.afterExecute(r, t);
//         logger.info("after to exectue: " + t);
//     }
// 
//     public INotifyingFuture doSearch(SearchRequest request) {
//         SearchingFuture future = new SearchingFuture(request);
//         future.setExecutor(this);
//         future.run();
//         return future;
//     }
// 
//     public String monitorInfo() {
//         StringBuilder result = new StringBuilder(100);
//         result.append("\r\n QueueSize :" + this.getQueue().size());
//         result.append("ThreadCount :" + this.getPoolSize() + "\r\n");
//         return result.toString();
//     }
// }


import elasticsearch.ElasticRestClient;
import http.worker.SearchWorker;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.util.concurrent.DefaultEventExecutorGroup;
import io.netty.util.concurrent.EventExecutorGroup;
import org.elasticsearch.client.RestClient;
import org.springframework.context.ConfigurableApplicationContext;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;

package http;




/**
 * Created by i311352 on 2/13/2017.
 */
public class DefaultServerInitializer extends ChannelInitializer<SocketChannel> {
    private final Config conf;

    //private final EventExecutorGroup executor;
    private final ExecutorService executor;
    private final ConfigurableApplicationContext applicationContext;

    public DefaultServerInitializer(Config conf, ConfigurableApplicationContext applicationContext) {
        this.conf = conf;
        this.applicationContext = applicationContext;


// Path: elasticservice/src/main/java/elasticsearch/ElasticRestClient.java
// @Component
// public class ElasticRestClient extends AbstractFactoryBean<RestClient> {
//     private static Logger logger = Logger.getLogger(ElasticRestClient.class);
//     private ClusterFailureListener clusterFailureListener;
//     private volatile RestClient restClient;
//     private static List<String> hosts = new ArrayList<>();
//     private Sniffer sniffer;
// 
//     static {
//         hosts.add("10.128.161.107:9200");
//     }
// 
//     @Override
//     public Class<?> getObjectType() {
//         return RestClient.class;
//     }
// 
// 
//     @Override
//     public RestClient createInstance() throws Exception {
//         if (this.restClient != null) {
//             return this.restClient;
//         }
// 
//         HttpHost[] addresses = new HttpHost[hosts.size()];
//         for (int i = 0; i < hosts.size(); i++) {
//             addresses[i] = HttpHost.create(hosts.get(i));
//         }
// 
//         this.restClient = RestClient
//                 .builder(addresses)
//                 .setMaxRetryTimeoutMillis(ESConstants.RESTCLIENT_TIMEOUT)
//                 .build();
// 
// //        this.sniffer = Sniffer.builder(this.restClient)
// //                                 .setSniffIntervalMillis(60000).build();
// 
//         return this.restClient;
//     }
// 
//     @Override
//     protected void destroyInstance(RestClient instance) throws Exception {
//         try {
//             logger.info("Closing sniffer");
//             instance.close();
//             this.sniffer.close();
//         } catch (IOException e) {
//             logger.warn("Error during close sniffer", e);
//         }
//     }
// 
//     public void setHosts(List<String> hosts) {
//         this.hosts = hosts;
//     }
// }
// 
// Path: netty-http/src/main/java/http/worker/SearchWorker.java
// public class SearchWorker extends ThreadPoolExecutor {
//     private final static Logger logger = LoggerFactory.getLogger(SearchWorker.class);
//     private static SearchWorker instance;
// 
//     public SearchWorker(int size, String name, BlockingQueue blockingQueue) {
//         super(size, size+5, 0L, TimeUnit.MILLISECONDS, blockingQueue, new WorkerThread(name));
//     }
// 
//     @Override
//     protected void beforeExecute(Thread t, Runnable r) {
//         logger.info("start to exectue: " + t);
//         super.beforeExecute(t, r);
//     }
// 
//     @Override
//     protected void afterExecute(Runnable r, Throwable t) {
//         super.afterExecute(r, t);
//         logger.info("after to exectue: " + t);
//     }
// 
//     public INotifyingFuture doSearch(SearchRequest request) {
//         SearchingFuture future = new SearchingFuture(request);
//         future.setExecutor(this);
//         future.run();
//         return future;
//     }
// 
//     public String monitorInfo() {
//         StringBuilder result = new StringBuilder(100);
//         result.append("\r\n QueueSize :" + this.getQueue().size());
//         result.append("ThreadCount :" + this.getPoolSize() + "\r\n");
//         return result.toString();
//     }
// }


// Path: netty-http/src/main/java/http/DefaultServerInitializer.java
import elasticsearch.ElasticRestClient;
import http.worker.SearchWorker;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.util.concurrent.DefaultEventExecutorGroup;
import io.netty.util.concurrent.EventExecutorGroup;
import org.elasticsearch.client.RestClient;
import org.springframework.context.ConfigurableApplicationContext;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;

package http;




/**
 * Created by i311352 on 2/13/2017.
 */
public class DefaultServerInitializer extends ChannelInitializer<SocketChannel> {
    private final Config conf;

    //private final EventExecutorGroup executor;
    private final ExecutorService executor;
    private final ConfigurableApplicationContext applicationContext;

    public DefaultServerInitializer(Config conf, ConfigurableApplicationContext applicationContext) {
        this.conf = conf;
        this.applicationContext = applicationContext;


        this.executor = new SearchWorker(conf.getTaskThreadPoolSize(), "SearchWorkder", new ArrayBlockingQueue(5));
