Search in sources :

Example 6 with Server

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project zemberek-nlp by ahmetaa.

the class ZemberekGrpcServer method start.

public void start() throws Exception {
    Server server = NettyServerBuilder.forPort(port).addService(new LanguageIdServiceImpl()).addService(new PreprocessingServiceImpl()).addService(new NormalizationServiceImpl(context)).addService(new MorphologyServiceImpl(context)).build().start();
    Log.info("Zemberek grpc server started at port: " + port);
    server.awaitTermination();
}
Also used : Server(io.grpc.Server)

Example 7 with Server

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project protoman by spotify.

the class Main method main.

public static void main(final String... args) throws IOException {
    final SchemaRegistry schemaRegistry = createSchemaRegistry();
    final SchemaRegistryService registryService = SchemaRegistryService.create(schemaRegistry, schemaRegistry);
    final SchemaProtodocService protodocService = SchemaProtodocService.create(schemaRegistry);
    final Server grpcServer = ServerBuilder.forPort(GRPC_PORT).addService(registryService).addService(protodocService).intercept(new LoggingServerInterceptor()).build();
    grpcServer.start();
    // HTTP server
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
    final ResourceConfig rc = resourceConfig(schemaRegistry);
    // static files
    final Path staticFilePath = staticFilesPathFromEnv();
    logger.info("Loading static files from " + staticFilePath);
    Files.list(staticFilePath).forEach(p -> logger.debug(p.toAbsolutePath().toString()));
    final StaticHttpHandler staticHttpHandler = new IndexFallbackStaticHttpHandler(staticFilePath.toAbsolutePath().toString());
    final ExtraHandler staticExtraHandler = ExtraHandler.create(staticHttpHandler, "/");
    URI uri = UriBuilder.fromUri("http://0.0.0.0/api").port(HTTP_PORT).build();
    startHttpServer(uri, rc, staticExtraHandler);
    while (!grpcServer.isTerminated()) {
        try {
            grpcServer.awaitTermination();
        } catch (InterruptedException e) {
        }
    }
}
Also used : Path(java.nio.file.Path) HttpServer(org.glassfish.grizzly.http.server.HttpServer) Server(io.grpc.Server) StaticHttpHandler(org.glassfish.grizzly.http.server.StaticHttpHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) URI(java.net.URI)

Example 8 with Server

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project tutorials by eugenp.

the class GrpcServer method main.

public static void main(String[] args) throws IOException, InterruptedException {
    Server server = ServerBuilder.forPort(8080).addService(new HelloServiceImpl()).build();
    System.out.println("Starting server...");
    server.start();
    System.out.println("Server started!");
    server.awaitTermination();
}
Also used : Server(io.grpc.Server)

Example 9 with Server

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project ballerina by ballerina-lang.

the class Stop method execute.

@Override
public void execute(Context context) {
    BStruct serviceEndpoint = (BStruct) context.getRefArgument(SERVICE_ENDPOINT_INDEX);
    Server server = getServerInstance(serviceEndpoint);
    stop(server);
    context.setReturnValues();
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) Server(io.grpc.Server)

Example 10 with Server

use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server in project beam by apache.

the class ServerFactoryTest method runTestUsing.

private Endpoints.ApiServiceDescriptor runTestUsing(ServerFactory serverFactory, ManagedChannelFactory channelFactory) throws Exception {
    Endpoints.ApiServiceDescriptor.Builder apiServiceDescriptorBuilder = Endpoints.ApiServiceDescriptor.newBuilder();
    final Collection<Elements> serverElements = new ArrayList<>();
    final CountDownLatch clientHangedUp = new CountDownLatch(1);
    CallStreamObserver<Elements> serverInboundObserver = TestStreams.withOnNext(serverElements::add).withOnCompleted(clientHangedUp::countDown).build();
    TestDataService service = new TestDataService(serverInboundObserver);
    Server server = serverFactory.allocateAddressAndCreate(ImmutableList.of(service), apiServiceDescriptorBuilder);
    assertFalse(server.isShutdown());
    ManagedChannel channel = channelFactory.forDescriptor(apiServiceDescriptorBuilder.build());
    BeamFnDataGrpc.BeamFnDataStub stub = BeamFnDataGrpc.newStub(channel);
    final Collection<BeamFnApi.Elements> clientElements = new ArrayList<>();
    final CountDownLatch serverHangedUp = new CountDownLatch(1);
    CallStreamObserver<BeamFnApi.Elements> clientInboundObserver = TestStreams.withOnNext(clientElements::add).withOnCompleted(serverHangedUp::countDown).build();
    StreamObserver<Elements> clientOutboundObserver = stub.data(clientInboundObserver);
    StreamObserver<BeamFnApi.Elements> serverOutboundObserver = service.outboundObservers.take();
    clientOutboundObserver.onNext(CLIENT_DATA);
    serverOutboundObserver.onNext(SERVER_DATA);
    clientOutboundObserver.onCompleted();
    clientHangedUp.await();
    serverOutboundObserver.onCompleted();
    serverHangedUp.await();
    assertThat(clientElements, contains(SERVER_DATA));
    assertThat(serverElements, contains(CLIENT_DATA));
    return apiServiceDescriptorBuilder.build();
}
Also used : ApiServiceDescriptor(org.apache.beam.model.pipeline.v1.Endpoints.ApiServiceDescriptor) Server(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server) ArrayList(java.util.ArrayList) Elements(org.apache.beam.model.fnexecution.v1.BeamFnApi.Elements) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedChannel(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel) BeamFnDataGrpc(org.apache.beam.model.fnexecution.v1.BeamFnDataGrpc)

Aggregations

Test (org.junit.Test)76 Server (io.grpc.Server)68 IOException (java.io.IOException)27 ByteString (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString)24 ArrayList (java.util.ArrayList)21 StreamObserver (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver)21 ExecutionException (java.util.concurrent.ExecutionException)20 TimeoutException (java.util.concurrent.TimeoutException)20 CountDownLatch (java.util.concurrent.CountDownLatch)19 ManagedChannel (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel)19 Server (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.Server)18 StatusException (io.grpc.StatusException)17 Metadata (io.grpc.Metadata)12 List (java.util.List)12 BeamFnApi (org.apache.beam.model.fnexecution.v1.BeamFnApi)12 FilterChain (io.grpc.xds.EnvoyServerProtoData.FilterChain)11 ExecutorService (java.util.concurrent.ExecutorService)11 ParallelInstruction (com.google.api.services.dataflow.model.ParallelInstruction)10 ServerCall (io.grpc.ServerCall)10 StreamObserver (io.grpc.stub.StreamObserver)10