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();
}
}
}
}
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();
}
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)));
}
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)));
}
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)));
}
Aggregations