Java Code Examples for com.linecorp.armeria.server.ServerBuilder#workerGroup()

The following examples show how to use com.linecorp.armeria.server.ServerBuilder#workerGroup() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GrpcServiceServerTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.workerGroup(EventLoopGroups.newEventLoopGroup(1), true);
    sb.maxRequestLength(0);

    sb.serviceUnder("/",
                    GrpcService.builder()
                               .setMaxInboundMessageSizeBytes(MAX_MESSAGE_SIZE)
                               .addService(ServerInterceptors.intercept(
                                       new UnitTestServiceImpl(),
                                       REPLACE_EXCEPTION, ADD_TO_CONTEXT))
                               .enableUnframedRequests(true)
                               .supportedSerializationFormats(
                                       GrpcSerializationFormats.values())
                               .useBlockingTaskExecutor(true)
                               .build()
                               .decorate(LoggingService.newDecorator())
                               .decorate((delegate, ctx, req) -> {
                                   ctx.log().whenComplete().thenAccept(requestLogQueue::add);
                                   return delegate.serve(ctx, req);
                               }));
}
 
Example 2
Source File: GrpcServiceServerTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.workerGroup(EventLoopGroups.newEventLoopGroup(1), true);
    sb.maxRequestLength(0);

    sb.serviceUnder("/",
                    GrpcService.builder()
                               .addService(new UnitTestServiceImpl())
                               .build()
                               .decorate(LoggingService.newDecorator())
                               .decorate((delegate, ctx, req) -> {
                                   ctx.log().whenComplete().thenAccept(requestLogQueue::add);
                                   return delegate.serve(ctx, req);
                               }));
}
 
Example 3
Source File: GrpcServiceServerTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.workerGroup(EventLoopGroups.newEventLoopGroup(1), true);
    sb.maxRequestLength(Long.MAX_VALUE);

    sb.serviceUnder("/",
                    GrpcService.builder()
                               .addService(new UnitTestServiceImpl())
                               .build()
                               .decorate(LoggingService.newDecorator())
                               .decorate((delegate, ctx, req) -> {
                                   ctx.log().whenComplete().thenAccept(requestLogQueue::add);
                                   return delegate.serve(ctx, req);
                               }));
}
 
Example 4
Source File: GrpcClientTest.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) {
    sb.workerGroup(EventLoopGroups.newEventLoopGroup(1), true);
    sb.maxRequestLength(MAX_MESSAGE_SIZE);
    sb.idleTimeoutMillis(0);
    sb.http(0);
    sb.https(0);
    sb.tlsSelfSigned();

    final ServerServiceDefinition interceptService =
            ServerInterceptors.intercept(
                    new TestServiceImpl(Executors.newSingleThreadScheduledExecutor()),
                    new ServerInterceptor() {
                        @Override
                        public <REQ, RESP> Listener<REQ> interceptCall(
                                ServerCall<REQ, RESP> call,
                                Metadata requestHeaders,
                                ServerCallHandler<REQ, RESP> next) {
                            final HttpHeadersBuilder fromClient = HttpHeaders.builder();
                            MetadataUtil.fillHeaders(requestHeaders, fromClient);
                            CLIENT_HEADERS_CAPTURE.set(fromClient.build());
                            return next.startCall(
                                    new SimpleForwardingServerCall<REQ, RESP>(call) {
                                        @Override
                                        public void close(Status status, Metadata trailers) {
                                            trailers.merge(requestHeaders);
                                            super.close(status, trailers);
                                        }
                                    }, requestHeaders);
                        }
                    });

    sb.serviceUnder("/",
                    GrpcService.builder()
                               .addService(interceptService)
                               .setMaxInboundMessageSizeBytes(MAX_MESSAGE_SIZE)
                               .setMaxOutboundMessageSizeBytes(MAX_MESSAGE_SIZE)
                               .useClientTimeoutHeader(false)
                               .build()
                               .decorate((client, ctx, req) -> {
                                   final HttpResponse res = client.serve(ctx, req);
                                   return new FilteredHttpResponse(res) {
                                       private boolean headersReceived;

                                       @Override
                                       protected HttpObject filter(HttpObject obj) {
                                           if (obj instanceof HttpHeaders) {
                                               if (!headersReceived) {
                                                   headersReceived = true;
                                               } else {
                                                   SERVER_TRAILERS_CAPTURE.set((HttpHeaders) obj);
                                               }
                                           }
                                           return obj;
                                       }
                                   };
                               }));
}
 
Example 5
Source File: GrpcServiceServerTest.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
protected void configure(ServerBuilder sb) throws Exception {
    sb.workerGroup(EventLoopGroups.newEventLoopGroup(1), true);
    sb.maxRequestLength(0);

    sb.service(
            GrpcService.builder()
                       .setMaxInboundMessageSizeBytes(MAX_MESSAGE_SIZE)
                       .addService(ServerInterceptors.intercept(
                               new UnitTestServiceImpl(),
                               REPLACE_EXCEPTION, ADD_TO_CONTEXT))
                       .enableUnframedRequests(true)
                       .supportedSerializationFormats(GrpcSerializationFormats.values())
                       .build(),
            service -> service
                    .decorate(LoggingService.newDecorator())
                    .decorate((delegate, ctx, req) -> {
                        ctx.log().whenComplete().thenAccept(requestLogQueue::add);
                        return delegate.serve(ctx, req);
                    }));

    // For simplicity, mount onto subpaths with custom options
    sb.serviceUnder(
            "/json-preserving/",
            GrpcService.builder()
                       .addService(new UnitTestServiceImpl())
                       .supportedSerializationFormats(GrpcSerializationFormats.values())
                       .jsonMarshallerFactory(serviceDescriptor -> {
                           return GrpcJsonMarshaller.builder()
                                                    .jsonMarshallerCustomizer(marshaller -> {
                                                        marshaller.preservingProtoFieldNames(true);
                                                    })
                                                    .build(serviceDescriptor);
                       })
                       .build());
    sb.serviceUnder(
            "/no-client-timeout/",
            GrpcService.builder()
                       .addService(new UnitTestServiceImpl())
                       .useClientTimeoutHeader(false)
                       .build());

    sb.service(
            GrpcService.builder()
                       .addService(ProtoReflectionService.newInstance())
                       .build(),
            service -> service.decorate(LoggingService.newDecorator()));
}