Search in sources :

Example 21 with ByteBufAllocator

use of io.netty.buffer.ByteBufAllocator in project netty by netty.

the class AbstractComboTestsuiteTest method run.

protected void run() throws Throwable {
    List<TestsuitePermutation.BootstrapComboFactory<SB, CB>> combos = newFactories();
    for (ByteBufAllocator allocator : newAllocators()) {
        int i = 0;
        for (TestsuitePermutation.BootstrapComboFactory<SB, CB> e : combos) {
            sb = e.newServerInstance();
            cb = e.newClientInstance();
            configure(sb, cb, allocator);
            logger.info(String.format("Running: %s %d of %d (%s + %s) with %s", testName.getMethodName(), ++i, combos.size(), sb, cb, StringUtil.simpleClassName(allocator)));
            try {
                Method m = getClass().getMethod(TestUtils.testMethodName(testName), sbClazz, cbClazz);
                m.invoke(this, sb, cb);
            } catch (InvocationTargetException ex) {
                throw ex.getCause();
            }
        }
    }
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 22 with ByteBufAllocator

use of io.netty.buffer.ByteBufAllocator in project ribbon by Netflix.

the class LoadBalancingHttpClient method createRxClient.

@Override
protected HttpClient<I, O> createRxClient(Server server) {
    HttpClientBuilder<I, O> clientBuilder;
    if (requestIdProvider != null) {
        clientBuilder = RxContexts.<I, O>newHttpClientBuilder(server.getHost(), server.getPort(), requestIdProvider, RxContexts.DEFAULT_CORRELATOR, pipelineConfigurator);
    } else {
        clientBuilder = RxContexts.<I, O>newHttpClientBuilder(server.getHost(), server.getPort(), RxContexts.DEFAULT_CORRELATOR, pipelineConfigurator);
    }
    Integer connectTimeout = getProperty(IClientConfigKey.Keys.ConnectTimeout, null, DefaultClientConfigImpl.DEFAULT_CONNECT_TIMEOUT);
    Integer readTimeout = getProperty(IClientConfigKey.Keys.ReadTimeout, null, DefaultClientConfigImpl.DEFAULT_READ_TIMEOUT);
    Boolean followRedirect = getProperty(IClientConfigKey.Keys.FollowRedirects, null, null);
    HttpClientConfig.Builder builder = new HttpClientConfig.Builder().readTimeout(readTimeout, TimeUnit.MILLISECONDS);
    if (followRedirect != null) {
        builder.setFollowRedirect(followRedirect);
    }
    clientBuilder.channelOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeout).config(builder.build());
    if (isPoolEnabled()) {
        clientBuilder.withConnectionPoolLimitStrategy(poolStrategy).withIdleConnectionsTimeoutMillis(idleConnectionEvictionMills).withPoolIdleCleanupScheduler(poolCleanerScheduler);
    } else {
        clientBuilder.withNoConnectionPooling();
    }
    if (sslContextFactory != null) {
        try {
            SSLEngineFactory myFactory = new DefaultFactories.SSLContextBasedFactory(sslContextFactory.getSSLContext()) {

                @Override
                public SSLEngine createSSLEngine(ByteBufAllocator allocator) {
                    SSLEngine myEngine = super.createSSLEngine(allocator);
                    myEngine.setUseClientMode(true);
                    return myEngine;
                }
            };
            clientBuilder.withSslEngineFactory(myFactory);
        } catch (ClientSslSocketFactoryException e) {
            throw new RuntimeException(e);
        }
    }
    return clientBuilder.build();
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) ClientSslSocketFactoryException(com.netflix.client.ssl.ClientSslSocketFactoryException) SSLEngine(javax.net.ssl.SSLEngine) URI(java.net.URI) SSLEngineFactory(io.reactivex.netty.pipeline.ssl.SSLEngineFactory) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 23 with ByteBufAllocator

use of io.netty.buffer.ByteBufAllocator in project ratpack by ratpack.

the class ServerSentEvents method render.

/**
   * {@inheritDoc}
   */
@Override
public void render(Context context) throws Exception {
    ByteBufAllocator bufferAllocator = context.get(ByteBufAllocator.class);
    Response response = context.getResponse();
    response.getHeaders().add(HttpHeaderConstants.CONTENT_TYPE, HttpHeaderConstants.TEXT_EVENT_STREAM_CHARSET_UTF_8);
    response.getHeaders().add(HttpHeaderConstants.TRANSFER_ENCODING, HttpHeaderConstants.CHUNKED);
    response.getHeaders().add(HttpHeaderConstants.CACHE_CONTROL, HttpHeaderConstants.NO_CACHE_FULL);
    response.getHeaders().add(HttpHeaderConstants.PRAGMA, HttpHeaderConstants.NO_CACHE);
    response.sendStream(Streams.map(publisher, i -> ServerSentEventEncoder.INSTANCE.encode(i, bufferAllocator)));
}
Also used : Response(ratpack.http.Response) Response(ratpack.http.Response) Context(ratpack.handling.Context) ServerSentEventEncoder(ratpack.sse.internal.ServerSentEventEncoder) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) Action(ratpack.func.Action) Publisher(org.reactivestreams.Publisher) Renderable(ratpack.render.Renderable) Streams(ratpack.stream.Streams) HttpHeaderConstants(ratpack.http.internal.HttpHeaderConstants) DefaultEvent(ratpack.sse.internal.DefaultEvent) ByteBufAllocator(io.netty.buffer.ByteBufAllocator)

Example 24 with ByteBufAllocator

use of io.netty.buffer.ByteBufAllocator in project ratpack by ratpack.

the class WebSockets method websocketBroadcast.

/**
   * Sets up a websocket that sends the published Strings to a client.
   * <p>
   * This takes the place of a {@link Streams#bindExec(Publisher)} call.
   *
   * @param context the request handling context
   * @param broadcaster a {@link Publisher} of Strings to send to the websocket client
   */
public static void websocketBroadcast(final Context context, final Publisher<String> broadcaster) {
    ByteBufAllocator bufferAllocator = context.get(ByteBufAllocator.class);
    websocketByteBufBroadcast(context, Streams.map(broadcaster, s -> ByteBufUtil.encodeString(bufferAllocator, CharBuffer.wrap(s), CharsetUtil.UTF_8)));
}
Also used : Function(ratpack.func.Function) Context(ratpack.handling.Context) CharBuffer(java.nio.CharBuffer) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) Publisher(org.reactivestreams.Publisher) DefaultWebSocketConnector(ratpack.websocket.internal.DefaultWebSocketConnector) WebsocketBroadcastSubscriber(ratpack.websocket.internal.WebsocketBroadcastSubscriber) ByteBufUtil(io.netty.buffer.ByteBufUtil) ByteBuf(io.netty.buffer.ByteBuf) ServerConfig(ratpack.server.ServerConfig) WebSocketEngine(ratpack.websocket.internal.WebSocketEngine) CharsetUtil(io.netty.util.CharsetUtil) Streams(ratpack.stream.Streams) ByteBufAllocator(io.netty.buffer.ByteBufAllocator)

Example 25 with ByteBufAllocator

use of io.netty.buffer.ByteBufAllocator in project ratpack by ratpack.

the class MetricsWebsocketBroadcastHandler method handle.

@Override
public void handle(final Context context) throws Exception {
    final MetricsBroadcaster broadcaster = context.get(MetricsBroadcaster.class);
    final ByteBufAllocator byteBufAllocator = context.get(ByteBufAllocator.class);
    final DropwizardMetricsConfig config = context.get(DropwizardMetricsConfig.class);
    MetricFilter filter = MetricFilter.ALL;
    if (config.getWebSocket().isPresent()) {
        filter = new RegexMetricFilter(config.getWebSocket().get().getIncludeFilter(), config.getWebSocket().get().getExcludeFilter());
    }
    websocketByteBufBroadcast(context, broadcaster.map(new MetricRegistryJsonMapper(byteBufAllocator, filter)));
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) MetricsBroadcaster(ratpack.dropwizard.metrics.internal.MetricsBroadcaster) MetricFilter(com.codahale.metrics.MetricFilter) RegexMetricFilter(ratpack.dropwizard.metrics.internal.RegexMetricFilter) MetricRegistryJsonMapper(ratpack.dropwizard.metrics.internal.MetricRegistryJsonMapper) RegexMetricFilter(ratpack.dropwizard.metrics.internal.RegexMetricFilter)

Aggregations

ByteBufAllocator (io.netty.buffer.ByteBufAllocator)27 ByteBuf (io.netty.buffer.ByteBuf)12 Channel (io.netty.channel.Channel)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 RecvByteBufAllocator (io.netty.channel.RecvByteBufAllocator)3 URI (java.net.URI)3 Test (org.junit.Test)3 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)2 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)2 UnpooledByteBufAllocator (io.netty.buffer.UnpooledByteBufAllocator)2 ChannelFuture (io.netty.channel.ChannelFuture)2 ChannelFutureListener (io.netty.channel.ChannelFutureListener)2 ChannelPipeline (io.netty.channel.ChannelPipeline)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 Publisher (org.reactivestreams.Publisher)2 Context (ratpack.handling.Context)2 Streams (ratpack.stream.Streams)2 MetricFilter (com.codahale.metrics.MetricFilter)1