org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder Java Examples
The following examples show how to use
org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TSOChannelHandler.java From phoenix-omid with Apache License 2.0 | 5 votes |
public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); // Max packet length is 10MB. Transactions with so many cells // that the packet is rejected will receive a ServiceUnavailableException. // 10MB is enough for 2 million cells in a transaction though. pipeline.addLast("lengthbaseddecoder", new LengthFieldBasedFrameDecoder(10 * 1024 * 1024, 0, 4, 0, 4)); pipeline.addLast("lengthprepender", new LengthFieldPrepender(4)); pipeline.addLast("protobufdecoder", new ProtobufDecoder(TSOProto.Request.getDefaultInstance())); pipeline.addLast("protobufencoder", new ProtobufEncoder()); pipeline.addLast("handler", handler); return pipeline; }
Example #2
Source File: TSOClientRaw.java From phoenix-omid with Apache License 2.0 | 5 votes |
public TSOClientRaw(String host, int port) throws InterruptedException, ExecutionException { // Start client with Nb of active threads = 3 as maximum. ChannelFactory factory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool( new ThreadFactoryBuilder().setNameFormat("tsoclient-boss-%d").build()), Executors.newCachedThreadPool( new ThreadFactoryBuilder().setNameFormat("tsoclient-worker-%d").build()), 3); // Create the bootstrap ClientBootstrap bootstrap = new ClientBootstrap(factory); InetSocketAddress addr = new InetSocketAddress(host, port); ChannelPipeline pipeline = bootstrap.getPipeline(); pipeline.addLast("lengthbaseddecoder", new LengthFieldBasedFrameDecoder(8 * 1024, 0, 4, 0, 4)); pipeline.addLast("lengthprepender", new LengthFieldPrepender(4)); pipeline.addLast("protobufdecoder", new ProtobufDecoder(TSOProto.Response.getDefaultInstance())); pipeline.addLast("protobufencoder", new ProtobufEncoder()); Handler handler = new Handler(); pipeline.addLast("handler", handler); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("keepAlive", true); bootstrap.setOption("reuseAddress", true); bootstrap.setOption("connectTimeoutMillis", 100); ChannelFuture channelFuture = bootstrap.connect(addr).await(); channel = channelFuture.getChannel(); }
Example #3
Source File: ProtoPipelineFactory.java From incubator-tajo with Apache License 2.0 | 5 votes |
public ChannelPipeline getPipeline() throws Exception { ChannelPipeline p = Channels.pipeline(); p.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1048576*2, 0, 4, 0, 4)); p.addLast("protobufDecoder", new ProtobufDecoder(defaultInstance)); p.addLast("frameEncoder", new LengthFieldPrepender(4)); p.addLast("protobufEncoder", new ProtobufEncoder()); p.addLast("handler", handler); return p; }
Example #4
Source File: CarbonPickleServer.java From kairos-carbon with Apache License 2.0 | 5 votes |
@Override public ChannelPipeline getPipeline() throws Exception { ChannelPipeline pipeline = Channels.pipeline(); LengthFieldBasedFrameDecoder frameDecoder = new LengthFieldBasedFrameDecoder( m_maxSize, 0, 4, 0, 4); pipeline.addLast("framer", frameDecoder); pipeline.addLast("decoder", new PickleDecoder()); pipeline.addLast("handler", this); return (pipeline); }
Example #5
Source File: TSOClient.java From phoenix-omid with Apache License 2.0 | 4 votes |
private TSOClient(OmidClientConfiguration omidConf) throws IOException { // Start client with Nb of active threads = 3 as maximum. int tsoExecutorThreads = omidConf.getExecutorThreads(); factory = new NioClientSocketChannelFactory( Executors.newCachedThreadPool( new ThreadFactoryBuilder().setNameFormat("tsoclient-boss-%d").build()), Executors.newCachedThreadPool( new ThreadFactoryBuilder().setNameFormat("tsoclient-worker-%d").build()), tsoExecutorThreads); // Create the bootstrap bootstrap = new ClientBootstrap(factory); requestTimeoutInMs = omidConf.getRequestTimeoutInMs(); requestMaxRetries = omidConf.getRequestMaxRetries(); tsoReconnectionDelayInSecs = omidConf.getReconnectionDelayInSecs(); LOG.info("Connecting to TSO..."); HostAndPort hp; switch (omidConf.getConnectionType()) { case HA: zkClient = ZKUtils.initZKClient(omidConf.getConnectionString(), omidConf.getZkNamespace(), omidConf.getZkConnectionTimeoutInSecs()); zkCurrentTsoPath = omidConf.getZkCurrentTsoPath(); configureCurrentTSOServerZNodeCache(zkCurrentTsoPath); String tsoInfo = getCurrentTSOInfoFoundInZK(zkCurrentTsoPath); // TSO info includes the new TSO host:port address and epoch String[] currentTSOAndEpochArray = tsoInfo.split("#"); hp = HostAndPort.fromString(currentTSOAndEpochArray[0]); setTSOAddress(hp.getHostText(), hp.getPort()); epoch = Long.parseLong(currentTSOAndEpochArray[1]); LOG.info("\t* Current TSO host:port found in ZK: {} Epoch {}", hp, getEpoch()); break; case DIRECT: default: hp = HostAndPort.fromString(omidConf.getConnectionString()); setTSOAddress(hp.getHostText(), hp.getPort()); LOG.info("\t* TSO host:port {} will be connected directly", hp); break; } fsmExecutor = Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder().setNameFormat("tsofsm-%d").build()); fsm = new StateMachine.FsmImpl(fsmExecutor); fsm.setInitState(new DisconnectedState(fsm)); ChannelPipeline pipeline = bootstrap.getPipeline(); pipeline.addLast("lengthbaseddecoder", new LengthFieldBasedFrameDecoder(8 * 1024, 0, 4, 0, 4)); pipeline.addLast("lengthprepender", new LengthFieldPrepender(4)); pipeline.addLast("protobufdecoder", new ProtobufDecoder(TSOProto.Response.getDefaultInstance())); pipeline.addLast("protobufencoder", new ProtobufEncoder()); pipeline.addLast("handler", new Handler(fsm)); bootstrap.setOption("tcpNoDelay", true); bootstrap.setOption("keepAlive", true); bootstrap.setOption("reuseAddress", true); bootstrap.setOption("connectTimeoutMillis", 100); lowLatency = false; conflictDetectionLevel = omidConf.getConflictAnalysisLevel(); }