當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpleChannelHandler類代碼示例

本文整理匯總了Java中org.jboss.netty.channel.SimpleChannelHandler的典型用法代碼示例。如果您正苦於以下問題:Java SimpleChannelHandler類的具體用法?Java SimpleChannelHandler怎麽用?Java SimpleChannelHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SimpleChannelHandler類屬於org.jboss.netty.channel包,在下文中一共展示了SimpleChannelHandler類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testNewChannel_forwardsWrappedFactoryFailure

import org.jboss.netty.channel.SimpleChannelHandler; //導入依賴的package包/類
@Test
public void testNewChannel_forwardsWrappedFactoryFailure() {
	final ChannelException innerException = new ChannelException();
	mockContext.checking(new Expectations() {
		{
			one(realChannelFactory).newChannel(
					with(any(ChannelPipeline.class)));
			will(throwException(innerException));
		}
	});

	try {
		factory.newChannel(Channels.pipeline(new SimpleChannelHandler()));
		fail("Expected ChannelException");
	} catch (ChannelException e) {
		assertSame(innerException, e);
	}
}
 
開發者ID:reines,項目名稱:httptunnel,代碼行數:19,代碼來源:HttpTunnelServerChannelFactoryTest.java

示例2: initialize

import org.jboss.netty.channel.SimpleChannelHandler; //導入依賴的package包/類
@Override
public void initialize(Map props) {
	super.initialize(props);
	
	// Pull the destination host and port.
	String host = props.get(NETTY_HOST_KEY).toString();
	Object p_string = props.get(NETTY_PORT_KEY);
	int port = DEFAULT_PORT;
	if (p_string != null) {
		port = Integer.parseInt(p_string.toString());
	}
		
	// Connect and pull the channel.
	ChannelFactory factory =
			new NioClientSocketChannelFactory(
					Executors.newCachedThreadPool(),
					Executors.newCachedThreadPool());

	ClientBootstrap bootstrap = new ClientBootstrap(factory);

	bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
		public ChannelPipeline getPipeline() {
			return Channels.pipeline(
					new StringEncoder(CharsetUtil.UTF_8), 
					new SimpleChannelHandler());
		}
	});

	bootstrap.setOption("keepAlive", true);

	ChannelFuture f = bootstrap.connect(new InetSocketAddress(host, port));
	
	f.awaitUninterruptibly();
	if (!f.isSuccess()) {
		throw new RuntimeException("Initialization failed.", f.getCause());
	}
	
	channel = f.getChannel();
}
 
開發者ID:JamesLampton,項目名稱:piggybank-squeal,代碼行數:40,代碼來源:NettyMetricsTransport.java

示例3: setUp

import org.jboss.netty.channel.SimpleChannelHandler; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
	realChannelFactory = mockContext.mock(ServerSocketChannelFactory.class);
	factory = new HttpTunnelServerChannelFactory(realChannelFactory);
	ChannelPipeline pipeline = Channels.pipeline(new SimpleChannelHandler());
	realChannel = new FakeServerSocketChannel(factory, pipeline,
			new FakeChannelSink());
}
 
開發者ID:reines,項目名稱:httptunnel,代碼行數:9,代碼來源:HttpTunnelServerChannelFactoryTest.java

示例4: HttpTunnelClientChannel

import org.jboss.netty.channel.SimpleChannelHandler; //導入依賴的package包/類
/**
 * @see HttpTunnelClientChannelFactory#newChannel(ChannelPipeline)
 */
protected HttpTunnelClientChannel(ChannelFactory factory, ChannelPipeline pipeline, HttpTunnelClientChannelSink sink, ClientSocketChannelFactory outboundFactory, ChannelGroup realConnections) {
	super(null, factory, pipeline, sink);

	this.outboundFactory = outboundFactory;

	final WorkerCallbacks callbackProxy = new WorkerCallbacks();

	incomingBuffer = new IncomingBuffer<ChannelBuffer>(this);

	Metrics.newGauge(HttpTunnelClientChannel.class, "incomingBuffer", new Gauge<Integer>() {
	    @Override
	    public Integer value() {
	        return incomingBuffer.size();
	    }
	});

	sendChannel = outboundFactory.newChannel(Channels.pipeline(new SimpleChannelHandler()));
	pollChannel = outboundFactory.newChannel(Channels.pipeline(new SimpleChannelHandler()));

	config = new HttpTunnelClientChannelConfig(sendChannel.getConfig(), pollChannel.getConfig());
	saturationManager = new SaturationManager(config.getWriteBufferLowWaterMark(), config.getWriteBufferHighWaterMark());

	sendHttpHandler = new HttpTunnelClientChannelProxyHandler();
	sendHandler = new HttpTunnelClientChannelSendHandler(callbackProxy);

	pollHttpHandler = new HttpTunnelClientChannelProxyHandler();
	pollHandler = new HttpTunnelClientChannelPollHandler(callbackProxy);

	opened = new AtomicBoolean(true);
	bindState = new AtomicReference<BindState>(BindState.UNBOUND);
	connectState = new AtomicReference<ConnectState>(ConnectState.DISCONNECTED);
	connectFuture = new AtomicReference<ChannelFuture>(null);

	tunnelId = null;
	remoteAddress = null;

	this.initSendPipeline(sendChannel.getPipeline());
	this.initPollPipeline(pollChannel.getPipeline());

	realConnections.add(sendChannel);
	realConnections.add(pollChannel);

	Channels.fireChannelOpen(this);
}
 
開發者ID:reines,項目名稱:httptunnel,代碼行數:48,代碼來源:HttpTunnelClientChannel.java


注:本文中的org.jboss.netty.channel.SimpleChannelHandler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。