List of usage examples for io.netty.buffer PooledByteBufAllocator DEFAULT
PooledByteBufAllocator DEFAULT
To view the source code for io.netty.buffer PooledByteBufAllocator DEFAULT.
Click Source Link
From source file:org.apache.rocketmq.remoting.netty.NettyRemotingServer.java
License:Apache License
@Override public void start() { this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(nettyServerConfig.getServerWorkerThreads(), new ThreadFactory() { private AtomicInteger threadIndex = new AtomicInteger(0); @Override/*from ww w.j av a2 s . c o m*/ public Thread newThread(Runnable r) { return new Thread(r, "NettyServerCodecThread_" + this.threadIndex.incrementAndGet()); } }); ServerBootstrap childHandler = this.serverBootstrap .group(this.eventLoopGroupBoss, this.eventLoopGroupSelector).channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 1024).option(ChannelOption.SO_REUSEADDR, true) .option(ChannelOption.SO_KEEPALIVE, false).childOption(ChannelOption.TCP_NODELAY, true) .option(ChannelOption.SO_SNDBUF, nettyServerConfig.getServerSocketSndBufSize()) .option(ChannelOption.SO_RCVBUF, nettyServerConfig.getServerSocketRcvBufSize()) .localAddress(new InetSocketAddress(this.nettyServerConfig.getListenPort())) .childHandler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(defaultEventExecutorGroup, new NettyEncoder(), new NettyDecoder(), new IdleStateHandler(0, 0, nettyServerConfig.getServerChannelMaxIdleTimeSeconds()), new NettyConnetManageHandler(), new NettyServerHandler()); } }); if (nettyServerConfig.isServerPooledByteBufAllocatorEnable()) { childHandler.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); } try { ChannelFuture sync = this.serverBootstrap.bind().sync(); InetSocketAddress addr = (InetSocketAddress) sync.channel().localAddress(); this.port = addr.getPort(); } catch (InterruptedException e1) { throw new RuntimeException("this.serverBootstrap.bind().sync() InterruptedException", e1); } if (this.channelEventListener != null) { this.nettyEventExecuter.start(); } this.timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { try { NettyRemotingServer.this.scanResponseTable(); } catch (Exception e) { log.error("scanResponseTable exception", e); } } }, 1000 * 3, 1000); }
From source file:org.apache.tajo.pullserver.PullServerAuxService.java
License:Apache License
@Override public synchronized void init(Configuration conf) { try {//from w w w.j ava2 s . c o m manageOsCache = conf.getBoolean(SHUFFLE_MANAGE_OS_CACHE, DEFAULT_SHUFFLE_MANAGE_OS_CACHE); readaheadLength = conf.getInt(SHUFFLE_READAHEAD_BYTES, DEFAULT_SHUFFLE_READAHEAD_BYTES); selector = RpcChannelFactory.createServerChannelFactory("PullServerAuxService", 0) .option(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.TCP_NODELAY, true); localFS = new LocalFileSystem(); super.init(new Configuration(conf)); } catch (Throwable t) { LOG.error(t); } }
From source file:org.apache.tajo.pullserver.TajoPullServerService.java
License:Apache License
@Override public void init(Configuration conf) { try {/*from w w w .j a v a 2s. c om*/ manageOsCache = conf.getBoolean(SHUFFLE_MANAGE_OS_CACHE, DEFAULT_SHUFFLE_MANAGE_OS_CACHE); readaheadLength = conf.getInt(SHUFFLE_READAHEAD_BYTES, DEFAULT_SHUFFLE_READAHEAD_BYTES); int workerNum = conf.getInt("tajo.shuffle.rpc.server.worker-thread-num", Runtime.getRuntime().availableProcessors() * 2); selector = RpcChannelFactory.createServerChannelFactory("TajoPullServerService", workerNum) .option(ChannelOption.TCP_NODELAY, true) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.TCP_NODELAY, true); localFS = new LocalFileSystem(); conf.setInt(TajoConf.ConfVars.PULLSERVER_PORT.varname, TajoConf.ConfVars.PULLSERVER_PORT.defaultIntVal); super.init(conf); LOG.info("Tajo PullServer initialized: readaheadLength=" + readaheadLength); } catch (Throwable t) { LOG.error(t, t); } }
From source file:org.apache.tajo.rpc.NettyClientBase.java
License:Apache License
protected void init(ChannelInitializer<Channel> initializer) { this.bootstrap = new Bootstrap(); this.bootstrap.channel(NioSocketChannel.class).handler(initializer) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .option(ChannelOption.SO_REUSEADDR, true) .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECTION_TIMEOUT) .option(ChannelOption.SO_RCVBUF, 1048576 * 10).option(ChannelOption.TCP_NODELAY, true); }
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); }/*w w w . ja v a 2 s . co m*/ 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; }//ww w. j a v a 2 s . 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.ws.rs.netty.NettyRestHandlerContainer.java
License:Apache License
protected void messageReceived(ChannelHandlerContext ctx, FullHttpRequest request) throws Exception { URI baseUri = getBaseUri(ctx, request); URI requestUri = baseUri.resolve(request.getUri()); ByteBuf responseContent = PooledByteBufAllocator.DEFAULT.buffer(); FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, responseContent);/*from w w w .j a va2s . co m*/ NettyRestResponseWriter responseWriter = new NettyRestResponseWriter(ctx, response); ContainerRequest containerRequest = new ContainerRequest(baseUri, requestUri, request.getMethod().name(), getSecurityContext(), new MapPropertiesDelegate()); containerRequest.setEntityStream(new ByteBufInputStream(request.content())); HttpHeaders httpHeaders = request.headers(); for (String headerName : httpHeaders.names()) { List<String> headerValues = httpHeaders.getAll(headerName); containerRequest.headers(headerName, headerValues); } containerRequest.setWriter(responseWriter); try { applicationHandler.handle(containerRequest); } finally { responseWriter.releaseConnection(); } }
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 w w w .j a v a 2 s .com*/ 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 .jav a 2 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. */// www . j a v a 2 s . 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; }