Java 类org.jboss.netty.channel.ChannelHandler 实例源码

项目:BJAF3.x    文件:CodecFactory.java   
public static ChannelHandler createDecoder() {
    int maxObjectSize = AppProperties.getAsInt("rpc_common_maxObjectSize",
            1024 * 1024);
    String f = AppProperties.get("rpc_common_codec", "java");
    if (f.equalsIgnoreCase("java")) {
        return new ObjectDecoder(maxObjectSize,
                ClassResolvers.softCachingConcurrentResolver(null));
    } else if (f.equalsIgnoreCase("jbossSerialization")) {
        return new JBossSerializationDecoder(maxObjectSize);
    } else if (f.equalsIgnoreCase("json")) {
        throw new AppRuntimeException("not support " + f + " yet!");
    } else if (f.equalsIgnoreCase("hessian")) {
        return new HessianDecoder(maxObjectSize);
    } else {
        throw new AppRuntimeException("not support " + f + " yet!");
    }
}
项目:Camel    文件:NettyHttpGetWithInvalidMessageTest.java   
@Override
protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry registry = super.createRegistry();

    // setup the String encoder and decoder 

    StringDecoder stringDecoder = new StringDecoder();
    registry.bind("string-decoder", stringDecoder);

    StringEncoder stringEncoder = new StringEncoder();
    registry.bind("string-encoder", stringEncoder);

    List<ChannelHandler> decoders = new ArrayList<ChannelHandler>();
    decoders.add(stringDecoder);

    List<ChannelHandler> encoders = new ArrayList<ChannelHandler>();
    encoders.add(stringEncoder);

    registry.bind("encoders", encoders);
    registry.bind("decoders", decoders);

    return registry;
}
项目:dataworks-zeus    文件:MasterServer.java   
public MasterServer(final ChannelHandler handler){
    NioServerSocketChannelFactory channelFactory=
        new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
    bootstrap=new ServerBootstrap(channelFactory);
    pipelineFactory=new ChannelPipelineFactory(){
        private final ProtobufVarint32LengthFieldPrepender frameEncoder = new ProtobufVarint32LengthFieldPrepender();
        private final ProtobufEncoder protobufEncoder = new ProtobufEncoder();
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline p = pipeline();
            p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder());
            p.addLast("protobufDecoder",new ProtobufDecoder(Protocol.SocketMessage.getDefaultInstance()));
            p.addLast("frameEncoder", frameEncoder);
            p.addLast("protobufEncoder", protobufEncoder);
            p.addLast("handler", handler);
            return p;
        }

    };
    try {
        bootstrap.setPipeline(pipelineFactory.getPipeline());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:dataworks-zeus    文件:MasterServer.java   
public MasterServer(final ChannelHandler handler){
    NioServerSocketChannelFactory channelFactory=
        new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
    bootstrap=new ServerBootstrap(channelFactory);
    pipelineFactory=new ChannelPipelineFactory(){
        private final ProtobufVarint32LengthFieldPrepender frameEncoder = new ProtobufVarint32LengthFieldPrepender();
        private final ProtobufEncoder protobufEncoder = new ProtobufEncoder();
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline p = pipeline();
            p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder());
            p.addLast("protobufDecoder",new ProtobufDecoder(Protocol.SocketMessage.getDefaultInstance()));
            p.addLast("frameEncoder", frameEncoder);
            p.addLast("protobufEncoder", protobufEncoder);
            p.addLast("handler", handler);
            return p;
        }

    };
    try {
        bootstrap.setPipeline(pipelineFactory.getPipeline());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:my-dev    文件:NettyClient.java   
private static ClientBootstrap prepareBootstrap(Logger logger, final ChannelPipeline pipeline,
        ChannelHandler handler, SslHandler sslHandler, int connectTimeoutMillis) {
    ClientBootstrap bootstrap = new ClientBootstrap(nioClientSocketChannelFactory);
    bootstrap.setOption("tcpNoDelay", true);
    bootstrap.setOption("reuseAddress", true);
    bootstrap.setOption("connectTimeoutMillis", connectTimeoutMillis);
    bootstrap.setOption("writeBufferHighWaterMark", 10 * 1024 * 1024);

    if (sslHandler != null) {
        pipeline.addFirst("ssl", sslHandler);
    }
    if (handler != null) {
        pipeline.addLast("handler", handler);
    }

    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            return pipeline;
        }
    });
    return bootstrap;
}
项目:zeus3    文件:MasterServer.java   
public MasterServer(final ChannelHandler handler){
    NioServerSocketChannelFactory channelFactory=
        new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
    bootstrap=new ServerBootstrap(channelFactory);
    pipelineFactory=new ChannelPipelineFactory(){
        private final ProtobufVarint32LengthFieldPrepender frameEncoder = new ProtobufVarint32LengthFieldPrepender();
        private final ProtobufEncoder protobufEncoder = new ProtobufEncoder();
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline p = pipeline();
            p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder());
            p.addLast("protobufDecoder",new ProtobufDecoder(Protocol.SocketMessage.getDefaultInstance()));
            p.addLast("frameEncoder", frameEncoder);
            p.addLast("protobufEncoder", protobufEncoder);
            p.addLast("handler", handler);
            return p;
        }

    };
    try {
        bootstrap.setPipeline(pipelineFactory.getPipeline());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:FlowSpaceFirewall    文件:ControllerConnector.java   
/**
 * 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;
}
项目:netty-isdn-transport    文件:IsdnHandlerFactory.java   
public static ChannelHandler getIsdnClientStateMachineHandler(IsdnChannel channel, String handlerName) {

        StateMachine sm = StateMachineFactory.getInstance(Transition.class).create(IsdnConnectionHandler.PLCI_IDLE,
                new IsdnConnectionHandler());

        StateContextLookup stateContextLookup = new ChannelHandlerContextLookup(new DefaultStateContextFactory(),
                channel, handlerName);

        StateMachineProxyBuilder proxyBuilder = new StateMachineProxyBuilder();
        proxyBuilder.setName("IsdnClientChannelStateMachine");
        proxyBuilder.setStateContextLookup(stateContextLookup);
        // proxyBuilder.setEventArgumentsInterceptor(new
        // NettyEventInterceptor());
        proxyBuilder.setEventFactory(new NettyEventFactory());

        IStateMachineChannelHandler engine = proxyBuilder.create(IStateMachineChannelHandler.class, sm);
        return new ChannelAllCoverageWrapper(new DefaultStateMachineChannelHandler(engine));

    }
项目:netty-isdn-transport    文件:IsdnHandlerFactory.java   
public static ChannelHandler getAcceptedChannelStateMachineHandler(IsdnChannel channel, String handlerName) {

        StateMachine sm = StateMachineFactory.getInstance(Transition.class).create(
                IsdnConnectionHandler.P4_WF_CONNECT_ACTIVE_IND, new IsdnConnectionHandler());

        StateContextLookup stateContextLookup = new ChannelHandlerContextLookup(new DefaultStateContextFactory(),
                channel, handlerName);

        StateMachineProxyBuilder proxyBuilder = new StateMachineProxyBuilder();
        proxyBuilder.setName("IsdnAcceptedChannelStateMachine");
        proxyBuilder.setStateContextLookup(stateContextLookup);
        // proxyBuilder.setEventArgumentsInterceptor(new
        // NettyEventInterceptor());
        proxyBuilder.setEventFactory(new NettyEventFactory());

        IStateMachineChannelHandler engine = proxyBuilder.create(IStateMachineChannelHandler.class, sm);
        return new ChannelAllCoverageWrapper(new DefaultStateMachineChannelHandler(engine));

    }
项目:android-netty    文件:FrameDecoder.java   
/**
 * 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);
    }
}
项目:android-netty    文件:Bootstrap.java   
/**
 * 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);
}
项目:proactive-component-monitoring    文件:PNPClientPipelineFactory.java   
public ChannelPipeline getPipeline() throws Exception {
    ChannelPipeline p = Channels.pipeline();

    if (extraHandlers != null) {
        for (final ChannelHandler handler : this.extraHandlers.getClientHandlers()) {
            p.addLast("" + handler.hashCode(), handler);
        }
    }

    // Do not use FixedLengthFrameDecoder provided by netty to avoid
    // copy and an extra handler to parse the messages
    //        p.addLast("pnpDecoder", new PNPClientFrameDecoder());
    p.addLast("pnpDecoder", new PNPClientFrameDecoder());

    p.addLast("frameEncoder", new LengthFieldPrepender(4));
    p.addLast("pnpEncoder", new PNPEncoder());

    long idle_timeout = PNPConfig.PA_PNP_IDLE_TIMEOUT.getValue();
    if (idle_timeout != 0) {
        p.addLast("timer", new IdleStateHandler(timer, 0, idle_timeout, 0, TimeUnit.MILLISECONDS));
    }

    p.addLast(PNPClientHandler.NAME, new PNPClientHandler());
    return p;
}
项目:proactive-component-monitoring    文件:PNPServerPipelineFactory.java   
public ChannelPipeline getPipeline() throws Exception {
    PNPServerHandler pnpServerHandler = new PNPServerHandler(this.executor);
    ChannelPipeline p = Channels.pipeline();

    if (extraHandlers != null) {
        for (final ChannelHandler handler : extraHandlers.getServertHandlers()) {
            p.addLast("" + handler.hashCode(), handler);
        }
    }

    p.addLast("pnpDecoder", new PNPServerFrameDecoder(pnpServerHandler, timer));
    p.addLast("frameEncoder", new LengthFieldPrepender(4));
    p.addLast("pnpEncoder", new PNPEncoder());
    p.addLast(PNPServerHandler.NAME, pnpServerHandler);
    return p;
}
项目:EatDubbo    文件:NettyCodecAdapter.java   
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;
}
项目:dubbo2    文件:NettyCodecAdapter.java   
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;
}
项目:traccar-service    文件:BasePipelineFactory.java   
private void addDynamicHandlers(ChannelPipeline pipeline) {
    if (Context.getConfig().hasKey("extra.handlers")) {
        String[] handlers = Context.getConfig().getString("extra.handlers").split(",");
        for (int i = 0; i < handlers.length; i++) {
            try {
                pipeline.addLast("extraHandler." + i, (ChannelHandler) Class.forName(handlers[i]).newInstance());
            } catch (ClassNotFoundException | InstantiationException | IllegalAccessException error) {
                Log.warning(error);
            }
        }
    }
}
项目:dubbox-hystrix    文件:NettyCodecAdapter.java   
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;
}
项目:dubbocloud    文件:NettyCodecAdapter.java   
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;
}
项目:dubbos    文件:NettyCodecAdapter.java   
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;
}
项目:graylog-plugin-beats    文件:BeatsTransport.java   
@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getFinalChannelHandlers(MessageInput input) {
    final LinkedHashMap<String, Callable<? extends ChannelHandler>> finalChannelHandlers = super.getFinalChannelHandlers(input);
    final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlers = new LinkedHashMap<>();
    handlers.put("beats", BeatsFrameDecoder::new);
    handlers.putAll(finalChannelHandlers);

    return handlers;
}
项目:graylog-plugin-beats    文件:BeatsTransportTest.java   
@Test
public void getFinalChannelHandlers() throws Exception {
    final BeatsTransport transport = new BeatsTransport(
            new Configuration(null),
            new ThroughputCounter(new HashedWheelTimer()),
            new LocalMetricRegistry(),
            Executors.newSingleThreadExecutor(),
            new ConnectionCounter()
    );

    final MessageInput input = mock(MessageInput.class);
    final LinkedHashMap<String, Callable<? extends ChannelHandler>> channelHandlers = transport.getFinalChannelHandlers(input);
    assertThat(channelHandlers).containsKey("beats");
}
项目:bigstreams    文件:MetricsDI.java   
@Bean
public ChannelHandler metricChannelFactory() {

    return new MetricChannel(
            (CounterMetric) beanFactory
                    .getBean("connectionsReceivedMetric"),
            (CounterMetric) beanFactory
                    .getBean("connectionsProcessedMetric"),
            (CounterMetric) beanFactory.getBean("kilobytesWrttenMetric"),
            (CounterMetric) beanFactory.getBean("kilobytesReceivedMetric"),
            (CounterMetric) beanFactory.getBean("errorsMetric"));

}
项目:bigstreams    文件:CollectorServerImpl.java   
public CollectorServerImpl(int port, ChannelHandler channelHandler,
        Configuration conf, ChannelHandler metricsHandler,
        IpFilterHandler ipFilterHandler) {
    super();
    this.port = port;
    this.channelHandler = channelHandler;
    this.conf = conf;
    this.metricsHandler = metricsHandler;
    this.ipFilterHandler = ipFilterHandler;
}
项目:bigstreams    文件:CoordinationServerImpl.java   
public CoordinationServerImpl(int lockPort, int releaseLockPort,
        ChannelHandler lockHandler, ChannelHandler unlockHandler,
        ChannelHandler metricHandler) {
    super();
    this.lockPort = lockPort;
    this.releaseLockPort = releaseLockPort;
    this.lockHandler = lockHandler;
    this.unlockHandler = unlockHandler;
    this.metricHandler = metricHandler;
}
项目:dubbo-comments    文件:NettyCodecAdapter.java   
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;
}
项目:dubbox    文件:NettyCodecAdapter.java   
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;
}
项目:dubbo    文件:NettyCodecAdapter.java   
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;
}
项目:dubbo3    文件:NettyCodecAdapter.java   
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;
}
项目:Netty-Resteasy-Spring    文件:NettyServer.java   
public void start() {
    ResteasyDeployment dp = new ResteasyDeployment();
    Collection<Object> providers = ac.getBeansWithAnnotation(Provider.class).values();
    Collection<Object> controllers = ac.getBeansWithAnnotation(Controller.class).values();
    Assert.notEmpty(controllers);
    // extract providers
    if (providers != null) {
        dp.getProviders().addAll(providers);
    }
    // extract only controller annotated beans
    dp.getResources().addAll(controllers);
    Map<String, Object> channelOptions = new HashMap<String, Object>();
    channelOptions.put("reuseAddress", true);
    List<ChannelHandler> channelHandlerList = new ArrayList<ChannelHandler>();
    channelHandlerList.add(channelHandler);
    channelHandlerList.add(idleStateHandler);
    channelHandlerList.add(healthCheckHandler);
    netty = new NettyJaxrsServer();
    netty.setChannelOptions(channelOptions);
    netty.setDeployment(dp);
    netty.setPort(port);
    netty.setRootResourcePath("/resteasy");
    netty.setIoWorkerCount(ioWorkerCount);
    netty.setExecutorThreadCount(executorThreadCount);
    netty.setMaxRequestSize(maxRequestSize);
    netty.setSSLContext(sslContext);
    netty.setKeepAlive(true);
    netty.setChannelHandlers(channelHandlerList);
    netty.setSecurityDomain(null);
    netty.start();
}
项目:BJAF3.x    文件:CodecFactory.java   
public static ChannelHandler createEncoder() {
    String f = AppProperties.get("rpc_common_codec", "java");
    if (f.equalsIgnoreCase("java")) {
        return new ObjectEncoder();
    } else if (f.equalsIgnoreCase("jbossSerialization")) {
        return new JBossSerializationEncoder();
    } else if (f.equalsIgnoreCase("json")) {
        throw new AppRuntimeException("not support " + f + " yet!");
    } else if (f.equalsIgnoreCase("hessian")) {
        return new HessianEncoder();
    } else {
        throw new AppRuntimeException("not support " + f + " yet!");
    }
}
项目:dubbo-learning    文件:NettyCodecAdapter.java   
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;
}
项目:DubboCode    文件:NettyCodecAdapter.java   
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;
}
项目:nfs-client-java    文件:Connection.java   
/**
 * @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);
        }
    });
}
项目:jahhan    文件:NettyCodecAdapter.java   
public NettyCodecAdapter(Codec2 codec, URL url, net.jahhan.spi.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;
}
项目:Camel    文件:NettyHttpConfiguration.java   
@Override
public NettyHttpConfiguration copy() {
    try {
        // clone as NettyHttpConfiguration
        NettyHttpConfiguration answer = (NettyHttpConfiguration) clone();
        // make sure the lists is copied in its own instance
        List<ChannelHandler> encodersCopy = new ArrayList<ChannelHandler>(getEncoders());
        answer.setEncoders(encodersCopy);
        List<ChannelHandler> decodersCopy = new ArrayList<ChannelHandler>(getDecoders());
        answer.setDecoders(decodersCopy);
        return answer;
    } catch (CloneNotSupportedException e) {
        throw new RuntimeCamelException(e);
    }
}
项目:Camel    文件:NettyHttpCompressTest.java   
@Override
protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry registry = super.createRegistry();
    List<ChannelHandler> decoders = new ArrayList<ChannelHandler>();
    decoders.add(new HttpContentDecompressor());
    registry.bind("myDecoders", decoders);
    return registry;
}
项目:Camel    文件:ChannelHandlerFactories.java   
public static ChannelHandlerFactory newObjectDecoder() {
    return new ChannelHandlerFactory() {
        @Override
        public ChannelHandler newChannelHandler() {
            return new ObjectDecoder(ClassResolvers.weakCachingResolver(null));
        }
    };
}
项目:Camel    文件:ChannelHandlerFactories.java   
public static ChannelHandlerFactory newDelimiterBasedFrameDecoder(final int maxFrameLength, final ChannelBuffer[] delimiters) {
    return new ChannelHandlerFactory() {
        @Override
        public ChannelHandler newChannelHandler() {
            return new DelimiterBasedFrameDecoder(maxFrameLength, true, delimiters);
        }
    };
}
项目:Camel    文件:ChannelHandlerFactories.java   
public static ChannelHandlerFactory newLengthFieldBasedFrameDecoder(final int maxFrameLength, final int lengthFieldOffset,
                                                                    final int lengthFieldLength, final int lengthAdjustment,
                                                                    final int initialBytesToStrip) {
    return new ChannelHandlerFactory() {
        @Override
        public ChannelHandler newChannelHandler() {
            return new LengthFieldBasedFrameDecoder(maxFrameLength, lengthFieldOffset, lengthFieldLength, lengthAdjustment, initialBytesToStrip);
        }
    };
}
项目:Camel    文件:NettyConfiguration.java   
/**
 * Returns a copy of this configuration
 */
public NettyConfiguration copy() {
    try {
        NettyConfiguration answer = (NettyConfiguration) clone();
        // make sure the lists is copied in its own instance
        List<ChannelHandler> encodersCopy = new ArrayList<ChannelHandler>(encoders);
        answer.setEncoders(encodersCopy);
        List<ChannelHandler> decodersCopy = new ArrayList<ChannelHandler>(decoders);
        answer.setDecoders(decodersCopy);
        return answer;
    } catch (CloneNotSupportedException e) {
        throw new RuntimeCamelException(e);
    }
}