// Path: fluency-fluentd/src/test/java/org/komamitsu/fluency/fluentd/ingester/sender/SSLTestServerSocketFactory.java
// public class SSLTestServerSocketFactory
// {
//     private static final String KEYSTORE_PASSWORD = "keypassword";
//     private static final String KEY_PASSWORD = "keypassword";
// 
//     public SSLServerSocket create()
//             throws IOException, CertificateException, NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, KeyManagementException
//     {
//         String trustStorePath = SSLSocketBuilder.class.getClassLoader().getResource("truststore.jks").getFile();
//         System.getProperties().setProperty("javax.net.ssl.trustStore", trustStorePath);
// 
//         String keyStorePath = SSLSocketBuilder.class.getClassLoader().getResource("keystore.jks").getFile();
// 
//         InputStream keystoreStream = null;
//         try {
//             KeyStore keystore = KeyStore.getInstance("JKS");
//             keystoreStream = new FileInputStream(new File(keyStorePath));
// 
//             keystore.load(keystoreStream, KEYSTORE_PASSWORD.toCharArray());
//             KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
// 
//             keyManagerFactory.init(keystore, KEY_PASSWORD.toCharArray());
// 
//             SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
//             sslContext.init(keyManagerFactory.getKeyManagers(), null, new SecureRandom());
// 
//             SSLServerSocket serverSocket = (SSLServerSocket) sslContext.getServerSocketFactory().createServerSocket();
//             serverSocket.setEnabledCipherSuites(serverSocket.getSupportedCipherSuites());
//             serverSocket.bind(new InetSocketAddress(0));
// 
//             return serverSocket;
//         }
//         finally {
//             if (keystoreStream != null) {
//                 keystoreStream.close();
//             }
//         }
//     }
// }


import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.komamitsu.fluency.fluentd.ingester.sender.SSLTestServerSocketFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLHandshakeException;
import java.io.EOFException;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.channels.ClosedByInterruptException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionException;
            }

            @Override
            public void onReceive(Socket acceptSocket, int len, byte[] data)
            {
            }

            @Override
            public void onClose(Socket acceptSocket)
            {
            }
        };
    }

    public synchronized void start()
            throws Exception
    {
        if (executorService == null) {
            this.executorService = Executors.newCachedThreadPool(new ThreadFactory()
            {
                @Override
                public Thread newThread(Runnable r)
                {
                    return new Thread(r, String.format("accepted-socket-worker-%d", threadSeqNum.getAndAdd(1)));
                }
            });
        }

        if (serverTask == null) {
            serverTask = new ServerTask(executorService, lastEventTimeStampMilli, getEventHandler(),
// Path: fluency-fluentd/src/test/java/org/komamitsu/fluency/fluentd/ingester/sender/SSLTestServerSocketFactory.java
// public class SSLTestServerSocketFactory
// {
//     private static final String KEYSTORE_PASSWORD = "keypassword";
//     private static final String KEY_PASSWORD = "keypassword";
// 
//     public SSLServerSocket create()
//             throws IOException, CertificateException, NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, KeyManagementException
//     {
//         String trustStorePath = SSLSocketBuilder.class.getClassLoader().getResource("truststore.jks").getFile();
//         System.getProperties().setProperty("javax.net.ssl.trustStore", trustStorePath);
// 
//         String keyStorePath = SSLSocketBuilder.class.getClassLoader().getResource("keystore.jks").getFile();
// 
//         InputStream keystoreStream = null;
//         try {
//             KeyStore keystore = KeyStore.getInstance("JKS");
//             keystoreStream = new FileInputStream(new File(keyStorePath));
// 
//             keystore.load(keystoreStream, KEYSTORE_PASSWORD.toCharArray());
//             KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
// 
//             keyManagerFactory.init(keystore, KEY_PASSWORD.toCharArray());
// 
//             SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
//             sslContext.init(keyManagerFactory.getKeyManagers(), null, new SecureRandom());
// 
//             SSLServerSocket serverSocket = (SSLServerSocket) sslContext.getServerSocketFactory().createServerSocket();
//             serverSocket.setEnabledCipherSuites(serverSocket.getSupportedCipherSuites());
//             serverSocket.bind(new InetSocketAddress(0));
// 
//             return serverSocket;
//         }
//         finally {
//             if (keystoreStream != null) {
//                 keystoreStream.close();
//             }
//         }
//     }
// }


// Path: fluency-fluentd/src/test/java/org/komamitsu/fluency/fluentd/MockTCPServer.java
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.komamitsu.fluency.fluentd.ingester.sender.SSLTestServerSocketFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLHandshakeException;
import java.io.EOFException;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.channels.ClosedByInterruptException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionException;

            }

            @Override
            public void onReceive(Socket acceptSocket, int len, byte[] data)
            {
            }

            @Override
            public void onClose(Socket acceptSocket)
            {
            }
        };
    }

    public synchronized void start()
            throws Exception
    {
        if (executorService == null) {
            this.executorService = Executors.newCachedThreadPool(new ThreadFactory()
            {
                @Override
                public Thread newThread(Runnable r)
                {
                    return new Thread(r, String.format("accepted-socket-worker-%d", threadSeqNum.getAndAdd(1)));
                }
            });
        }

        if (serverTask == null) {
            serverTask = new ServerTask(executorService, lastEventTimeStampMilli, getEventHandler(),
                    sslEnabled ? new SSLTestServerSocketFactory().create() : new ServerSocket());