org.jboss.netty.channel.ChannelHandler Java Examples

The following examples show how to use org.jboss.netty.channel.ChannelHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Bootstrap.java    From android-netty with Apache License 2.0 6 votes vote down vote up
/**
 * Dependency injection friendly convenience method for
 * {@link #setPipeline(ChannelPipeline)} which sets the default pipeline of
 * this bootstrap from an ordered map.
 * <p>
 * Please note that this method is a convenience method that works only
 * when <b>1)</b> you create only one channel from this bootstrap (e.g.
 * one-time client-side or connectionless channel) or <b>2)</b> all handlers
 * in the pipeline is stateless.  You have to use
 * {@link #setPipelineFactory(ChannelPipelineFactory)} if <b>1)</b> your
 * pipeline contains a stateful {@link ChannelHandler} and <b>2)</b> one or
 * more channels are going to be created by this bootstrap (e.g. server-side
 * channels).
 *
 * @throws IllegalArgumentException
 *         if the specified map is not an ordered map
 */
public void setPipelineAsMap(Map<String, ChannelHandler> pipelineMap) {
    if (pipelineMap == null) {
        throw new NullPointerException("pipelineMap");
    }

    if (!isOrderedMap(pipelineMap)) {
        throw new IllegalArgumentException(
                "pipelineMap is not an ordered map. " +
                "Please use " +
                LinkedHashMap.class.getName() + '.');
    }

    ChannelPipeline pipeline = pipeline();
    for (Map.Entry<String, ChannelHandler> e: pipelineMap.entrySet()) {
        pipeline.addLast(e.getKey(), e.getValue());
    }

    setPipeline(pipeline);
}
 
Example #2
Source File: FrameDecoder.java    From android-netty with Apache License 2.0 6 votes vote down vote up
/**
 * Replace this {@link FrameDecoder} in the {@link ChannelPipeline} with the
 * given {@link ChannelHandler}. All remaining bytes in the
 * {@link ChannelBuffer} will get send to the new {@link ChannelHandler}
 * that was used as replacement
 * 
 */
public void replace(String handlerName, ChannelHandler handler) {
	if (ctx == null) {
		throw new IllegalStateException("Replace cann only be called once the FrameDecoder is added to the ChannelPipeline");
	}
	ChannelPipeline pipeline = ctx.getPipeline();
	pipeline.addAfter(ctx.getName(), handlerName, handler);

	try {
		if (cumulation != null) {
			Channels.fireMessageReceived(ctx, cumulation.readBytes(actualReadableBytes()));
		}
	} finally {
		pipeline.remove(this);
	}
}
 
Example #3
Source File: ControllerConnector.java    From FlowSpaceFirewall with Apache License 2.0 6 votes vote down vote up
/**
 * creates a new pipeline for interacting with the
 * controller.  This is where the controllerHandler and
 * the timeouthandler come into play
 * @return the pipeline (ChannelPipeline) for a new Socket.
 */
private ChannelPipeline getPipeline(){
	ChannelPipeline pipe = Channels.pipeline();
    
	ChannelHandler idleHandler = new IdleStateHandler(timer, 20, 25, 0);
    ChannelHandler readTimeoutHandler = new ReadTimeoutHandler(timer, 30);
    OFControllerChannelHandler controllerHandler = new OFControllerChannelHandler();
	
       pipe.addLast("ofmessagedecoder", new OFMessageDecoder());
       pipe.addLast("ofmessageencoder", new OFMessageEncoder());
       pipe.addLast("idle", idleHandler);
       pipe.addLast("timeout", readTimeoutHandler);
       pipe.addLast("handshaketimeout",
                    new ControllerHandshakeTimeoutHandler(controllerHandler, timer, 15));
       pipe.addLast("handler", controllerHandler);
       return pipe;
}
 
Example #4
Source File: TestPinpointServerAcceptor.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
public TestPinpointServerAcceptor(ServerMessageListenerFactory messageListenerFactory, ServerStreamChannelMessageHandler streamChannelMessageHandler, ChannelHandler messageHandler) {
    PinpointServerAcceptor serverAcceptor = new PinpointServerAcceptor();

    if (messageListenerFactory != null) {
        serverAcceptor.setMessageListenerFactory(messageListenerFactory);
    }

    if (streamChannelMessageHandler != null) {
        serverAcceptor.setServerStreamChannelMessageHandler(streamChannelMessageHandler);
    }

    if (messageHandler != null) {
        serverAcceptor.setMessageHandler(messageHandler);
    }

    this.serverAcceptor = serverAcceptor;
}
 
Example #5
Source File: Connection.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
void connect(SocketAddressProvider remoteAddressProvider, boolean reconnect, PipelineFactory pipelineFactory) {
    Assert.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);
}
 
Example #6
Source File: NettyCodecAdapter.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public NettyCodecAdapter(Codec2 codec, URL url, com.alibaba.dubbo.remoting.ChannelHandler handler) {
    this.codec = codec;
    this.url = url;
    this.handler = handler;
    int b = url.getPositiveParameter(Constants.BUFFER_KEY, Constants.DEFAULT_BUFFER_SIZE);
    this.bufferSize = b >= Constants.MIN_BUFFER_SIZE && b <= Constants.MAX_BUFFER_SIZE ? b : Constants.DEFAULT_BUFFER_SIZE;
}
 
Example #7
Source File: NettyCodecAdapter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public NettyCodecAdapter(Codec2 codec, URL url, com.alibaba.dubbo.remoting.ChannelHandler handler) {
    this.codec = codec;
    this.url = url;
    this.handler = handler;
    int b = url.getPositiveParameter(Constants.BUFFER_KEY, Constants.DEFAULT_BUFFER_SIZE);
    this.bufferSize = b >= Constants.MIN_BUFFER_SIZE && b <= Constants.MAX_BUFFER_SIZE ? b : Constants.DEFAULT_BUFFER_SIZE;
}
 
Example #8
Source File: NettyCodecAdapter.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
public NettyCodecAdapter(Codec2 codec, URL url, com.alibaba.dubbo.remoting.ChannelHandler handler) {
    this.codec = codec;
    this.url = url;
    this.handler = handler;
    int b = url.getPositiveParameter(Constants.BUFFER_KEY, Constants.DEFAULT_BUFFER_SIZE);
    this.bufferSize = b >= Constants.MIN_BUFFER_SIZE && b <= Constants.MAX_BUFFER_SIZE ? b : Constants.DEFAULT_BUFFER_SIZE;
}
 
Example #9
Source File: Connection.java    From nfs-client-java with Apache License 2.0 5 votes vote down vote up
/**
 * @param remoteHost A unique name for the host to which the connection is being made.
 * @param port The remote host port being used for the connection.
 * @param usePrivilegedPort
 *            <ul>
 *            <li>If <code>true</code>, use a privileged port (below 1024)
 *            for RPC communication.</li>
 *            <li>If <code>false</code>, use any non-privileged port for RPC
 *            communication.</li>
 *            </ul>
 */
public Connection(String remoteHost, int port, boolean usePrivilegedPort) {
    _remoteHost = remoteHost;
    _port = port;
    _usePrivilegedPort = usePrivilegedPort;
    _clientBootstrap = new ClientBootstrap(NetMgr.getInstance().getFactory());
    // Configure the client.
    _clientBootstrap.setOption(REMOTE_ADDRESS_OPTION, new InetSocketAddress(_remoteHost, _port));
    _clientBootstrap.setOption("connectTimeoutMillis", CONNECT_TIMEOUT);  // set
                                                                          // connection
                                                                          // timeout
                                                                          // value
                                                                          // to
                                                                          // 10
                                                                          // seconds
    _clientBootstrap.setOption("tcpNoDelay", true);
    _clientBootstrap.setOption("keepAlive", true);
    _clientBootstrap.setOption(CONNECTION_OPTION, this);

    // Configure the pipeline factory.
    _clientBootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        /**
         * Netty helper instance.
         */
        private final ChannelHandler ioHandler = new ClientIOHandler(_clientBootstrap);

        /* (non-Javadoc)
         * @see org.jboss.netty.channel.ChannelPipelineFactory#getPipeline()
         */
        public ChannelPipeline getPipeline() throws Exception {
            return Channels.pipeline(new RPCRecordDecoder(), ioHandler);
        }
    });
}
 
Example #10
Source File: NettyCodecAdapter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public NettyCodecAdapter(Codec2 codec, URL url, com.alibaba.dubbo.remoting.ChannelHandler handler) {
    this.codec = codec;
    this.url = url;
    this.handler = handler;
    int b = url.getPositiveParameter(Constants.BUFFER_KEY, Constants.DEFAULT_BUFFER_SIZE);
    this.bufferSize = b >= Constants.MIN_BUFFER_SIZE && b <= Constants.MAX_BUFFER_SIZE ? b : Constants.DEFAULT_BUFFER_SIZE;
}
 
Example #11
Source File: PinpointServerAcceptor.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
public void setMessageHandler(final ChannelHandler messageHandler) {
    Assert.requireNonNull(messageHandler, "messageHandler");
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = pipelineFactory.newPipeline();
            pipeline.addLast("handler", messageHandler);

            return pipeline;
        }
    });
}
 
Example #12
Source File: NettyCodecAdapter.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public NettyCodecAdapter(Codec2 codec, URL url, com.alibaba.dubbo.remoting.ChannelHandler handler) {
    this.codec = codec;
    this.url = url;
    this.handler = handler;
    int b = url.getPositiveParameter(Constants.BUFFER_KEY, Constants.DEFAULT_BUFFER_SIZE);
    this.bufferSize = b >= Constants.MIN_BUFFER_SIZE && b <= Constants.MAX_BUFFER_SIZE ? b : Constants.DEFAULT_BUFFER_SIZE;
}
 
Example #13
Source File: NettyCodecAdapter.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public NettyCodecAdapter(Codec2 codec, URL url, com.alibaba.dubbo.remoting.ChannelHandler handler) {
    this.codec = codec;
    this.url = url;
    this.handler = handler;
    int b = url.getPositiveParameter(Constants.BUFFER_KEY, Constants.DEFAULT_BUFFER_SIZE);
    this.bufferSize = b >= Constants.MIN_BUFFER_SIZE && b <= Constants.MAX_BUFFER_SIZE ? b : Constants.DEFAULT_BUFFER_SIZE;
}
 
Example #14
Source File: NettyCodecAdapter.java    From anima with GNU General Public License v3.0 4 votes vote down vote up
public ChannelHandler getEncoder() {
    return encoder;
}
 
Example #15
Source File: SwitchableLineBasedFrameDecoderFactory.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
public ChannelHandler create(ChannelPipeline pipeline) {
    return new SwitchableLineBasedFrameDecoder(maxLineLength, false);
}
 
Example #16
Source File: TestPinpointServerAcceptor.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
public TestPinpointServerAcceptor(ChannelHandler messageHandler) {
    this(null, null, messageHandler);
}
 
Example #17
Source File: LineDelimiterBasedChannelHandlerFactory.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
public ChannelHandler create(ChannelPipeline pipeline) {
    return new LineBasedFrameDecoder(maxLineLength, false, !FAIL_FAST);
}
 
Example #18
Source File: AllButStartTlsLineChannelHandlerFactory.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
public ChannelHandler create(ChannelPipeline pipeline) {
    return new AllButStartTlsLineBasedChannelHandler(pipeline, maxFrameLength, false);
}
 
Example #19
Source File: NettyCodecAdapter.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public ChannelHandler getDecoder() {
    return decoder;
}
 
Example #20
Source File: NettyCodecAdapter.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public ChannelHandler getEncoder() {
    return encoder;
}
 
Example #21
Source File: TimestampPipelineFactoryLite.java    From spliceengine with GNU Affero General Public License v3.0 4 votes vote down vote up
public TimestampPipelineFactoryLite(ChannelHandler handler) {
    tsHandler = handler;
}
 
Example #22
Source File: TSOChannelHandler.java    From phoenix-omid with Apache License 2.0 4 votes vote down vote up
TSOPipelineFactory(ChannelHandler handler) {
    this.handler = handler;
}
 
Example #23
Source File: NettyCodecAdapter.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
public ChannelHandler getEncoder() {
    return encoder;
}
 
Example #24
Source File: NettyCodecAdapter.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
public ChannelHandler getDecoder() {
    return decoder;
}
 
Example #25
Source File: NettyCodecAdapter.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public ChannelHandler getEncoder() {
    return encoder;
}
 
Example #26
Source File: NettyCodecAdapter.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public ChannelHandler getDecoder() {
    return decoder;
}
 
Example #27
Source File: NettyCodecAdapter.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public ChannelHandler getEncoder() {
    return encoder;
}
 
Example #28
Source File: NettyCodecAdapter.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public ChannelHandler getDecoder() {
    return decoder;
}
 
Example #29
Source File: NettyCodecAdapter.java    From anima with GNU General Public License v3.0 4 votes vote down vote up
public ChannelHandler getDecoder() {
    return decoder;
}
 
Example #30
Source File: NettyCodecAdapter.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
public ChannelHandler getEncoder() {
    return encoder;
}