本文整理汇总了Java中org.jboss.netty.channel.Channels类的典型用法代码示例。如果您正苦于以下问题:Java Channels类的具体用法?Java Channels怎么用?Java Channels使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Channels类属于org.jboss.netty.channel包,在下文中一共展示了Channels类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPipeline
import org.jboss.netty.channel.Channels; //导入依赖的package包/类
@Override
public ChannelPipeline getPipeline() throws Exception {
BootstrapChannelHandler handler =
new BootstrapChannelHandler(bootstrap);
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("frameDecoder",
new ThriftFrameDecoder(maxFrameSize));
pipeline.addLast("frameEncoder",
new ThriftFrameEncoder());
pipeline.addLast("timeout",
new BootstrapTimeoutHandler(timer, 10));
pipeline.addLast("handler", handler);
return pipeline;
}
示例2: send
import org.jboss.netty.channel.Channels; //导入依赖的package包/类
/**
* Sends this response to all the passed channels as a {@link TextWebSocketFrame}
* @param listener A channel future listener to attach to each channel future. Ignored if null.
* @param channels The channels to send this response to
* @return An array of the futures for the write of this response to each channel written to
*/
public ChannelFuture[] send(ChannelFutureListener listener, Channel...channels) {
if(channels!=null && channels.length>0) {
Set<ChannelFuture> futures = new HashSet<ChannelFuture>(channels.length);
if(opCode==null) {
opCode = "ok";
}
TextWebSocketFrame frame = new TextWebSocketFrame(this.toChannelBuffer());
for(Channel channel: channels) {
if(channel!=null && channel.isWritable()) {
ChannelFuture cf = Channels.future(channel);
if(listener!=null) cf.addListener(listener);
channel.getPipeline().sendDownstream(new DownstreamMessageEvent(channel, cf, frame, channel.getRemoteAddress()));
futures.add(cf);
}
}
return futures.toArray(new ChannelFuture[futures.size()]);
}
return EMPTY_CHANNEL_FUTURE_ARR;
}
示例3: doOpen
import org.jboss.netty.channel.Channels; //导入依赖的package包/类
@Override
protected void doOpen() throws Throwable {
NettyHelper.setNettyLoggerFactory();
bootstrap = new ClientBootstrap(channelFactory);
// config
// @see org.jboss.netty.channel.socket.SocketChannelConfig
bootstrap.setOption("keepAlive", true);
bootstrap.setOption("tcpNoDelay", true);
bootstrap.setOption("connectTimeoutMillis", getTimeout());
final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
public ChannelPipeline getPipeline() {
NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyClient.this);
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("decoder", adapter.getDecoder());
pipeline.addLast("encoder", adapter.getEncoder());
pipeline.addLast("handler", nettyHandler);
return pipeline;
}
});
}
示例4: NettyServerCnxnFactory
import org.jboss.netty.channel.Channels; //导入依赖的package包/类
NettyServerCnxnFactory() {
bootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
// parent channel
bootstrap.setOption("reuseAddress", true);
// child channels
bootstrap.setOption("child.tcpNoDelay", true);
/* set socket linger to off, so that socket close does not block */
bootstrap.setOption("child.soLinger", -1);
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline p = Channels.pipeline();
if (secure) {
initSSL(p);
}
p.addLast("servercnxnfactory", channelHandler);
return p;
}
});
}
示例5: getPipeline
import org.jboss.netty.channel.Channels; //导入依赖的package包/类
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline channelPipeline = Channels.pipeline();
SizeHeaderFrameDecoder sizeHeader = new SizeHeaderFrameDecoder();
if (nettyTransport.maxCumulationBufferCapacity != null) {
if (nettyTransport.maxCumulationBufferCapacity.bytes() > Integer.MAX_VALUE) {
sizeHeader.setMaxCumulationBufferCapacity(Integer.MAX_VALUE);
} else {
sizeHeader.setMaxCumulationBufferCapacity((int) nettyTransport.maxCumulationBufferCapacity.bytes());
}
}
if (nettyTransport.maxCompositeBufferComponents != -1) {
sizeHeader.setMaxCumulationBufferComponents(nettyTransport.maxCompositeBufferComponents);
}
channelPipeline.addLast("size", sizeHeader);
// using a dot as a prefix means, this cannot come from any settings parsed
channelPipeline.addLast("dispatcher", new MessageChannelHandler(nettyTransport, nettyTransport.logger, ".client"));
return channelPipeline;
}
示例6: getPipeline
import org.jboss.netty.channel.Channels; //导入依赖的package包/类
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
if (sslFactory != null) {
pipeline.addLast("ssl", new SslHandler(sslFactory.createSSLEngine()));
}
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("aggregator", new HttpChunkAggregator(1 << 16));
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("chunking", new ChunkedWriteHandler());
pipeline.addLast("shuffle", SHUFFLE);
return pipeline;
// TODO factor security manager into pipeline
// TODO factor out encode/decode to permit binary shuffle
// TODO factor out decode of index to permit alt. models
}
示例7: startHttpServer
import org.jboss.netty.channel.Channels; //导入依赖的package包/类
private ServerBootstrap startHttpServer(int port,
final Token<DelegationTokenIdentifier> token, final URI url) {
ServerBootstrap bootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(Executors.newCachedThreadPool(),
Executors.newCachedThreadPool()));
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
return Channels.pipeline(new HttpRequestDecoder(),
new HttpChunkAggregator(65536), new HttpResponseEncoder(),
new CredentialsLogicHandler(token, url.toString()));
}
});
bootstrap.bind(new InetSocketAddress("localhost", port));
return bootstrap;
}
示例8: run
import org.jboss.netty.channel.Channels; //导入依赖的package包/类
public void run() {
// Configure the client.
DatagramChannelFactory f = new NioDatagramChannelFactory(
Executors.newCachedThreadPool(), workerCount);
server = new ConnectionlessBootstrap(f);
server.setPipeline(Channels.pipeline(RpcUtil.STAGE_RPC_MESSAGE_PARSER,
rpcProgram, RpcUtil.STAGE_RPC_UDP_RESPONSE));
server.setOption("broadcast", "false");
server.setOption("sendBufferSize", SEND_BUFFER_SIZE);
server.setOption("receiveBufferSize", RECEIVE_BUFFER_SIZE);
// Listen to the UDP port
ch = server.bind(new InetSocketAddress(port));
InetSocketAddress socketAddr = (InetSocketAddress) ch.getLocalAddress();
boundPort = socketAddr.getPort();
LOG.info("Started listening to UDP requests at port " + boundPort + " for "
+ rpcProgram + " with workerCount " + workerCount);
}
示例9: messageReceived
import org.jboss.netty.channel.Channels; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
throws Exception {
ChannelBuffer buf = (ChannelBuffer) e.getMessage();
ByteBuffer b = buf.toByteBuffer().asReadOnlyBuffer();
XDR in = new XDR(b, XDR.State.READING);
RpcInfo info = null;
try {
RpcCall callHeader = RpcCall.read(in);
ChannelBuffer dataBuffer = ChannelBuffers.wrappedBuffer(in.buffer()
.slice());
info = new RpcInfo(callHeader, dataBuffer, ctx, e.getChannel(),
e.getRemoteAddress());
} catch (Exception exc) {
LOG.info("Malformed RPC request from " + e.getRemoteAddress());
}
if (info != null) {
Channels.fireMessageReceived(ctx, info);
}
}
示例10: getPipeline
import org.jboss.netty.channel.Channels; //导入依赖的package包/类
@Override
public ChannelPipeline getPipeline() throws Exception {
BgpChannelHandler handler = new BgpChannelHandler(bgpController);
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("bgpmessagedecoder", new BgpMessageDecoder());
pipeline.addLast("bgpmessageencoder", new BgpMessageEncoder());
pipeline.addLast("holdTime", readTimeoutHandler);
if (isBgpServ) {
pipeline.addLast("PassiveHandler", handler);
} else {
pipeline.addLast("ActiveHandler", handler);
}
return pipeline;
}
示例11: connect
import org.jboss.netty.channel.Channels; //导入依赖的package包/类
/**
* Starts the BGP peer.
*
* @param connectToSocket the socket to connect to
*/
private void connect(InetSocketAddress connectToSocket)
throws InterruptedException {
ChannelFactory channelFactory =
new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool());
ChannelPipelineFactory pipelineFactory = () -> {
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("BgpPeerFrameDecoderTest",
peerFrameDecoder);
pipeline.addLast("BgpPeerChannelHandlerTest",
peerChannelHandler);
return pipeline;
};
peerBootstrap = new ClientBootstrap(channelFactory);
peerBootstrap.setOption("child.keepAlive", true);
peerBootstrap.setOption("child.tcpNoDelay", true);
peerBootstrap.setPipelineFactory(pipelineFactory);
peerBootstrap.connect(connectToSocket);
}
示例12: connectFrom
import org.jboss.netty.channel.Channels; //导入依赖的package包/类
private Channel connectFrom(InetSocketAddress connectToSocket, SocketAddress localAddress)
throws InterruptedException {
ChannelFactory channelFactory =
new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
Executors.newCachedThreadPool());
ChannelPipelineFactory pipelineFactory = () -> {
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("BgpPeerFrameDecoderTest",
peerFrameDecoder);
pipeline.addLast("BgpPeerChannelHandlerTest",
peerChannelHandler);
return pipeline;
};
peerBootstrap = new ClientBootstrap(channelFactory);
peerBootstrap.setOption("child.keepAlive", true);
peerBootstrap.setOption("child.tcpNoDelay", true);
peerBootstrap.setPipelineFactory(pipelineFactory);
Channel channel = peerBootstrap.connect(connectToSocket, localAddress).getChannel();
return channel;
}
示例13: messageReceived
import org.jboss.netty.channel.Channels; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx,
MessageEvent e) throws Exception {
Object message = e.getMessage();
if (message instanceof SyncMessage) {
handleSyncMessage((SyncMessage)message, ctx.getChannel());
} else if (message instanceof List) {
for (Object i : (List<?>)message) {
if (i instanceof SyncMessage) {
try {
handleSyncMessage((SyncMessage)i,
ctx.getChannel());
} catch (Exception ex) {
Channels.fireExceptionCaught(ctx, ex);
}
}
}
} else {
handleUnknownMessage(ctx, message);
}
}
示例14: getPipeline
import org.jboss.netty.channel.Channels; //导入依赖的package包/类
@Override
public ChannelPipeline getPipeline() throws Exception {
RPCChannelHandler channelHandler =
new RPCChannelHandler(syncManager, rpcService);
IdleStateHandler idleHandler =
new IdleStateHandler(timer, 5, 10, 0);
ReadTimeoutHandler readTimeoutHandler =
new ReadTimeoutHandler(timer, 30);
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("idle", idleHandler);
pipeline.addLast("timeout", readTimeoutHandler);
pipeline.addLast("handshaketimeout",
new HandshakeTimeoutHandler(channelHandler, timer, 10));
pipeline.addLast("frameDecoder",
new ThriftFrameDecoder(maxFrameSize));
pipeline.addLast("frameEncoder",
new ThriftFrameEncoder());
pipeline.addLast("handler", channelHandler);
return pipeline;
}
示例15: getPipeline
import org.jboss.netty.channel.Channels; //导入依赖的package包/类
@Override
public ChannelPipeline getPipeline() throws Exception {
RemoteSyncChannelHandler channelHandler =
new RemoteSyncChannelHandler(syncManager);
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("frameDecoder",
new ThriftFrameDecoder(maxFrameSize));
pipeline.addLast("frameEncoder",
new ThriftFrameEncoder());
pipeline.addLast("timeout",
new RSHandshakeTimeoutHandler(channelHandler,
timer, 3));
pipeline.addLast("handler", channelHandler);
return pipeline;
}