/** * This is used to accept a new TCP connections. When the socket * is ready to accept a connection this method is invoked. It will * then create a HTTP pipeline object using the accepted socket * and if provided with an <code>SSLContext</code> it will also * provide an <code>SSLEngine</code> which is handed to the * processor to handle the HTTP requests. */ public void run() { try { accept(); } catch(Exception e) { pause(); } }
/** * This is used to cancel the operation if the reactor decides to * reject it for some reason. Typically this method will never be * invoked as this operation never times out. However, should the * reactor cancel the operation this will close the socket. */ public void cancel() { try { close(); } catch(Throwable e) { return; } }
/** * This is used to acquire the local socket address that this is * listening to. This required in case the socket address that * is specified is an emphemeral address, that is an address that * is assigned dynamically when a port of 0 is specified. * * @return this returns the address for the listening address */ public SocketAddress getAddress() { return acceptor.getAddress(); }
/** * The main processing done by this object is done using a thread * calling the <code>run</code> method. Here the TCP connections * are accepted from the <code>ServerSocketChannel</code> which * creates the socket objects. Each socket is then encapsulated in * to a pipeline and dispatched to the processor for processing. * * @throws IOException if there is a problem accepting the socket */ private void accept() throws IOException { SocketChannel channel = listener.accept(); while(channel != null) { Trace trace = agent.attach(channel); configure(channel); if(context == null) { process(channel, trace, null); } else { process(channel, trace); } channel = listener.accept(); } }
/** * Constructor for the <code>SocketAcceptor</code> object. This * accepts new TCP connections from the specified server socket. * Each of the connections that is accepted is configured for * performance for HTTP applications. * * @param address this is the address to accept connections from * @param context this is the SSL context used for secure HTTPS * @param server this is used to initiate the HTTP processing * @param agent this is the tracing agent associated with this */ public SocketAcceptor(SocketAddress address, SSLContext context, Server server, Agent agent) throws IOException { this.listener = ServerSocketChannel.open(); this.socket = listener.socket(); this.context = context; this.agent = agent; this.server = server; this.bind(address); }
/** * Constructor for the <code>SocketListener</code> object. This * needs a socket address and a processor to hand created sockets * to. This creates a <code>Reactor</code> which will notify the * acceptor when there is a new connection waiting to be accepted. * * @param address this is the address to listen for new sockets * @param processor this is the processor that sockets are handed to * @param analyzer this is used to create a trace to monitor events * @param context this is the SSL context used for secure HTTPS */ public SocketListener(SocketAddress address, SocketProcessor processor, TraceAnalyzer analyzer, SSLContext context) throws IOException { this.acceptor = new SocketAcceptor(address, processor, analyzer, context); this.reactor = new SynchronousReactor(); }
/** * This method is used to dispatch the socket for processing. The * socket will be configured and connected to the client, this * will hand processing to the <code>Server</code> which will * create the pipeline instance used to wrap the socket object. * * @param channel this is the connected socket to be processed * @param trace this is the trace to associate with the socket */ private void process(SocketChannel channel, Trace trace) throws IOException { SSLEngine engine = context.createSSLEngine(); try { process(channel, trace, engine); } catch(Exception cause) { trace.trace(ERROR, cause); channel.close(); } }
/** * The main processing done by this object is done using a thread * calling the <code>run</code> method. Here the TCP connections * are accepted from the <code>ServerSocketChannel</code> which * creates the socket objects. Each socket is then encapsulated in * to a pipeline and dispatched to the processor for processing. * * @throws IOException if there is a problem accepting the socket */ private void accept() throws IOException { SocketChannel channel = listener.accept(); while(channel != null) { Trace trace = analyzer.attach(channel); configure(channel); if(context == null) { process(channel, trace, null); } else { process(channel, trace); } channel = listener.accept(); } }
/** * This is used to register the socket acceptor to listen for * new connections that are ready to be accepted. Once this is * registered it will remain registered until the interface is * closed, at which point the socket is closed. */ public void process() throws IOException { try { acceptor.bind(); reactor.process(acceptor, OP_ACCEPT); } catch(Exception cause) { throw new ConnectionException("Listen error", cause); } }
/** * Constructor for the <code>SocketListener</code> object. This * needs a socket address and a processor to hand created sockets * to. This creates a <code>Reactor</code> which will notify the * acceptor when there is a new connection waiting to be accepted. * * @param address this is the address to listen for new sockets * @param processor this is the processor that sockets are handed to * @param analyzer this is used to create a trace to monitor events * @param context this is the SSL context used for secure HTTPS */ public SocketListener(SocketAddress address, SocketProcessor processor, TraceAnalyzer analyzer, SSLContext context) throws IOException { this.acceptor = new SocketAcceptor(address, processor, analyzer, context); this.reactor = new SynchronousReactor(); }
/** * This method is used to dispatch the socket for processing. The * socket will be configured and connected to the client, this * will hand processing to the <code>Server</code> which will * create the pipeline instance used to wrap the socket object. * * @param channel this is the connected socket to be processed * @param trace this is the trace to associate with the socket */ private void process(SocketChannel channel, Trace trace) throws IOException { SSLEngine engine = context.createSSLEngine(); try { process(channel, trace, engine); } catch(Exception cause) { trace.trace(ERROR, cause); channel.close(); } }
/** * This is used to accept a new TCP connections. When the socket * is ready to accept a connection this method is invoked. It will * then create a HTTP pipeline object using the accepted socket * and if provided with an <code>SSLContext</code> it will also * provide an <code>SSLEngine</code> which is handed to the * processor to handle the HTTP requests. */ public void run() { try { accept(); } catch(Exception cause) { pause(); } }
/** * The main processing done by this object is done using a thread * calling the <code>run</code> method. Here the TCP connections * are accepted from the <code>ServerSocketChannel</code> which * creates the socket objects. Each socket is then encapsulated in * to a pipeline and dispatched to the processor for processing. * * @throws IOException if there is a problem accepting the socket */ private void accept() throws IOException { SocketChannel channel = listener.accept(); while(channel != null) { Trace trace = analyzer.attach(channel); configure(channel); if(context == null) { process(channel, trace, null); } else { process(channel, trace); } channel = listener.accept(); } }
/** * This is used to cancel the operation if the reactor decides to * reject it for some reason. Typically this method will never be * invoked as this operation never times out. However, should the * reactor cancel the operation this will close the socket. */ public void cancel() { try { close(); } catch(Throwable cause) { trace.trace(ERROR, cause); } }
/** * This is used to acquire the local socket address that this is * listening to. This required in case the socket address that * is specified is an emphemeral address, that is an address that * is assigned dynamically when a port of 0 is specified. * * @return this returns the address for the listening address */ public SocketAddress getAddress() { return acceptor.getAddress(); }
/** * This is used to register the socket acceptor to listen for * new connections that are ready to be accepted. Once this is * registered it will remain registered until the interface is * closed, at which point the socket is closed. */ public void process() throws IOException { try { acceptor.bind(); reactor.process(acceptor, OP_ACCEPT); } catch(Exception cause) { throw new ConnectionException("Listen error", cause); } }
/** * Constructor for the <code>Listener</code> object. This needs * a socket address and a processor to hand created sockets * to. This creates a <code>Reactor</code> which will notify the * acceptor when there is a new connection waiting to be accepted. * * @param address this is the address to listen for new sockets * @param context this is the SSL context used for secure HTTPS * @param server this is the server that pipelines are handed to * @param agent this is used to create a trace to monitor events */ public SocketListener(SocketAddress address, SSLContext context, Server server, Agent agent) throws IOException { this.acceptor = new SocketAcceptor(address, context, server, agent); this.reactor = new DirectReactor(); this.process(); }
/** * This method is used to dispatch the socket for processing. The * socket will be configured and connected to the client, this * will hand processing to the <code>Server</code> which will * create the pipeline instance used to wrap the socket object. * * @param channel this is the connected socket to be processed * @param trace this is the trace to associate with the socket */ private void process(SocketChannel channel, Trace trace) throws IOException { SSLEngine engine = context.createSSLEngine(); try { process(channel, trace, engine); } catch(Exception cause) { trace.trace(ERROR, cause); channel.close(); } }
/** * This is used to accept a new TCP connections. When the socket * is ready to accept a connection this method is invoked. It will * then create a HTTP pipeline object using the accepted socket * and if provided with an <code>SSLContext</code> it will also * provide an <code>SSLEngine</code> which is handed to the * processor to handle the HTTP requests. */ public void run() { try { accept(); } catch(Exception cause) { pause(); } }
/** * This is used to cancel the operation if the reactor decides to * reject it for some reason. Typically this method will never be * invoked as this operation never times out. However, should the * reactor cancel the operation this will close the socket. */ public void cancel() { try { close(); } catch(Throwable cause) { trace.trace(ERROR, cause); } }