List of usage examples for io.netty.channel ChannelOption ALLOCATOR
ChannelOption ALLOCATOR
To view the source code for io.netty.channel ChannelOption ALLOCATOR.
Click Source Link
From source file:org.apache.tajo.rpc.NettyServerBase.java
License:Apache License
public void init(ChannelInitializer<Channel> initializer, int workerNum) { for (RpcEventListener listener : listeners) { listener.onBeforeInit(this); }/* www . ja v a 2 s. com*/ bootstrap = RpcChannelFactory.createServerChannelFactory(serviceName, workerNum); this.initializer = initializer; bootstrap.channel(NioServerSocketChannel.class).childHandler(initializer) .option(ChannelOption.SO_REUSEADDR, true).option(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000) .childOption(ChannelOption.SO_RCVBUF, 1048576 * 10); for (RpcEventListener listener : listeners) { listener.onAfterInit(this); } }
From source file:org.apache.tajo.worker.Fetcher.java
License:Apache License
public Fetcher(TajoConf conf, URI uri, FileChunk chunk) { this.uri = uri; this.fileChunk = chunk; this.useLocalFile = !chunk.fromRemote(); this.state = TajoProtos.FetcherState.FETCH_INIT; this.conf = conf; String scheme = uri.getScheme() == null ? "http" : uri.getScheme(); this.host = uri.getHost() == null ? "localhost" : uri.getHost(); this.port = uri.getPort(); if (port == -1) { if (scheme.equalsIgnoreCase("http")) { this.port = 80; } else if (scheme.equalsIgnoreCase("https")) { this.port = 443; }//from w w w. j a va 2s.c o m } if (!useLocalFile) { bootstrap = new Bootstrap() .group(RpcChannelFactory.getSharedClientEventloopGroup( RpcChannelFactory.ClientChannelId.FETCHER, conf.getIntVar(TajoConf.ConfVars.SHUFFLE_RPC_CLIENT_WORKER_THREAD_NUM))) .channel(NioSocketChannel.class).option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 5000) // set 5 sec .option(ChannelOption.SO_RCVBUF, 1048576) // set 1M .option(ChannelOption.TCP_NODELAY, true); ChannelInitializer<Channel> initializer = new HttpClientChannelInitializer(fileChunk.getFile()); bootstrap.handler(initializer); } }
From source file:org.apache.tajo.worker.LocalFetcher.java
License:Apache License
@VisibleForTesting public LocalFetcher(TajoConf conf, URI uri, String tableName) throws IOException { super(conf, uri); this.maxUrlLength = conf.getIntVar(ConfVars.PULLSERVER_FETCH_URL_MAX_LENGTH); this.tableName = tableName; this.localFileSystem = new LocalFileSystem(); this.localDirAllocator = new LocalDirAllocator(ConfVars.WORKER_TEMPORAL_DIR.varname); this.pullServerService = null; String scheme = uri.getScheme() == null ? "http" : uri.getScheme(); this.host = uri.getHost() == null ? "localhost" : uri.getHost(); this.port = uri.getPort(); if (port == -1) { if (scheme.equalsIgnoreCase("http")) { this.port = 80; } else if (scheme.equalsIgnoreCase("https")) { this.port = 443; }/*from ww w .j a v a2 s. c om*/ } bootstrap = new Bootstrap() .group(NettyUtils.getSharedEventLoopGroup(NettyUtils.GROUP.FETCHER, conf.getIntVar(ConfVars.SHUFFLE_RPC_CLIENT_WORKER_THREAD_NUM))) .channel(NioSocketChannel.class).option(ChannelOption.ALLOCATOR, NettyUtils.ALLOCATOR) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, conf.getIntVar(ConfVars.SHUFFLE_FETCHER_CONNECT_TIMEOUT) * 1000) .option(ChannelOption.SO_RCVBUF, 1048576) // set 1M .option(ChannelOption.TCP_NODELAY, true); }
From source file:org.apache.tajo.worker.LocalFetcher.java
License:Apache License
public LocalFetcher(TajoConf conf, URI uri, ExecutionBlockContext executionBlockContext, String tableName) { super(conf, uri); this.localFileSystem = executionBlockContext.getLocalFS(); this.localDirAllocator = executionBlockContext.getLocalDirAllocator(); this.maxUrlLength = conf.getIntVar(ConfVars.PULLSERVER_FETCH_URL_MAX_LENGTH); this.tableName = tableName; Optional<TajoPullServerService> optional = executionBlockContext.getSharedResource().getPullServerService(); if (optional.isPresent()) { // local pull server service this.pullServerService = optional.get(); this.host = null; this.bootstrap = null; } else if (PullServerUtil.useExternalPullServerService(conf)) { // external pull server service pullServerService = null;//from w ww .j ava 2s . c om String scheme = uri.getScheme() == null ? "http" : uri.getScheme(); this.host = uri.getHost() == null ? "localhost" : uri.getHost(); this.port = uri.getPort(); if (port == -1) { if (scheme.equalsIgnoreCase("http")) { this.port = 80; } else if (scheme.equalsIgnoreCase("https")) { this.port = 443; } } bootstrap = new Bootstrap() .group(NettyUtils.getSharedEventLoopGroup(NettyUtils.GROUP.FETCHER, conf.getIntVar(ConfVars.SHUFFLE_RPC_CLIENT_WORKER_THREAD_NUM))) .channel(NioSocketChannel.class).option(ChannelOption.ALLOCATOR, NettyUtils.ALLOCATOR) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, conf.getIntVar(ConfVars.SHUFFLE_FETCHER_CONNECT_TIMEOUT) * 1000) .option(ChannelOption.SO_RCVBUF, 1048576) // set 1M .option(ChannelOption.TCP_NODELAY, true); } else { endFetch(FetcherState.FETCH_FAILED); throw new TajoInternalError("Pull server service is not initialized"); } }
From source file:org.apache.tajo.worker.RemoteFetcher.java
License:Apache License
public RemoteFetcher(TajoConf conf, URI uri, FileChunk chunk) { super(conf, uri, chunk); String scheme = uri.getScheme() == null ? "http" : uri.getScheme(); this.host = uri.getHost() == null ? "localhost" : uri.getHost(); this.port = uri.getPort(); if (port == -1) { if (scheme.equalsIgnoreCase("http")) { this.port = 80; } else if (scheme.equalsIgnoreCase("https")) { this.port = 443; }//w w w. j av a 2 s. c o m } bootstrap = new Bootstrap() .group(NettyUtils.getSharedEventLoopGroup(NettyUtils.GROUP.FETCHER, conf.getIntVar(TajoConf.ConfVars.SHUFFLE_RPC_CLIENT_WORKER_THREAD_NUM))) .channel(NioSocketChannel.class).option(ChannelOption.ALLOCATOR, NettyUtils.ALLOCATOR) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, conf.getIntVar(TajoConf.ConfVars.SHUFFLE_FETCHER_CONNECT_TIMEOUT) * 1000) .option(ChannelOption.SO_RCVBUF, 1048576) // set 1M .option(ChannelOption.TCP_NODELAY, true); }
From source file:org.apache.tinkerpop.gremlin.driver.simple.NioClient.java
License:Apache License
public NioClient(final URI uri) { super("nio-client-%d"); final Bootstrap b = new Bootstrap().group(group); b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); try {/*from ww w . j a v a 2s . c o m*/ final MessageSerializer serializer = new GryoMessageSerializerV1d0(); b.channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(final SocketChannel ch) { final ChannelPipeline p = ch.pipeline(); p.addLast(new NioGremlinResponseDecoder(serializer), new NioGremlinRequestEncoder(true, serializer), callbackResponseHandler); } }); channel = b.connect(uri.getHost(), uri.getPort()).sync().channel(); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:org.apache.tinkerpop.gremlin.driver.simple.WebSocketClient.java
License:Apache License
public WebSocketClient(final URI uri) { super("ws-client-%d"); final Bootstrap b = new Bootstrap().group(group); b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); final String protocol = uri.getScheme(); if (!"ws".equals(protocol)) throw new IllegalArgumentException("Unsupported protocol: " + protocol); try {/*from w w w . ja v a2 s . c o m*/ final WebSocketClientHandler wsHandler = new WebSocketClientHandler(WebSocketClientHandshakerFactory .newHandshaker(uri, WebSocketVersion.V13, null, false, HttpHeaders.EMPTY_HEADERS, 65536)); final MessageSerializer serializer = new GryoMessageSerializerV1d0(); b.channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() { @Override protected void initChannel(final SocketChannel ch) { final ChannelPipeline p = ch.pipeline(); p.addLast(new HttpClientCodec(), new HttpObjectAggregator(65536), wsHandler, new WebSocketGremlinRequestEncoder(true, serializer), new WebSocketGremlinResponseDecoder(serializer), callbackResponseHandler); } }); channel = b.connect(uri.getHost(), uri.getPort()).sync().channel(); wsHandler.handshakeFuture().get(10000, TimeUnit.MILLISECONDS); } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:org.apache.tinkerpop.gremlin.server.GremlinServer.java
License:Apache License
/** * Start Gremlin Server with {@link Settings} provided to the constructor. *//*from w w w. j a v a 2s .c o m*/ public synchronized CompletableFuture<ServerGremlinExecutor<EventLoopGroup>> start() throws Exception { if (serverStarted != null) { // server already started - don't get it rolling again return serverStarted; } serverStarted = new CompletableFuture<>(); final CompletableFuture<ServerGremlinExecutor<EventLoopGroup>> serverReadyFuture = serverStarted; try { final ServerBootstrap b = new ServerBootstrap(); // when high value is reached then the channel becomes non-writable and stays like that until the // low value is so that there is time to recover b.childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, settings.writeBufferHighWaterMark); b.childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, settings.writeBufferLowWaterMark); b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); // fire off any lifecycle scripts that were provided by the user. hooks get initialized during // ServerGremlinExecutor initialization serverGremlinExecutor.getHooks().forEach(hook -> { logger.info("Executing start up {}", LifeCycleHook.class.getSimpleName()); try { hook.onStartUp(new LifeCycleHook.Context(logger)); } catch (UnsupportedOperationException uoe) { // if the user doesn't implement onStartUp the scriptengine will throw // this exception. it can safely be ignored. } }); final Channelizer channelizer = createChannelizer(settings); channelizer.init(serverGremlinExecutor); b.group(bossGroup, workerGroup).childHandler(channelizer); if (isEpollEnabled) { b.channel(EpollServerSocketChannel.class); } else { b.channel(NioServerSocketChannel.class); } // bind to host/port and wait for channel to be ready b.bind(settings.host, settings.port).addListener(new ChannelFutureListener() { @Override public void operationComplete(final ChannelFuture channelFuture) throws Exception { if (channelFuture.isSuccess()) { ch = channelFuture.channel(); logger.info( "Gremlin Server configured with worker thread pool of {}, gremlin pool of {} and boss thread pool of {}.", settings.threadPoolWorker, settings.gremlinPool, settings.threadPoolBoss); logger.info("Channel started at port {}.", settings.port); serverReadyFuture.complete(serverGremlinExecutor); } else { serverReadyFuture.completeExceptionally(new IOException(String.format( "Could not bind to %s and %s - perhaps something else is bound to that address.", settings.host, settings.port))); } } }); } catch (Exception ex) { logger.error("Gremlin Server Error", ex); serverReadyFuture.completeExceptionally(ex); } return serverStarted; }
From source file:org.apache.zookeeper.ClientCnxnSocketNetty.java
License:Apache License
private Bootstrap configureBootstrapAllocator(Bootstrap bootstrap) { ByteBufAllocator testAllocator = TEST_ALLOCATOR.get(); if (testAllocator != null) { return bootstrap.option(ChannelOption.ALLOCATOR, testAllocator); } else {//from w w w . j a v a2s .com return bootstrap; } }
From source file:org.apache.zookeeper.server.NettyServerCnxnFactory.java
License:Apache License
private ServerBootstrap configureBootstrapAllocator(ServerBootstrap bootstrap) { ByteBufAllocator testAllocator = TEST_ALLOCATOR.get(); if (testAllocator != null) { return bootstrap.option(ChannelOption.ALLOCATOR, testAllocator).childOption(ChannelOption.ALLOCATOR, testAllocator);/*from ww w. j av a 2s .c o m*/ } else { return bootstrap; } }