Search in sources :

Example 1 with ServerMethodDefinition

use of io.grpc.ServerMethodDefinition in project alluxio by Alluxio.

the class GrpcSerializationUtils method overrideMethods.

/**
 * Creates a service definition that uses custom marshallers.
 *
 * @param service the service to intercept
 * @param marshallers a map that specifies which marshaller to use for each method
 * @return the new service definition
 */
public static ServerServiceDefinition overrideMethods(final ServerServiceDefinition service, final Map<MethodDescriptor, MethodDescriptor> marshallers) {
    List<ServerMethodDefinition<?, ?>> newMethods = new ArrayList<ServerMethodDefinition<?, ?>>();
    List<MethodDescriptor<?, ?>> newDescriptors = new ArrayList<MethodDescriptor<?, ?>>();
    // intercepts the descriptors
    for (final ServerMethodDefinition<?, ?> definition : service.getMethods()) {
        ServerMethodDefinition<?, ?> newMethod = interceptMethod(definition, marshallers);
        newDescriptors.add(newMethod.getMethodDescriptor());
        newMethods.add(newMethod);
    }
    // builds the new service descriptor
    final ServerServiceDefinition.Builder serviceBuilder = ServerServiceDefinition.builder(new ServiceDescriptor(service.getServiceDescriptor().getName(), newDescriptors));
    // creates the new service definition
    for (ServerMethodDefinition<?, ?> definition : newMethods) {
        serviceBuilder.addMethod(definition);
    }
    return serviceBuilder.build();
}
Also used : ServerMethodDefinition(io.grpc.ServerMethodDefinition) ServiceDescriptor(io.grpc.ServiceDescriptor) ServerServiceDefinition(io.grpc.ServerServiceDefinition) ArrayList(java.util.ArrayList) MethodDescriptor(io.grpc.MethodDescriptor)

Example 2 with ServerMethodDefinition

use of io.grpc.ServerMethodDefinition in project grpc-java by grpc.

the class ManagedChannelImplTest method binaryLogInstalled.

@Test
public void binaryLogInstalled() throws Exception {
    final SettableFuture<Boolean> intercepted = SettableFuture.create();
    channelBuilder.binlog = new BinaryLog() {

        @Override
        public void close() throws IOException {
        // noop
        }

        @Override
        public <ReqT, RespT> ServerMethodDefinition<?, ?> wrapMethodDefinition(ServerMethodDefinition<ReqT, RespT> oMethodDef) {
            return oMethodDef;
        }

        @Override
        public Channel wrapChannel(Channel channel) {
            return ClientInterceptors.intercept(channel, new ClientInterceptor() {

                @Override
                public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
                    intercepted.set(true);
                    return next.newCall(method, callOptions);
                }
            });
        }
    };
    createChannel();
    ClientCall<String, Integer> call = channel.newCall(method, CallOptions.DEFAULT);
    call.start(mockCallListener, new Metadata());
    assertTrue(intercepted.get());
}
Also used : ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) Metadata(io.grpc.Metadata) IOException(java.io.IOException) CallOptions(io.grpc.CallOptions) MethodDescriptor(io.grpc.MethodDescriptor) BinaryLog(io.grpc.BinaryLog) ServerMethodDefinition(io.grpc.ServerMethodDefinition) ClientInterceptor(io.grpc.ClientInterceptor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Example 3 with ServerMethodDefinition

use of io.grpc.ServerMethodDefinition in project grpc-java by grpc.

the class ServerImplTest method binaryLogInstalled.

@Test
public void binaryLogInstalled() throws Exception {
    final SettableFuture<Boolean> intercepted = SettableFuture.create();
    final ServerInterceptor interceptor = new ServerInterceptor() {

        @Override
        public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
            intercepted.set(true);
            return next.startCall(call, headers);
        }
    };
    builder.binlog = new BinaryLog() {

        @Override
        public void close() throws IOException {
        // noop
        }

        @Override
        public <ReqT, RespT> ServerMethodDefinition<?, ?> wrapMethodDefinition(ServerMethodDefinition<ReqT, RespT> oMethodDef) {
            return ServerMethodDefinition.create(oMethodDef.getMethodDescriptor(), InternalServerInterceptors.interceptCallHandlerCreate(interceptor, oMethodDef.getServerCallHandler()));
        }

        @Override
        public Channel wrapChannel(Channel channel) {
            return channel;
        }
    };
    createAndStartServer();
    basicExchangeHelper(METHOD, "Lots of pizza, please", 314, 50);
    assertTrue(intercepted.get());
}
Also used : ServerCallHandler(io.grpc.ServerCallHandler) Channel(io.grpc.Channel) Metadata(io.grpc.Metadata) IOException(java.io.IOException) BinaryLog(io.grpc.BinaryLog) ServerMethodDefinition(io.grpc.ServerMethodDefinition) ServerCall(io.grpc.ServerCall) ServerInterceptor(io.grpc.ServerInterceptor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test)

Aggregations

ServerMethodDefinition (io.grpc.ServerMethodDefinition)3 BinaryLog (io.grpc.BinaryLog)2 Channel (io.grpc.Channel)2 Metadata (io.grpc.Metadata)2 MethodDescriptor (io.grpc.MethodDescriptor)2 IOException (java.io.IOException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Test (org.junit.Test)2 CallOptions (io.grpc.CallOptions)1 ClientInterceptor (io.grpc.ClientInterceptor)1 ManagedChannel (io.grpc.ManagedChannel)1 ServerCall (io.grpc.ServerCall)1 ServerCallHandler (io.grpc.ServerCallHandler)1 ServerInterceptor (io.grpc.ServerInterceptor)1 ServerServiceDefinition (io.grpc.ServerServiceDefinition)1 ServiceDescriptor (io.grpc.ServiceDescriptor)1 ArrayList (java.util.ArrayList)1