当前位置: 首页>>代码示例>>Java>>正文


Java ChannelHandler类代码示例

本文整理汇总了Java中org.jboss.netty.channel.ChannelHandler的典型用法代码示例。如果您正苦于以下问题:Java ChannelHandler类的具体用法?Java ChannelHandler怎么用?Java ChannelHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ChannelHandler类属于org.jboss.netty.channel包,在下文中一共展示了ChannelHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createDecoder

import org.jboss.netty.channel.ChannelHandler; //导入依赖的package包/类
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!");
	}
}
 
开发者ID:jbeetle,项目名称:BJAF3.x,代码行数:18,代码来源:CodecFactory.java

示例2: createRegistry

import org.jboss.netty.channel.ChannelHandler; //导入依赖的package包/类
@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;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:NettyHttpGetWithInvalidMessageTest.java

示例3: MasterServer

import org.jboss.netty.channel.ChannelHandler; //导入依赖的package包/类
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();
	}
}
 
开发者ID:ctripcorp,项目名称:dataworks-zeus,代码行数:25,代码来源:MasterServer.java

示例4: prepareBootstrap

import org.jboss.netty.channel.ChannelHandler; //导入依赖的package包/类
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;
}
 
开发者ID:kuiwang,项目名称:my-dev,代码行数:25,代码来源:NettyClient.java

示例5: getPipeline

import org.jboss.netty.channel.ChannelHandler; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:GlobalNOC,项目名称:FlowSpaceFirewall,代码行数:23,代码来源:ControllerConnector.java

示例6: getIsdnClientStateMachineHandler

import org.jboss.netty.channel.ChannelHandler; //导入依赖的package包/类
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));

    }
 
开发者ID:rmarins,项目名称:netty-isdn-transport,代码行数:20,代码来源:IsdnHandlerFactory.java

示例7: getAcceptedChannelStateMachineHandler

import org.jboss.netty.channel.ChannelHandler; //导入依赖的package包/类
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));

    }
 
开发者ID:rmarins,项目名称:netty-isdn-transport,代码行数:20,代码来源:IsdnHandlerFactory.java

示例8: replace

import org.jboss.netty.channel.ChannelHandler; //导入依赖的package包/类
/**
 * 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);
	}
}
 
开发者ID:urunimi,项目名称:android-netty,代码行数:23,代码来源:FrameDecoder.java

示例9: setPipelineAsMap

import org.jboss.netty.channel.ChannelHandler; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:urunimi,项目名称:android-netty,代码行数:37,代码来源:Bootstrap.java

示例10: getPipeline

import org.jboss.netty.channel.ChannelHandler; //导入依赖的package包/类
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;
}
 
开发者ID:mnip91,项目名称:proactive-component-monitoring,代码行数:26,代码来源:PNPClientPipelineFactory.java

示例11: getPipeline

import org.jboss.netty.channel.ChannelHandler; //导入依赖的package包/类
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;
}
 
开发者ID:mnip91,项目名称:proactive-component-monitoring,代码行数:17,代码来源:PNPServerPipelineFactory.java

示例12: NettyCodecAdapter

import org.jboss.netty.channel.ChannelHandler; //导入依赖的package包/类
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;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:8,代码来源:NettyCodecAdapter.java

示例13: addDynamicHandlers

import org.jboss.netty.channel.ChannelHandler; //导入依赖的package包/类
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);
            }
        }
    }
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:13,代码来源:BasePipelineFactory.java

示例14: getFinalChannelHandlers

import org.jboss.netty.channel.ChannelHandler; //导入依赖的package包/类
@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;
}
 
开发者ID:Graylog2,项目名称:graylog-plugin-beats,代码行数:10,代码来源:BeatsTransport.java

示例15: getFinalChannelHandlers

import org.jboss.netty.channel.ChannelHandler; //导入依赖的package包/类
@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");
}
 
开发者ID:Graylog2,项目名称:graylog-plugin-beats,代码行数:15,代码来源:BeatsTransportTest.java


注:本文中的org.jboss.netty.channel.ChannelHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。