Search in sources :

Example 1 with ExtendedReadTimeoutHandler

use of com.linkedin.databus2.core.container.ExtendedReadTimeoutHandler in project databus by linkedin.

the class GenericHttpClientPipelineFactory method getPipeline.

@Override
public ChannelPipeline getPipeline() throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = pipeline();
    if (_channelGroup != null)
        pipeline.addLast("auto group register ", new ConnectionChannelRegistrationHandler(_channelGroup));
    if (Logger.getRootLogger().isTraceEnabled()) {
        LOG.debug("Adding Netty tracing");
        pipeline.addLast("netty client traffic", new LoggingHandler("netty client traffic", InternalLogLevel.DEBUG, true));
    }
    if (null != _containerStatsCollector) {
        pipeline.addLast("inbound statistics collector", new InboundContainerStatisticsCollectingHandler(_containerStatsCollector));
    }
    ExtendedReadTimeoutHandler readTimeoutHandler = new ExtendedReadTimeoutHandler("client call ", _timeoutTimer, _readTimeoutMs, true);
    pipeline.addLast(READ_TIMEOUT_HANDLER_NAME, readTimeoutHandler);
    pipeline.addLast("codec", new HttpClientCodec());
    pipeline.addLast("http logger", new HttpRequestLoggingHandler());
    // Remove the following line if you don't want automatic content decompression.
    pipeline.addLast("inflater", new HttpContentDecompressor());
    //pipeline.addLast("handler", new GenericHttpResponseHandler(_responseProcessor, _keepAlive));
    pipeline.addLast("handler", _handler);
    //add a handler to deal with write timeouts
    pipeline.addLast("client request write timeout handler", new ExtendedWriteTimeoutHandler("netty client traffic", _timeoutTimer, _writeTimeoutMs, true));
    return pipeline;
}
Also used : ConnectionChannelRegistrationHandler(com.linkedin.databus2.core.container.netty.ConnectionChannelRegistrationHandler) LoggingHandler(org.jboss.netty.handler.logging.LoggingHandler) HttpRequestLoggingHandler(com.linkedin.databus2.core.container.HttpRequestLoggingHandler) ExtendedReadTimeoutHandler(com.linkedin.databus2.core.container.ExtendedReadTimeoutHandler) ExtendedWriteTimeoutHandler(com.linkedin.databus2.core.container.ExtendedWriteTimeoutHandler) HttpClientCodec(org.jboss.netty.handler.codec.http.HttpClientCodec) HttpRequestLoggingHandler(com.linkedin.databus2.core.container.HttpRequestLoggingHandler) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) InboundContainerStatisticsCollectingHandler(com.linkedin.databus2.core.container.netty.InboundContainerStatisticsCollectingHandler) HttpContentDecompressor(org.jboss.netty.handler.codec.http.HttpContentDecompressor)

Example 2 with ExtendedReadTimeoutHandler

use of com.linkedin.databus2.core.container.ExtendedReadTimeoutHandler in project databus by linkedin.

the class HttpServerPipelineFactory method getPipeline.

@Override
public ChannelPipeline getPipeline() throws Exception {
    //TODO   DDS-305: Rework the netty stats collector to use event-based stats aggregation
    /*  NettyStats nettyStats = _serverContainer.getNettyStats();
        CallCompletion getPipelineCompletion = nettyStats.isEnabled() ?
            nettyStats.getPipelineFactory_GetPipelineCallTracker().startCall() :
            null;*/
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = pipeline();
    //pipeline.addLast("in traffic",
    //                 new LoggingHandler("in traffic", InternalLogLevel.INFO, true));
    pipeline.addLast("auto group register ", new ConnectionChannelRegistrationHandler(_serverContainer.getHttpChannelGroup()));
    if (Logger.getRootLogger().isTraceEnabled()) {
        pipeline.addLast("netty server traffic", new LoggingHandler("netty server traffic", InternalLogLevel.DEBUG, true));
    }
    pipeline.addLast("outbound statistics collector", new OutboundContainerStatisticsCollectingHandler(_serverContainer.getContainerStatsCollector()));
    pipeline.addLast("decoder", new HttpRequestDecoder());
    pipeline.addLast("encoder", new HttpResponseEncoder());
    pipeline.addLast("http logger", new HttpRequestLoggingHandler());
    ExtendedReadTimeoutHandler readTimeoutHandler = new ExtendedReadTimeoutHandler("server container " + _serverContainer.getContainerStaticConfig().getId(), _serverContainer.getNetworkTimeoutTimer(), _serverContainer.getContainerStaticConfig().getReadTimeoutMs(), true);
    HttpRequestHandler reqHandler = new HttpRequestHandler(_serverContainer, readTimeoutHandler);
    pipeline.addLast("handler", reqHandler);
    if (_serverContainer.getContainerStaticConfig().getEnableHttpCompression()) {
        pipeline.addLast("deflater", new HttpContentCompressor());
    }
    pipeline.addLast("executionHandler", _serverContainer.getNettyExecHandler());
    DatabusRequestExecutionHandler dbusRequestHandler = new DatabusRequestExecutionHandler(_serverContainer);
    pipeline.addLast("databusRequestRunner", dbusRequestHandler);
    //add a handler to deal with write timeouts
    pipeline.addLast("server container write timeout handler", new ExtendedWriteTimeoutHandler("server container " + _serverContainer.getContainerStaticConfig().getId(), _serverContainer.getNetworkTimeoutTimer(), _serverContainer.getContainerStaticConfig().getWriteTimeoutMs(), true));
    return pipeline;
}
Also used : HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) ConnectionChannelRegistrationHandler(com.linkedin.databus2.core.container.netty.ConnectionChannelRegistrationHandler) LoggingHandler(org.jboss.netty.handler.logging.LoggingHandler) HttpRequestLoggingHandler(com.linkedin.databus2.core.container.HttpRequestLoggingHandler) OutboundContainerStatisticsCollectingHandler(com.linkedin.databus2.core.container.netty.OutboundContainerStatisticsCollectingHandler) HttpRequestHandler(com.linkedin.databus2.core.container.netty.HttpRequestHandler) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) HttpContentCompressor(org.jboss.netty.handler.codec.http.HttpContentCompressor) DatabusRequestExecutionHandler(com.linkedin.databus2.core.container.netty.DatabusRequestExecutionHandler) ExtendedReadTimeoutHandler(com.linkedin.databus2.core.container.ExtendedReadTimeoutHandler) ExtendedWriteTimeoutHandler(com.linkedin.databus2.core.container.ExtendedWriteTimeoutHandler) HttpRequestLoggingHandler(com.linkedin.databus2.core.container.HttpRequestLoggingHandler) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 3 with ExtendedReadTimeoutHandler

use of com.linkedin.databus2.core.container.ExtendedReadTimeoutHandler in project databus by linkedin.

the class SimpleClientPipelineFactory method testServerSimpleRequestTimeout.

@Test
public /**
   * Simulates the follow communication with no request timeout
   *
   * <table>
   * <th><td>client</td><td>server</td></th>
   * <tr><td>send "hello"</td><td></td></tr>
   * <tr><td></td><td>start read timeout</td></tr>
   * <tr><td>induce timeout</td><td></td></tr>
   * <tr><td>generate read timeout</td><td></td></tr>
   * <tr><td></td><td>disconnect client</td></tr>
   * <tr><td>send "eom"</td><td></td></tr>
   * <tr><td>detect it has been disconnected</td><td></td></tr>
   * </table>
   */
void testServerSimpleRequestTimeout() {
    SimpleTestServerConnection srvConn = new SimpleTestServerConnection(_eventFactory.getByteOrder());
    srvConn.setPipelineFactory(new SimpleServerPipelineFactory());
    boolean serverStarted = srvConn.startSynchronously(3, CONNECT_TIMEOUT_MS);
    Assert.assertTrue(serverStarted, "server started");
    SimpleTestClientConnection clientConn = new SimpleTestClientConnection(_eventFactory.getByteOrder());
    clientConn.setPipelineFactory(new SimpleClientPipelineFactory());
    boolean clientConnected = clientConn.startSynchronously(3, CONNECT_TIMEOUT_MS);
    Assert.assertTrue(clientConnected, "client connected");
    //hook in to key places in the server pipeline
    ChannelPipeline lastSrvConnPipeline = srvConn.getLastConnChannel().getPipeline();
    ExtendedReadTimeoutHandler srvTimeoutHandler = (ExtendedReadTimeoutHandler) lastSrvConnPipeline.get(ExtendedReadTimeoutHandler.class.getSimpleName());
    SimpleTestMessageReader srvMsgReader = (SimpleTestMessageReader) lastSrvConnPipeline.get(SimpleTestMessageReader.class.getSimpleName());
    ExceptionListenerTestHandler srvExceptionListener = (ExceptionListenerTestHandler) lastSrvConnPipeline.get(ExceptionListenerTestHandler.class.getSimpleName());
    //hook in to key places in the client pipeline
    ChannelPipeline clientPipeline = clientConn.getChannel().getPipeline();
    ExtendedReadTimeoutHandler clientTimeoutHandler = (ExtendedReadTimeoutHandler) clientPipeline.get(ExtendedReadTimeoutHandler.class.getSimpleName());
    ExceptionListenerTestHandler clientExceptionListener = (ExceptionListenerTestHandler) clientPipeline.get(ExceptionListenerTestHandler.class.getSimpleName());
    //send a request
    ChannelBuffer msg = ChannelBuffers.wrappedBuffer("hello".getBytes(Charset.defaultCharset()));
    ChannelFuture writeFuture = clientConn.getChannel().write(msg);
    //wait for the request to propagate
    try {
        writeFuture.await(10);
    } catch (InterruptedException ie) {
    }
    ;
    Assert.assertTrue(writeFuture.isDone(), "write completed");
    Assert.assertTrue(writeFuture.isSuccess(), "write successful");
    Assert.assertNull(srvExceptionListener.getLastException(), "no server read timeout");
    Assert.assertNull(clientExceptionListener.getLastException(), "no client read timeout");
    Assert.assertEquals(srvMsgReader.getMsg(), "hello", "message read");
    //start server read timeout
    srvTimeoutHandler.start(lastSrvConnPipeline.getContext(srvTimeoutHandler));
    //Timeout
    try {
        Thread.sleep(300);
    } catch (InterruptedException ie) {
    }
    ;
    ChannelBuffer msg2 = ChannelBuffers.wrappedBuffer("eom".getBytes(Charset.defaultCharset()));
    writeFuture = clientConn.getChannel().write(msg2);
    //wait for the respomse to propagate
    try {
        writeFuture.await(10);
    } catch (InterruptedException ie) {
    }
    ;
    //start the client timeout handler
    clientTimeoutHandler.start(clientPipeline.getContext(clientTimeoutHandler));
    Assert.assertTrue(srvExceptionListener.getLastException() instanceof ReadTimeoutException, "server read timeout");
    Assert.assertTrue(clientExceptionListener.getLastException() instanceof ClosedChannelException, "failed write");
    Assert.assertTrue(!lastSrvConnPipeline.getChannel().isConnected(), "client has been disconnected");
    Assert.assertTrue(!clientPipeline.getChannel().isConnected(), "disconnected from server");
    //stop server read timeout
    srvTimeoutHandler.stop();
    //stop client read timeout
    clientTimeoutHandler.stop();
    clientConn.stop();
    srvConn.stop();
}
Also used : SimpleTestClientConnection(com.linkedin.databus2.test.container.SimpleTestClientConnection) ChannelFuture(org.jboss.netty.channel.ChannelFuture) ClosedChannelException(java.nio.channels.ClosedChannelException) SimpleTestMessageReader(com.linkedin.databus2.test.container.SimpleTestMessageReader) ReadTimeoutException(org.jboss.netty.handler.timeout.ReadTimeoutException) SimpleTestServerConnection(com.linkedin.databus2.test.container.SimpleTestServerConnection) ExceptionListenerTestHandler(com.linkedin.databus2.test.container.ExceptionListenerTestHandler) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.testng.annotations.Test)

Example 4 with ExtendedReadTimeoutHandler

use of com.linkedin.databus2.core.container.ExtendedReadTimeoutHandler in project databus by linkedin.

the class SimpleClientPipelineFactory method testServerSimpleResponseTimeout.

@Test
public /**
   * Simulates the follow communication with no request timeout
   *
   * <table>
   * <th><td>client</td><td>server</td></th>
   * <tr><td>send "hello"</td><td></td></tr>
   * <tr><td></td><td>start read timeout</td></tr>
   * <tr><td>generate read timeout</td><td></td></tr>
   * <tr><td></td><td>induce timeout</td></tr>
   * <tr><td>disconnect from server</td><td></td></tr>
   * <tr><td></td><td>send "hi there"</td></tr>
   * <tr><td></td><td>detect it has been disconnected</td></tr>
   * </table>
   */
void testServerSimpleResponseTimeout() {
    SimpleTestServerConnection srvConn = new SimpleTestServerConnection(_eventFactory.getByteOrder());
    srvConn.setPipelineFactory(new SimpleServerPipelineFactory());
    boolean serverStarted = srvConn.startSynchronously(4, CONNECT_TIMEOUT_MS);
    Assert.assertTrue(serverStarted, "server started");
    SimpleTestClientConnection clientConn = new SimpleTestClientConnection(_eventFactory.getByteOrder());
    clientConn.setPipelineFactory(new SimpleClientPipelineFactory());
    boolean clientConnected = clientConn.startSynchronously(4, CONNECT_TIMEOUT_MS);
    Assert.assertTrue(clientConnected, "client connected");
    //hook in to key places in the server pipeline
    ChannelPipeline lastSrvConnPipeline = srvConn.getLastConnChannel().getPipeline();
    ExtendedReadTimeoutHandler srvTimeoutHandler = (ExtendedReadTimeoutHandler) lastSrvConnPipeline.get(ExtendedReadTimeoutHandler.class.getSimpleName());
    SimpleTestMessageReader srvMsgReader = (SimpleTestMessageReader) lastSrvConnPipeline.get(SimpleTestMessageReader.class.getSimpleName());
    ExceptionListenerTestHandler srvExceptionListener = (ExceptionListenerTestHandler) lastSrvConnPipeline.get(ExceptionListenerTestHandler.class.getSimpleName());
    //hook in to key places in the client pipeline
    ChannelPipeline clientPipeline = clientConn.getChannel().getPipeline();
    ExtendedReadTimeoutHandler clientTimeoutHandler = (ExtendedReadTimeoutHandler) clientPipeline.get(ExtendedReadTimeoutHandler.class.getSimpleName());
    ExceptionListenerTestHandler clientExceptionListener = (ExceptionListenerTestHandler) clientPipeline.get(ExceptionListenerTestHandler.class.getSimpleName());
    //send a request
    ChannelBuffer msg = ChannelBuffers.wrappedBuffer("hello".getBytes(Charset.defaultCharset()));
    clientConn.getChannel().write(msg);
    //wait for the request to propagate
    try {
        Thread.sleep(10);
    } catch (InterruptedException ie) {
    }
    ;
    Assert.assertNull(srvExceptionListener.getLastException(), "no server read timeout");
    Assert.assertNull(clientExceptionListener.getLastException(), "no client read timeout");
    Assert.assertEquals(srvMsgReader.getMsg(), "hello", "message read");
    //start server read timeout
    srvTimeoutHandler.start(lastSrvConnPipeline.getContext(srvTimeoutHandler));
    ChannelBuffer msg2 = ChannelBuffers.wrappedBuffer("eom".getBytes(Charset.defaultCharset()));
    clientConn.getChannel().write(msg2);
    //start the client timeout handler
    clientTimeoutHandler.start(clientPipeline.getContext(clientTimeoutHandler));
    Assert.assertNull(srvExceptionListener.getLastException(), "no server read timeout");
    Assert.assertNull(clientExceptionListener.getLastException(), "no client read timeout");
    Assert.assertEquals(srvMsgReader.getMsg(), "eom", "message read");
    //stop server read timeout
    srvTimeoutHandler.stop();
    ChannelBuffer resp = ChannelBuffers.wrappedBuffer("hi there".getBytes(Charset.defaultCharset()));
    //Induce timeout
    try {
        Thread.sleep(500);
    } catch (InterruptedException ie) {
    }
    ;
    lastSrvConnPipeline.getChannel().write(resp);
    //wait for the response to propagate
    try {
        Thread.sleep(10);
    } catch (InterruptedException ie) {
    }
    ;
    Assert.assertTrue(srvExceptionListener.getLastException() instanceof ClosedChannelException, "no server read timeout but client has disconnected");
    Assert.assertTrue(clientExceptionListener.getLastException() instanceof ReadTimeoutException, "client read timeout");
    Assert.assertTrue(!lastSrvConnPipeline.getChannel().isConnected(), "client has disconnected");
    Assert.assertTrue(!clientPipeline.getChannel().isConnected(), "closed connection to server");
    //stop client read timeout
    clientTimeoutHandler.stop();
    clientConn.stop();
    srvConn.stop();
}
Also used : SimpleTestClientConnection(com.linkedin.databus2.test.container.SimpleTestClientConnection) ClosedChannelException(java.nio.channels.ClosedChannelException) SimpleTestMessageReader(com.linkedin.databus2.test.container.SimpleTestMessageReader) ReadTimeoutException(org.jboss.netty.handler.timeout.ReadTimeoutException) SimpleTestServerConnection(com.linkedin.databus2.test.container.SimpleTestServerConnection) ExceptionListenerTestHandler(com.linkedin.databus2.test.container.ExceptionListenerTestHandler) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.testng.annotations.Test)

Example 5 with ExtendedReadTimeoutHandler

use of com.linkedin.databus2.core.container.ExtendedReadTimeoutHandler in project databus by linkedin.

the class SimpleClientPipelineFactory method getPipeline.

@Override
public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline newPipeline = Channels.pipeline();
    newPipeline.addLast(ExtendedReadTimeoutHandler.class.getSimpleName(), new ExtendedReadTimeoutHandler("test", null, 100, true));
    newPipeline.addLast(ExceptionListenerTestHandler.class.getSimpleName(), new ExceptionListenerTestHandler());
    newPipeline.addLast(SimpleTestMessageReader.class.getSimpleName(), new SimpleTestMessageReader());
    return newPipeline;
}
Also used : SimpleTestMessageReader(com.linkedin.databus2.test.container.SimpleTestMessageReader) ExceptionListenerTestHandler(com.linkedin.databus2.test.container.ExceptionListenerTestHandler) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Aggregations

ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)8 ExceptionListenerTestHandler (com.linkedin.databus2.test.container.ExceptionListenerTestHandler)5 SimpleTestMessageReader (com.linkedin.databus2.test.container.SimpleTestMessageReader)5 SimpleTestClientConnection (com.linkedin.databus2.test.container.SimpleTestClientConnection)4 SimpleTestServerConnection (com.linkedin.databus2.test.container.SimpleTestServerConnection)4 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)4 Test (org.testng.annotations.Test)4 ExtendedReadTimeoutHandler (com.linkedin.databus2.core.container.ExtendedReadTimeoutHandler)3 ExtendedWriteTimeoutHandler (com.linkedin.databus2.core.container.ExtendedWriteTimeoutHandler)3 LoggingHandler (org.jboss.netty.handler.logging.LoggingHandler)3 HttpRequestLoggingHandler (com.linkedin.databus2.core.container.HttpRequestLoggingHandler)2 ConnectionChannelRegistrationHandler (com.linkedin.databus2.core.container.netty.ConnectionChannelRegistrationHandler)2 ClosedChannelException (java.nio.channels.ClosedChannelException)2 ReadTimeoutException (org.jboss.netty.handler.timeout.ReadTimeoutException)2 DatabusRequestExecutionHandler (com.linkedin.databus2.core.container.netty.DatabusRequestExecutionHandler)1 HttpRequestHandler (com.linkedin.databus2.core.container.netty.HttpRequestHandler)1 InboundContainerStatisticsCollectingHandler (com.linkedin.databus2.core.container.netty.InboundContainerStatisticsCollectingHandler)1 OutboundContainerStatisticsCollectingHandler (com.linkedin.databus2.core.container.netty.OutboundContainerStatisticsCollectingHandler)1 SimpleBinaryDatabusRequestDecoder (com.linkedin.databus2.core.container.request.SimpleBinaryDatabusRequestDecoder)1 SimpleBinaryDatabusResponseEncoder (com.linkedin.databus2.core.container.request.SimpleBinaryDatabusResponseEncoder)1