io.grpc.ServerServiceDefinition Java Examples
The following examples show how to use
io.grpc.ServerServiceDefinition.
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: FramedGrpcService.java From armeria with Apache License 2.0 | 6 votes |
@Override public void serviceAdded(ServiceConfig cfg) { if (maxInboundMessageSizeBytes == ArmeriaMessageDeframer.NO_MAX_INBOUND_MESSAGE_SIZE) { maxInboundMessageSizeBytes = (int) Math.min(cfg.maxRequestLength(), Integer.MAX_VALUE); } if (protoReflectionServiceInterceptor != null) { final Map<String, ServerServiceDefinition> grpcServices = cfg.server().config().virtualHosts().stream() .flatMap(host -> host.serviceConfigs().stream()) .map(serviceConfig -> serviceConfig.service().as(FramedGrpcService.class)) .filter(Objects::nonNull) .flatMap(service -> service.services().stream()) // Armeria allows the same service to be registered multiple times at different // paths, but proto reflection service only supports a single instance of each // service so we dedupe here. .collect(toImmutableMap(def -> def.getServiceDescriptor().getName(), Function.identity(), (a, b) -> a)); protoReflectionServiceInterceptor.setServer(newDummyServer(grpcServices)); } }
Example #2
Source File: GrpcRpcProtocolServer.java From heroic with Apache License 2.0 | 5 votes |
private ServerServiceDefinition bindService() { final ServerServiceDefinition.Builder builder = ServerServiceDefinition.builder(GrpcRpcProtocol.SERVICE); for (final GrpcEndpointHandle<?, ?> spec : container.getEndpoints()) { final ServerCallHandler<byte[], byte[]> handler = serverCallHandlerFor((GrpcEndpointHandle<Object, Object>) spec); builder.addMethod(spec.descriptor(), handler); } return builder.build(); }
Example #3
Source File: ClientCallsTest.java From grpc-java with Apache License 2.0 | 5 votes |
@Test public void blockingServerStreamingCall_interruptedWaitsForOnClose() throws Exception { Integer req = 2; class NoopServerStreamingMethod implements ServerStreamingMethod<Integer, Integer> { ServerCallStreamObserver<Integer> observer; @Override public void invoke(Integer request, StreamObserver<Integer> responseObserver) { observer = (ServerCallStreamObserver<Integer>) responseObserver; } } NoopServerStreamingMethod methodImpl = new NoopServerStreamingMethod(); server = InProcessServerBuilder.forName("noop").directExecutor() .addService(ServerServiceDefinition.builder("some") .addMethod(SERVER_STREAMING_METHOD, ServerCalls.asyncServerStreamingCall(methodImpl)) .build()) .build().start(); InterruptInterceptor interceptor = new InterruptInterceptor(); channel = InProcessChannelBuilder.forName("noop") .directExecutor() .intercept(interceptor) .build(); Iterator<Integer> iter = ClientCalls.blockingServerStreamingCall( channel.newCall(SERVER_STREAMING_METHOD, CallOptions.DEFAULT), req); try { iter.next(); fail(); } catch (StatusRuntimeException ex) { assertTrue(Thread.interrupted()); assertTrue("interrupted", ex.getCause() instanceof InterruptedException); } assertTrue("onCloseCalled", interceptor.onCloseCalled); assertTrue("context not cancelled", methodImpl.observer.isCancelled()); }
Example #4
Source File: TestSdsServer.java From grpc-java with Apache License 2.0 | 5 votes |
/** * Starts the server with given transport params. * * @param name UDS pathname or server name for {@link InProcessServerBuilder} * @param useUds creates a UDS based server if true. * @param useInterceptor if true, uses {@link SdsServerInterceptor} to grab & save Jwt Token. */ void startServer(String name, boolean useUds, boolean useInterceptor) throws IOException { checkNotNull(name, "name"); discoveryService = new SecretDiscoveryServiceImpl(); ServerServiceDefinition serviceDefinition = discoveryService.bindService(); if (useInterceptor) { serviceDefinition = ServerInterceptors.intercept(serviceDefinition, new SdsServerInterceptor()); } if (useUds) { elg = new EpollEventLoopGroup(); boss = new EpollEventLoopGroup(1); server = NettyServerBuilder.forAddress(new DomainSocketAddress(name)) .bossEventLoopGroup(boss) .workerEventLoopGroup(elg) .channelType(EpollServerDomainSocketChannel.class) .addService(serviceDefinition) .directExecutor() .build() .start(); } else { server = InProcessServerBuilder.forName(name) .addService(serviceDefinition) .directExecutor() .build() .start(); } }
Example #5
Source File: ServerImplTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void handlerRegistryPriorities() throws Exception { fallbackRegistry = mock(HandlerRegistry.class); builder.addService( ServerServiceDefinition.builder(new ServiceDescriptor("Waiter", METHOD)) .addMethod(METHOD, callHandler).build()); transportServer = new SimpleServer(); createAndStartServer(); ServerTransportListener transportListener = transportServer.registerNewServerTransport(new SimpleServerTransport()); transportListener.transportReady(Attributes.EMPTY); Metadata requestHeaders = new Metadata(); StatsTraceContext statsTraceCtx = StatsTraceContext.newServerContext(streamTracerFactories, "Waiter/serve", requestHeaders); when(stream.statsTraceContext()).thenReturn(statsTraceCtx); // This call will be handled by callHandler from the internal registry transportListener.streamCreated(stream, "Waiter/serve", requestHeaders); assertEquals(1, executor.runDueTasks()); verify(callHandler).startCall(Matchers.<ServerCall<String, Integer>>anyObject(), Matchers.<Metadata>anyObject()); // This call will be handled by the fallbackRegistry because it's not registred in the internal // registry. transportListener.streamCreated(stream, "Service1/Method2", requestHeaders); assertEquals(1, executor.runDueTasks()); verify(fallbackRegistry).lookupMethod("Service1/Method2", AUTHORITY); verifyNoMoreInteractions(callHandler); verifyNoMoreInteractions(fallbackRegistry); }
Example #6
Source File: HelloJsonServer.java From grpc-java with Apache License 2.0 | 5 votes |
@Override public ServerServiceDefinition bindService() { return io.grpc.ServerServiceDefinition .builder(GreeterGrpc.getServiceDescriptor().getName()) .addMethod(HelloJsonClient.HelloJsonStub.METHOD_SAY_HELLO, asyncUnaryCall( new UnaryMethod<HelloRequest, HelloReply>() { @Override public void invoke( HelloRequest request, StreamObserver<HelloReply> responseObserver) { sayHello(request, responseObserver); } })) .build(); }
Example #7
Source File: GrpcServer.java From cloudbreak with Apache License 2.0 | 5 votes |
@PostConstruct public void start() { checkState(server == null); try { ServerBuilder builder = ServerBuilder.forPort(port); for (ServerServiceDefinition serviceDefinition : serviceDefinitions) { LOG.info("Starting {} service on port {}.", serviceDefinition.getServiceDescriptor().getName(), port); builder.addService(serviceDefinition); } server = builder.build().start(); LOG.info("Server started."); } catch (IOException e) { throw new RuntimeException(e); } }
Example #8
Source File: MockAdGroupAudienceViewService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #9
Source File: MockAdParameterService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #10
Source File: MockGeoTargetConstantService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #11
Source File: MockDisplayKeywordViewService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #12
Source File: MockRecommendationService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #13
Source File: MockAdGroupCriterionLabelService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #14
Source File: MockAdGroupAdLabelService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #15
Source File: MockCurrencyConstantService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #16
Source File: MockRecommendationService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #17
Source File: MockCampaignLabelService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #18
Source File: MockAdGroupAdLabelService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #19
Source File: MockParentalStatusViewService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #20
Source File: MockTopicConstantService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #21
Source File: MockCampaignCriterionService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #22
Source File: MockHotelGroupViewService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #23
Source File: HandlerRegistry.java From armeria with Apache License 2.0 | 4 votes |
List<ServerServiceDefinition> services() { return services; }
Example #24
Source File: MockMobileDeviceConstantService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #25
Source File: AbstractServerServiceFactory.java From pinpoint with Apache License 2.0 | 4 votes |
@Override public Class<ServerServiceDefinition> getObjectType() { return ServerServiceDefinition.class; }
Example #26
Source File: MockOfflineUserDataJobService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #27
Source File: MockOperatingSystemVersionConstantService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #28
Source File: MockDistanceViewService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #29
Source File: MockAdGroupCriterionService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }
Example #30
Source File: MockHotelPerformanceViewService.java From google-ads-java with Apache License 2.0 | 4 votes |
@Override public ServerServiceDefinition getServiceDefinition() { return serviceImpl.bindService(); }