use of io.servicetalk.data.jackson.JacksonSerializationProvider in project FrameworkBenchmarks by TechEmpower.
the class Server method main.
public static void main(String[] args) throws Exception {
/*
* Disable AsyncContext
*/
AsyncContext.disable();
/*
* Factory to implement io pooling
*/
IoExecutor ioExecutor = NettyIoExecutors.createIoExecutor(Runtime.getRuntime().availableProcessors(), new IoThreadFactory("io-pool"));
/*
* Factory to disable headers validation
*/
DefaultHttpHeadersFactory headersFactory = new DefaultHttpHeadersFactory(false, false);
HttpSerializationProvider serializer = HttpSerializationProviders.jsonSerializer(new JacksonSerializationProvider());
// Create a custom server builder with performance enhancements
HttpServers.forPort(8080).executionStrategy(HttpExecutionStrategies.noOffloadsStrategy()).ioExecutor(ioExecutor).disableDrainingRequestPayloadBody().protocols(HttpProtocolConfigs.h1().headersFactory(headersFactory).build()).appendConnectionAcceptorFilter(delegate -> new ConnectionAcceptor() {
@Override
public Completable accept(ConnectionContext context) {
((NettyConnectionContext) context).updateFlushStrategy((current, isOrig) -> FlushStrategies.flushOnEnd());
return delegate.accept(context);
}
}).listenAndAwait((ctx, request, responseFactory) -> {
((NettyConnectionContext) ctx).updateFlushStrategy(((current, isCurrentOriginal) -> FlushStrategies.flushOnEach()));
if (request.path().equals("/json")) {
Map<String, String> obj = new HashMap<String, String>();
obj.put("message", "Hello, World!");
return succeeded(responseFactory.ok().payloadBody(obj, serializer.serializerFor(Map.class)).addHeader("Date", getCurrentTime()).addHeader("Server", "ServiceTalk"));
}
if (request.path().equals("/plaintext")) {
return succeeded(responseFactory.ok().payloadBody("Hello, World!", HttpSerializationProviders.textSerializer()).addHeader("Date", getCurrentTime()).addHeader("Server", "ServiceTalk"));
}
;
return null;
}).awaitShutdown();
}
Aggregations