@Override public void close() { try { Netty4Utils.closeChannels(openChannels); } catch (IOException e) { logger.trace("exception while closing channels", e); } openChannels.clear(); }
/** * Wraps the given ChannelBuffer with a BytesReference */ public static BytesReference toBytesReference(final ByteBuf buffer) { return toBytesReference(buffer, buffer.readableBytes()); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { Netty4Utils.maybeDie(cause); super.exceptionCaught(ctx, cause); } }
public Netty4Transport(Settings settings, ThreadPool threadPool, NetworkService networkService, BigArrays bigArrays, NamedWriteableRegistry namedWriteableRegistry, CircuitBreakerService circuitBreakerService) { super("netty", settings, threadPool, bigArrays, circuitBreakerService, namedWriteableRegistry, networkService); try { // maybe already set by cassandra. Netty4Utils.setAvailableProcessors(EsExecutors.PROCESSORS_SETTING.get(settings)); } catch (java.lang.IllegalStateException e) { logger.warn("Netty4 init error:",e); } this.workerCount = WORKER_COUNT.get(settings); // See AdaptiveReceiveBufferSizePredictor#DEFAULT_XXX for default values in netty..., we can use higher ones for us, even fixed one this.receivePredictorMin = NETTY_RECEIVE_PREDICTOR_MIN.get(settings); this.receivePredictorMax = NETTY_RECEIVE_PREDICTOR_MAX.get(settings); if (receivePredictorMax.getBytes() == receivePredictorMin.getBytes()) { recvByteBufAllocator = new FixedRecvByteBufAllocator((int) receivePredictorMax.getBytes()); } else { recvByteBufAllocator = new AdaptiveRecvByteBufAllocator((int) receivePredictorMin.getBytes(), (int) receivePredictorMin.getBytes(), (int) receivePredictorMax.getBytes()); } }
@Override public void sendMessage(BytesReference reference, ActionListener<Void> listener) { ChannelPromise writePromise = channel.newPromise(); writePromise.addListener(f -> { if (f.isSuccess()) { listener.onResponse(null); } else { final Throwable cause = f.cause(); Netty4Utils.maybeDie(cause); assert cause instanceof Exception; listener.onFailure((Exception) cause); } }); channel.writeAndFlush(Netty4Utils.toByteBuf(reference), writePromise); if (channel.eventLoop().isShutdown()) { listener.onFailure(new TransportException("Cannot send message, event loop is shutting down.")); } }
@Override public void sendMessage(BytesReference reference, ActionListener<Void> listener) { ChannelPromise writePromise = channel.newPromise(); writePromise.addListener(f -> { if (f.isSuccess()) { listener.onResponse(null); } else { final Throwable cause = f.cause(); Netty4Utils.maybeDie(cause); assert cause instanceof Exception; listener.onFailure((Exception) cause); } }); channel.writeAndFlush(Netty4Utils.toByteBuf(reference), writePromise); if (channel.eventLoop().isShutdown()) { listener.onFailure(new TransportException("Cannot send message, event loop is shutting down.")); } }
Netty4Utils.setup();
public Netty4HttpServerTransport(Settings settings, NetworkService networkService, BigArrays bigArrays, ThreadPool threadPool, NamedXContentRegistry xContentRegistry, Dispatcher dispatcher) { super(settings); Netty4Utils.setAvailableProcessors(EsExecutors.PROCESSORS_SETTING.get(settings)); this.networkService = networkService; this.bigArrays = bigArrays;
@Override public void sendMessage(BytesReference reference, ActionListener<Void> listener) { ChannelPromise writePromise = channel.newPromise(); writePromise.addListener(f -> { if (f.isSuccess()) { listener.onResponse(null); } else { final Throwable cause = f.cause(); ExceptionsHelper.maybeDieOnAnotherThread(cause); assert cause instanceof Exception; listener.onFailure((Exception) cause); } }); channel.writeAndFlush(Netty4Utils.toByteBuf(reference), writePromise); if (channel.eventLoop().isShutdown()) { listener.onFailure(new TransportException("Cannot send message, event loop is shutting down.")); } }
/** * Wraps the given ChannelBuffer with a BytesReference */ public static BytesReference toBytesReference(final ByteBuf buffer) { return toBytesReference(buffer, buffer.readableBytes()); }
@Override public void close() { try { Netty4Utils.closeChannels(openChannels); } catch (IOException e) { logger.trace("exception while closing channels", e); } openChannels.clear(); }
super(settings); this.settings = settings; Netty4Utils.setAvailableProcessors(EsExecutors.PROCESSORS_SETTING.get(settings)); this.networkService = networkService; this.bigArrays = bigArrays;
@Override public void sendMessage(BytesReference reference, ActionListener<Void> listener) { ChannelPromise writePromise = channel.newPromise(); writePromise.addListener(f -> { if (f.isSuccess()) { listener.onResponse(null); } else { final Throwable cause = f.cause(); ExceptionsHelper.maybeDieOnAnotherThread(cause); if (cause instanceof Error) { listener.onFailure(new Exception(cause)); } else { listener.onFailure((Exception) cause); } } }); channel.writeAndFlush(Netty4Utils.toByteBuf(reference), writePromise); if (channel.eventLoop().isShutdown()) { listener.onFailure(new TransportException("Cannot send message, event loop is shutting down.")); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { Netty4Utils.maybeDie(cause); super.exceptionCaught(ctx, cause); } }
/** * Wraps the given ChannelBuffer with a BytesReference */ public static BytesReference toBytesReference(final ByteBuf buffer) { return toBytesReference(buffer, buffer.readableBytes()); }
@Override public void close() { try { Netty4Utils.closeChannels(openChannels); } catch (IOException e) { logger.trace("exception while closing channels", e); } openChannels.clear(); }
public Netty4Transport(Settings settings, ThreadPool threadPool, NetworkService networkService, BigArrays bigArrays, NamedWriteableRegistry namedWriteableRegistry, CircuitBreakerService circuitBreakerService) { super("netty", settings, threadPool, bigArrays, circuitBreakerService, namedWriteableRegistry, networkService); Netty4Utils.setAvailableProcessors(EsExecutors.PROCESSORS_SETTING.get(settings)); this.workerCount = WORKER_COUNT.get(settings); // See AdaptiveReceiveBufferSizePredictor#DEFAULT_XXX for default values in netty..., we can use higher ones for us, even fixed one this.receivePredictorMin = NETTY_RECEIVE_PREDICTOR_MIN.get(settings); this.receivePredictorMax = NETTY_RECEIVE_PREDICTOR_MAX.get(settings); if (receivePredictorMax.getBytes() == receivePredictorMin.getBytes()) { recvByteBufAllocator = new FixedRecvByteBufAllocator((int) receivePredictorMax.getBytes()); } else { recvByteBufAllocator = new AdaptiveRecvByteBufAllocator((int) receivePredictorMin.getBytes(), (int) receivePredictorMin.getBytes(), (int) receivePredictorMax.getBytes()); } }
ByteBuf buffer = Netty4Utils.toByteBuf(response.content()); final FullHttpResponse resp; if (HttpMethod.HEAD.equals(nettyRequest.method())) {
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { Netty4Utils.maybeDie(cause); super.exceptionCaught(ctx, cause); }
/** * Wraps the given ChannelBuffer with a BytesReference */ public static BytesReference toBytesReference(final ByteBuf buffer) { return toBytesReference(buffer, buffer.readableBytes()); }