本文整理汇总了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);
}
}
示例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();
}
示例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());
}
示例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);
}