Ejemplo n.º 1
0
 public void run() {
   System.out.println("JSSE Server listening on port " + cipherTest.serverPort);
   Executor exec = Executors.newFixedThreadPool(cipherTest.THREADS, DaemonThreadFactory.INSTANCE);
   try {
     while (true) {
       final SSLSocket socket = (SSLSocket) serverSocket.accept();
       socket.setSoTimeout(cipherTest.TIMEOUT);
       Runnable r =
           new Runnable() {
             public void run() {
               try {
                 InputStream in = socket.getInputStream();
                 OutputStream out = socket.getOutputStream();
                 handleRequest(in, out);
                 out.flush();
                 socket.close();
                 socket.getSession().invalidate();
               } catch (IOException e) {
                 cipherTest.setFailed();
                 e.printStackTrace();
               } finally {
                 if (socket != null) {
                   try {
                     socket.close();
                   } catch (IOException e) {
                     cipherTest.setFailed();
                     System.out.println("Exception closing socket on server side:");
                     e.printStackTrace();
                   }
                 }
               }
             }
           };
       exec.execute(r);
     }
   } catch (IOException e) {
     cipherTest.setFailed();
     e.printStackTrace();
     //
   }
 }
Ejemplo n.º 2
0
  /**
   * Create the HttpServer to use. Can be overridden if a custom or already existing HttpServer
   * should be used
   *
   * @return HttpServer to use
   * @throws IOException if something fails during the initialisation
   */
  private HttpServer createHttpServer(JolokiaServerConfig pConfig) throws IOException {
    int port = pConfig.getPort();
    InetAddress address = pConfig.getAddress();
    InetSocketAddress socketAddress = new InetSocketAddress(address, port);

    HttpServer server =
        pConfig.useHttps()
            ? createHttpsServer(socketAddress, pConfig)
            : HttpServer.create(socketAddress, pConfig.getBacklog());

    // Prepare executor pool
    Executor executor;
    String mode = pConfig.getExecutor();
    if ("fixed".equalsIgnoreCase(mode)) {
      executor = Executors.newFixedThreadPool(pConfig.getThreadNr(), daemonThreadFactory);
    } else if ("cached".equalsIgnoreCase(mode)) {
      executor = Executors.newCachedThreadPool(daemonThreadFactory);
    } else {
      executor = Executors.newSingleThreadExecutor(daemonThreadFactory);
    }
    server.setExecutor(executor);

    return server;
  }
Ejemplo n.º 3
0
 public static Executor getExecutor() {
   if (executor == null) executor = Executors.newFixedThreadPool(4);
   return executor;
 }