本文整理汇总了Java中io.netty.handler.codec.protobuf.ProtobufEncoder类的典型用法代码示例。如果您正苦于以下问题:Java ProtobufEncoder类的具体用法?Java ProtobufEncoder怎么用?Java ProtobufEncoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProtobufEncoder类属于io.netty.handler.codec.protobuf包,在下文中一共展示了ProtobufEncoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Client
import io.netty.handler.codec.protobuf.ProtobufEncoder; //导入依赖的package包/类
/**
* 本地爬虫服务,长连接
*
* @param action
*/
public Client(@Nonnull final Action action){
isLongConnection = true;
final Client self = this;
this.action = action;
channelInitializer = new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new ProtobufVarint32FrameDecoder());
ch.pipeline().addLast(new ProtobufDecoder(ProcessData.getDefaultInstance()));
ch.pipeline().addLast(new ProtobufVarint32LengthFieldPrepender());
ch.pipeline().addLast(new ProtobufEncoder());
ch.pipeline().addLast(new ReadTimeoutHandler(60));
ch.pipeline().addLast(new LoginAuthReqHandler(channel));
ch.pipeline().addLast(new LocalCrawlerHandler(action));
ch.pipeline().addLast(new HeartBeatReqHandler(self, closeLongConnection));
}
};
}
示例2: getBootstrap
import io.netty.handler.codec.protobuf.ProtobufEncoder; //导入依赖的package包/类
/**
* Init Bootstrap
*/
public static final Bootstrap getBootstrap() {
EventLoopGroup group = new NioEventLoopGroup();
Bootstrap b = new Bootstrap();
b.group(group);
b.channel(NioSocketChannel.class);
b.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("frameDecoder", new ProtobufVarint32FrameDecoder());
pipeline.addLast("decoder", new ProtobufDecoder(MessageBuf.JMTransfer.getDefaultInstance()));
pipeline.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender());
pipeline.addLast("encoder", new ProtobufEncoder());
pipeline.addLast("handler", new TcpClientHandler());
}
});
b.option(ChannelOption.SO_KEEPALIVE, true);
return b;
}
示例3: ExternalJavacProcess
import io.netty.handler.codec.protobuf.ProtobufEncoder; //导入依赖的package包/类
public ExternalJavacProcess() {
final JavacRemoteProto.Message msgDefaultInstance = JavacRemoteProto.Message.getDefaultInstance();
myEventLoopGroup = new NioEventLoopGroup(1, SharedThreadPool.getInstance());
myChannelInitializer = new ChannelInitializer() {
@Override
protected void initChannel(Channel channel) throws Exception {
channel.pipeline().addLast(new ProtobufVarint32FrameDecoder(),
new ProtobufDecoder(msgDefaultInstance),
new ProtobufVarint32LengthFieldPrepender(),
new ProtobufEncoder(),
new CompilationRequestsHandler()
);
}
};
}
示例4: startListening
import io.netty.handler.codec.protobuf.ProtobufEncoder; //导入依赖的package包/类
private int startListening() throws Exception {
final ServerBootstrap bootstrap = NettyUtil.nioServerBootstrap(new NioEventLoopGroup(1, PooledThreadExecutor.INSTANCE));
bootstrap.childHandler(new ChannelInitializer() {
@Override
protected void initChannel(Channel channel) throws Exception {
channel.pipeline().addLast(myChannelRegistrar,
new ProtobufVarint32FrameDecoder(),
new ProtobufDecoder(CmdlineRemoteProto.Message.getDefaultInstance()),
new ProtobufVarint32LengthFieldPrepender(),
new ProtobufEncoder(),
myMessageDispatcher);
}
});
Channel serverChannel = bootstrap.bind(NetUtils.getLoopbackAddress(), 0).syncUninterruptibly().channel();
myChannelRegistrar.add(serverChannel);
return ((InetSocketAddress)serverChannel.localAddress()).getPort();
}
示例5: connect
import io.netty.handler.codec.protobuf.ProtobufEncoder; //导入依赖的package包/类
public void connect() throws Exception {
workerGroup = new NioEventLoopGroup();
Bootstrap bootstrap =
new Bootstrap()
.group(workerGroup)
.channel(NioSocketChannel.class)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel socketChannel) throws Exception {
ChannelPipeline pipeline = socketChannel.pipeline();
pipeline.addLast(new LengthFieldBasedFrameDecoder(1048576, 0, 4, 0, 4));
pipeline.addLast(new ProtobufDecoder(Protocol.BaseMessage.getDefaultInstance()));
clientHandler = new ClientHandler();
pipeline.addLast(clientHandler);
pipeline.addLast(new LengthFieldPrepender(4));
pipeline.addLast(new ProtobufEncoder());
}
});
ChannelFuture channelFuture = bootstrap.connect(host, port).sync();
channel = channelFuture.channel();
}
示例6: initChannel
import io.netty.handler.codec.protobuf.ProtobufEncoder; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc(), NettyPistachioClient.HOST, NettyPistachioClient.PORT));
}
LogLevel level = LogLevel.DEBUG;
p.addLast(new LoggingHandler(level));
p.addLast(new ReadTimeoutHandler(ConfigurationManager.getConfiguration().getInt("Network.Netty.ClientReadTimeoutMillis",10000), TimeUnit.MILLISECONDS));
p.addLast(new ProtobufVarint32FrameDecoder());
p.addLast(new ProtobufDecoder(NettyPistachioProtocol.Response.getDefaultInstance()));
p.addLast(new ProtobufVarint32LengthFieldPrepender());
p.addLast(new ProtobufEncoder());
p.addLast(new NettyPistachioClientHandler());
}
示例7: start
import io.netty.handler.codec.protobuf.ProtobufEncoder; //导入依赖的package包/类
public void start() throws Exception {
logger.info("start start()");
bossGroup = new NioEventLoopGroup(1);
workerGroup = new NioEventLoopGroup();
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).
channel(NioServerSocketChannel.class).
handler(new LoggingHandler(LogLevel.INFO)).
childHandler(new ChannelInitializer<SocketChannel>() {
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new ProtobufVarint32FrameDecoder());
p.addLast(new ProtobufDecoder(WirePayload.getDefaultInstance()));
p.addLast(new ProtobufVarint32LengthFieldPrepender());
p.addLast(new ProtobufEncoder());
p.addLast(new RPCServerHandler(serviceRegistry));
}
});
logger.info("finish start()");
logger.info("bind and waiting for request");
b.bind(port).sync().channel().closeFuture().sync();
}
示例8: protoBuf
import io.netty.handler.codec.protobuf.ProtobufEncoder; //导入依赖的package包/类
/**
* Returns a new channel initializer suited to encode and decode a protocol
* buffer message.
* <p/>
* <p>Message sizes over 10 MB are not supported.</p>
* <p/>
* <p>The handler will be executed on the I/O thread. Blocking operations
* should be executed in their own thread.</p>
*
* @param defaultInstance an instance of the message to handle
* @param handler the handler implementing the application logic
* @param <M> the type of the support protocol buffer message
*/
public static final <M extends Message> ChannelInitializer<Channel> protoBuf(
final M defaultInstance, final SimpleChannelInboundHandler<M> handler) {
return new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel channel) throws Exception {
channel.pipeline().addLast("frameDecoder",
new LengthFieldBasedFrameDecoder(10 * 1024 * 1024, 0, 4, 0, 4));
channel.pipeline().addLast("protobufDecoder",
new ProtobufDecoder(defaultInstance));
channel.pipeline().addLast("frameEncoder", new LengthFieldPrepender(4));
channel.pipeline().addLast("protobufEncoder", new ProtobufEncoder());
channel.pipeline().addLast("applicationHandler", handler);
}
};
}
示例9: initChannel
import io.netty.handler.codec.protobuf.ProtobufEncoder; //导入依赖的package包/类
@Override
protected void initChannel(T ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
p.addLast("protobufDecoder", new ProtobufDecoder(NettyRpcProto.RpcContainer.getDefaultInstance()));
p.addLast("frameEncoder", new LengthFieldPrepender(4));
p.addLast("protobufEncoder", new ProtobufEncoder());
ConcurrentHashMap<Integer, RpcCall> callMap = new ConcurrentHashMap<Integer, RpcCall>();
p.addLast(eventExecutor, "inboundHandler", new InboundHandler(callMap));
p.addLast("outboundHandler", new OutboundHandler(callMap));
}
示例10: initChannel
import io.netty.handler.codec.protobuf.ProtobufEncoder; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
p.addLast("protobufDecoder", new ProtobufDecoder(NettyRpcProto.RpcContainer.getDefaultInstance()));
p.addLast("frameEncoder", new LengthFieldPrepender(4));
p.addLast("protobufEncoder", new ProtobufEncoder());
p.addLast(eventExecutor, "serverHandler", handler);
}
示例11: start
import io.netty.handler.codec.protobuf.ProtobufEncoder; //导入依赖的package包/类
public static void start(MemberEventLoop loop) throws InterruptedException {
String host = "127.0.0.1";
int port = 9005;
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
Bootstrap b = new Bootstrap();
b.group(workerGroup);
b.channel(NioSocketChannel.class);
b.option(ChannelOption.SO_KEEPALIVE, true);
b.handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new ProtobufVarint32FrameDecoder());
ch.pipeline().addLast(new ProtobufDecoder(SocketMessage.getDefaultInstance()));
ch.pipeline().addLast(new ProtobufVarint32LengthFieldPrepender());
ch.pipeline().addLast(new ProtobufEncoder());
ch.pipeline().addLast(new IdleStateHandler(0, 5, 10, TimeUnit.SECONDS));
ch.pipeline().addLast(new BusinessRouterHandler(loop));
}
});
// Start the client.
ChannelFuture f = b.connect(host, port).sync();
// Wait until the connection is closed.
f.channel().closeFuture().sync();
} finally {
workerGroup.shutdownGracefully();
}
}
示例12: bind
import io.netty.handler.codec.protobuf.ProtobufEncoder; //导入依赖的package包/类
public void bind() {
bossGroup = new NioEventLoopGroup();
workerGroup = new NioEventLoopGroup();
ServerBootstrap b = new ServerBootstrap();
try {
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 100)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new ProtobufVarint32FrameDecoder());
ch.pipeline().addLast(new ProtobufDecoder(ProcessData.getDefaultInstance()));
ch.pipeline().addLast(new ProtobufVarint32LengthFieldPrepender());
ch.pipeline().addLast(new ProtobufEncoder());
ch.pipeline().addLast(new ReadTimeoutHandler(60));
ch.pipeline().addLast(new LoginAuthRespHandler(channels));
ch.pipeline().addLast(new ShellRespHandler(client, dfsManager));
ch.pipeline().addLast(new WorkerProxyHandler(worker));
ch.pipeline().addLast(new HeartBeatRespHandler());
}
});
ChannelFuture f = b.bind(port).sync();
f.channel().closeFuture().sync();
} catch (InterruptedException e) {
logger.error(e.getMessage());
}
}
示例13: initChannel
import io.netty.handler.codec.protobuf.ProtobufEncoder; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new ProtobufVarint32FrameDecoder());
p.addLast(new ProtobufDecoder(prototype,extensionRegistry));
p.addLast(new ProtobufVarint32LengthFieldPrepender());
p.addLast(new ProtobufEncoder());
p.addLast(new DefaultIdleListenerHandler<T>(listener));
}
示例14: connect
import io.netty.handler.codec.protobuf.ProtobufEncoder; //导入依赖的package包/类
public void connect(int port, String host) throws InterruptedException {
EventLoopGroup group = new NioEventLoopGroup();
try{
Bootstrap b = new Bootstrap();
b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new ProtobufVarint32FrameDecoder());
/**
* ProtobufDecoder仅仅负责解码, 它不支持读半包, 因此在ProtobufDecoder之前使用ProtobufVarint32FrameDecoder
* 来处理半包
*/
ch.pipeline().addLast(new ProtobufDecoder(SubscribeRespProto.SubscribeResp.getDefaultInstance()));
ch.pipeline().addLast(new ProtobufVarint32LengthFieldPrepender());
ch.pipeline().addLast(new ProtobufEncoder());
ch.pipeline().addLast(new SubReqClientHandler());
}
});
//发送异步链接操作
ChannelFuture f = b.connect(host, port).sync();
//等待客户端链路关闭
f.channel().closeFuture().sync();
}finally{
group.shutdownGracefully();
}
}
示例15: initChannel
import io.netty.handler.codec.protobuf.ProtobufEncoder; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new ProtobufVarint32FrameDecoder());
/**
* ProtobufDecoder仅仅负责解码, 它不支持读半包, 因此在ProtobufDecoder之前使用ProtobufVarint32FrameDecoder
* 来处理半包
*/
ch.pipeline().addLast(new ProtobufDecoder(SubscribeReqProto.SubscribeReq.getDefaultInstance()));
ch.pipeline().addLast(new ProtobufVarint32LengthFieldPrepender());
ch.pipeline().addLast(new ProtobufEncoder());
ch.pipeline().addLast(new SubReqServerHandler());
}