public RequestListenerThread( int port, HttpService httpService, SSLServerSocketFactory sf) throws IOException { this.connFactory = DefaultBHttpServerConnectionFactory.INSTANCE; while (!createServerSocket(sf, port)) { port++; if (port >= 65535) { System.out.println("Now the port is already in use,port number add 1"); ConsoleFactory.printToConsole("Now the port is already in use,port number add 1",true); break; } } monitorPort = port; this.httpService = httpService; }
/** * Default constructor which specifies the <code>port</code> to listen to * for requests and the <code>handlers</code>, which specify how to handle * the request. * * @param port * the port to listen to * @param handlers * the handlers, which specify how to handle the different * requests * * @throws IOException * if some IO operation fails */ public RequestListenerThread(final int port, final Map<String, IHandler> handlers) throws IOException { super(port); // Set up the HTTP protocol processor final HttpProcessor httpproc = new ImmutableHttpProcessor( new HttpResponseInterceptor[] { new ResponseDate(), new ResponseServer(), new ResponseContent(), new ResponseConnControl() }); // Set up request handlers UriHttpRequestHandlerMapper registry = new UriHttpRequestHandlerMapper(); for (final Entry<String, IHandler> entry : handlers.entrySet()) { registry.register(entry.getKey(), entry.getValue()); } // Set up the HTTP service httpService = new HttpService(httpproc, registry); connFactory = DefaultBHttpServerConnectionFactory.INSTANCE; }
public RequestListenerThread( final int port, final HttpService httpService, final SSLServerSocketFactory sf) throws IOException { this.connFactory = DefaultBHttpServerConnectionFactory.INSTANCE; this.serversocket = sf != null ? sf.createServerSocket(port) : new ServerSocket(port); this.httpService = httpService; }
public RequestListenerThread( final int port, final HttpService httpService, final SSLServerSocketFactory sf) throws IOException { this.connFactory = DefaultBHttpServerConnectionFactory.INSTANCE; this.serversocket = sf != null ? sf.createServerSocket(port) : new ServerSocket(port); this.httpService = httpService; // only 4 connections can run concurrently connectionHandlerExecutor = Executors.newFixedThreadPool(100); System.out.println("Request Listener Thread created"); }
public GenericRequestListenerThread( final int port, final HttpService httpService, final SSLServerSocketFactory sf) throws IOException { this.connFactory = DefaultBHttpServerConnectionFactory.INSTANCE; this.serversocket = sf != null ? sf.createServerSocket(port) : new ServerSocket(port); this.httpService = httpService; // only 4 connections can run concurrently connectionHandlerExecutor = Executors.newFixedThreadPool(1000); //System.out.println("Request Listener Thread created"); }
public LateBindingRequestListenerThread( final int port, final HttpService httpService, final SSLServerSocketFactory sf) throws IOException { this.connFactory = DefaultBHttpServerConnectionFactory.INSTANCE; this.serversocket = sf != null ? sf.createServerSocket(port) : new ServerSocket(port); this.httpService = httpService; // only 4 connections can run concurrently connectionHandlerExecutor = Executors.newFixedThreadPool(22); System.out.println("Request Listener Thread created"); }
public RequestListenerThread(final int port, final HttpService httpService, final SSLServerSocketFactory sf) throws IOException { this.connFactory = DefaultBHttpServerConnectionFactory.INSTANCE; this.serversocket = sf != null ? sf.createServerSocket(port) : new ServerSocket(port); this.httpService = httpService; LimitedQueue<Runnable> blockingQueue = new LimitedQueue<Runnable>( 10); executor = new java.util.concurrent.ThreadPoolExecutor(1, 10, 0L, TimeUnit.MILLISECONDS, blockingQueue); }
public HttpConnectionFactory<DefaultBHttpServerConnection> getHttpConnectionFactory() { if (null == _connectionFactory) _connectionFactory = DefaultBHttpServerConnectionFactory.INSTANCE; return _connectionFactory; }
public RequestListenerThread(final int port, final HttpService httpService, final SSLServerSocketFactory sf) throws IOException { this.connFactory = DefaultBHttpServerConnectionFactory.INSTANCE; this.serversocket = sf != null ? sf.createServerSocket(port) : new ServerSocket(port); this.httpService = httpService; }
public SimpleHttpServer(int port, ConnectedAddressesProvider connectedAddressesProvider){ this.connFactory = DefaultBHttpServerConnectionFactory.INSTANCE; // Set up the HTTP protocol processor HttpProcessor httpproc = HttpProcessorBuilder.create() .add(new ResponseDate()) .add(new ResponseServer("Test/1.1")) .add(new ResponseContent()) .add(new ResponseConnControl()).build(); // Set up request handlers UriHttpRequestHandlerMapper reqistry = new UriHttpRequestHandlerMapper(); reqistry.register("*", new HttpRequestHandlerNew(connectedAddressesProvider)); // Set up the HTTP service httpService = new HttpService(httpproc, reqistry); try { serversocket = new ServerSocket(port, 1, InetAddress.getByName("127.0.0.1")); System.out.println("Listening on port " + serversocket.getLocalPort()); while (!Thread.interrupted()) { try { // Set up HTTP connection Socket socket = serversocket.accept(); System.out.println("Incoming connection from " + socket.getInetAddress()); HttpServerConnection conn = connFactory.createConnection(socket); // Start worker thread Thread t = new WorkerThread(httpService, conn); t.setDaemon(true); t.start(); } catch (InterruptedIOException ex) { break; } catch (IOException e) { System.err.println("I/O error initialising connection thread: " + e.getMessage()); break; } } } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }