Search in sources :

Example 1 with WriteTimeoutHandler

use of org.jboss.netty.handler.timeout.WriteTimeoutHandler in project pinpoint by naver.

the class PinpointClientPipelineFactory method getPipeline.

@Override
public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline pipeline = Channels.pipeline();
    pipeline.addLast("encoder", new PacketEncoder());
    pipeline.addLast("decoder", new PacketDecoder());
    long pingDelay = pinpointClientFactory.getPingDelay();
    long enableWorkerPacketDelay = pinpointClientFactory.getEnableWorkerPacketDelay();
    long timeoutMillis = pinpointClientFactory.getTimeoutMillis();
    DefaultPinpointClientHandler defaultPinpointClientHandler = new DefaultPinpointClientHandler(pinpointClientFactory, pingDelay, enableWorkerPacketDelay, timeoutMillis);
    pipeline.addLast("writeTimeout", new WriteTimeoutHandler(defaultPinpointClientHandler.getChannelTimer(), 3000, TimeUnit.MILLISECONDS));
    pipeline.addLast("socketHandler", defaultPinpointClientHandler);
    return pipeline;
}
Also used : PacketEncoder(com.navercorp.pinpoint.rpc.codec.PacketEncoder) WriteTimeoutHandler(org.jboss.netty.handler.timeout.WriteTimeoutHandler) PacketDecoder(com.navercorp.pinpoint.rpc.codec.PacketDecoder) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 2 with WriteTimeoutHandler

use of org.jboss.netty.handler.timeout.WriteTimeoutHandler in project smscgateway by RestComm.

the class TestSmppClient method createSession.

protected DefaultSmppSession createSession(Channel channel, SmppSessionConfiguration config, SmppSessionHandler sessionHandler) throws SmppTimeoutException, SmppChannelException, InterruptedException {
    TestSmppSession session = new TestSmppSession(SmppSession.Type.CLIENT, config, channel, sessionHandler, monitorExecutor);
    // add SSL handler
    if (config.isUseSsl()) {
        SslConfiguration sslConfig = config.getSslConfiguration();
        if (sslConfig == null)
            throw new IllegalStateException("sslConfiguration must be set");
        try {
            SslContextFactory factory = new SslContextFactory(sslConfig);
            SSLEngine sslEngine = factory.newSslEngine();
            sslEngine.setUseClientMode(true);
            channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_SSL_NAME, new SslHandler(sslEngine));
        } catch (Exception e) {
            throw new SmppChannelConnectException("Unable to create SSL session]: " + e.getMessage(), e);
        }
    }
    // add the thread renamer portion to the pipeline
    if (config.getName() != null) {
        channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_THREAD_RENAMER_NAME, new SmppSessionThreadRenamer(config.getName()));
    } else {
    // logger.warn("Session configuration did not have a name set - skipping threadRenamer in pipeline");
    }
    // create the logging handler (for bytes sent/received on wire)
    SmppSessionLogger loggingHandler = new SmppSessionLogger(DefaultSmppSession.class.getCanonicalName(), config.getLoggingOptions());
    channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_LOGGER_NAME, loggingHandler);
    // add a writeTimeout handler after the logger
    if (config.getWriteTimeout() > 0) {
        WriteTimeoutHandler writeTimeoutHandler = new WriteTimeoutHandler(new org.jboss.netty.util.HashedWheelTimer(), /* writeTimeoutTimer */
        config.getWriteTimeout(), TimeUnit.MILLISECONDS);
        channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_WRITE_TIMEOUT_NAME, writeTimeoutHandler);
    }
    // add a new instance of a decoder (that takes care of handling frames)
    channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_PDU_DECODER_NAME, new SmppSessionPduDecoder(session.getTranscoder()));
    // create a new wrapper around a session to pass the pdu up the chain
    channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_WRAPPER_NAME, new SmppSessionWrapper(session));
    return session;
}
Also used : SmppSessionThreadRenamer(com.cloudhopper.smpp.channel.SmppSessionThreadRenamer) SSLEngine(javax.net.ssl.SSLEngine) SmppSessionPduDecoder(com.cloudhopper.smpp.channel.SmppSessionPduDecoder) SmppSessionWrapper(com.cloudhopper.smpp.channel.SmppSessionWrapper) WriteTimeoutHandler(org.jboss.netty.handler.timeout.WriteTimeoutHandler) DefaultSmppSession(com.cloudhopper.smpp.impl.DefaultSmppSession) SslHandler(org.jboss.netty.handler.ssl.SslHandler) SmppChannelException(com.cloudhopper.smpp.type.SmppChannelException) SmppTimeoutException(com.cloudhopper.smpp.type.SmppTimeoutException) SmppChannelConnectException(com.cloudhopper.smpp.type.SmppChannelConnectException) UnrecoverablePduException(com.cloudhopper.smpp.type.UnrecoverablePduException) RecoverablePduException(com.cloudhopper.smpp.type.RecoverablePduException) SslContextFactory(com.cloudhopper.smpp.ssl.SslContextFactory) SmppSessionLogger(com.cloudhopper.smpp.channel.SmppSessionLogger) SslConfiguration(com.cloudhopper.smpp.ssl.SslConfiguration) SmppChannelConnectException(com.cloudhopper.smpp.type.SmppChannelConnectException)

Example 3 with WriteTimeoutHandler

use of org.jboss.netty.handler.timeout.WriteTimeoutHandler in project pinpoint by naver.

the class Connection method connect.

void connect(SocketAddressProvider remoteAddressProvider, boolean reconnect, PipelineFactory pipelineFactory) {
    Objects.requireNonNull(remoteAddressProvider, "remoteAddress");
    final ChannelPipeline pipeline = pipelineFactory.newPipeline();
    Timer channelTimer = createTimer("Pinpoint-PinpointClientHandler-Timer");
    final ChannelHandler writeTimeout = new WriteTimeoutHandler(channelTimer, 3000, TimeUnit.MILLISECONDS);
    pipeline.addLast("writeTimeout", writeTimeout);
    this.pinpointClientHandler = this.clientHandlerFactory.newClientHandler(connectionFactory, remoteAddressProvider, channelTimer, reconnect);
    if (pinpointClientHandler instanceof SimpleChannelHandler) {
        pipeline.addLast("socketHandler", (SimpleChannelHandler) this.pinpointClientHandler);
    } else {
        throw new IllegalArgumentException("invalid pinpointClientHandler");
    }
    final SocketAddress remoteAddress = remoteAddressProvider.resolve();
    this.connectFuture = connect0(remoteAddress, pipeline);
}
Also used : Timer(org.jboss.netty.util.Timer) HashedWheelTimer(org.jboss.netty.util.HashedWheelTimer) SimpleChannelHandler(org.jboss.netty.channel.SimpleChannelHandler) WriteTimeoutHandler(org.jboss.netty.handler.timeout.WriteTimeoutHandler) SimpleChannelHandler(org.jboss.netty.channel.SimpleChannelHandler) ChannelHandler(org.jboss.netty.channel.ChannelHandler) SocketAddress(java.net.SocketAddress) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Aggregations

WriteTimeoutHandler (org.jboss.netty.handler.timeout.WriteTimeoutHandler)3 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)2 SmppSessionLogger (com.cloudhopper.smpp.channel.SmppSessionLogger)1 SmppSessionPduDecoder (com.cloudhopper.smpp.channel.SmppSessionPduDecoder)1 SmppSessionThreadRenamer (com.cloudhopper.smpp.channel.SmppSessionThreadRenamer)1 SmppSessionWrapper (com.cloudhopper.smpp.channel.SmppSessionWrapper)1 DefaultSmppSession (com.cloudhopper.smpp.impl.DefaultSmppSession)1 SslConfiguration (com.cloudhopper.smpp.ssl.SslConfiguration)1 SslContextFactory (com.cloudhopper.smpp.ssl.SslContextFactory)1 RecoverablePduException (com.cloudhopper.smpp.type.RecoverablePduException)1 SmppChannelConnectException (com.cloudhopper.smpp.type.SmppChannelConnectException)1 SmppChannelException (com.cloudhopper.smpp.type.SmppChannelException)1 SmppTimeoutException (com.cloudhopper.smpp.type.SmppTimeoutException)1 UnrecoverablePduException (com.cloudhopper.smpp.type.UnrecoverablePduException)1 PacketDecoder (com.navercorp.pinpoint.rpc.codec.PacketDecoder)1 PacketEncoder (com.navercorp.pinpoint.rpc.codec.PacketEncoder)1 SocketAddress (java.net.SocketAddress)1 SSLEngine (javax.net.ssl.SSLEngine)1 ChannelHandler (org.jboss.netty.channel.ChannelHandler)1 SimpleChannelHandler (org.jboss.netty.channel.SimpleChannelHandler)1