Search in sources :

Example 6 with BindableService

use of io.grpc.BindableService in project pinpoint by naver.

the class AgentServerTestMain method run.

public void run() throws Exception {
    GrpcReceiver grpcReceiver = new GrpcReceiver();
    grpcReceiver.setEnable(true);
    grpcReceiver.setBeanName("AgentServer");
    BindAddress.Builder builder = BindAddress.newBuilder();
    builder.setPort(PORT);
    builder.setIp(IP);
    grpcReceiver.setBindAddress(builder.build());
    PingEventHandler pingEventHandler = mock(PingEventHandler.class);
    BindableService agentService = new AgentService(new MockDispatchHandler(), pingEventHandler, Executors.newFixedThreadPool(8), serverRequestFactory);
    grpcReceiver.setBindableServiceList(Arrays.asList(agentService, new MetadataService(new MockDispatchHandler(), Executors.newFixedThreadPool(8), serverRequestFactory)));
    grpcReceiver.setAddressFilter(new MockAddressFilter());
    grpcReceiver.setExecutor(Executors.newFixedThreadPool(8));
    grpcReceiver.setServerOption(ServerOption.newBuilder().build());
    grpcReceiver.afterPropertiesSet();
    grpcReceiver.blockUntilShutdown();
    grpcReceiver.destroy();
}
Also used : PingEventHandler(com.navercorp.pinpoint.grpc.server.lifecycle.PingEventHandler) AgentService(com.navercorp.pinpoint.collector.receiver.grpc.service.AgentService) BindAddress(com.navercorp.pinpoint.collector.receiver.BindAddress) MetadataService(com.navercorp.pinpoint.collector.receiver.grpc.service.MetadataService) BindableService(io.grpc.BindableService)

Example 7 with BindableService

use of io.grpc.BindableService in project pinpoint by naver.

the class ServerFactory method build.

public Server build() throws SSLException {
    InetSocketAddress bindAddress = new InetSocketAddress(this.hostname, this.port);
    PinpointNettyServerBuilder serverBuilder = PinpointNettyServerBuilder.forAddress(bindAddress);
    serverBuilder.serverListenerDelegator(new LogIdServerListenerDelegator());
    logger.info("ChannelType:{}", channelType.getSimpleName());
    serverBuilder.channelType(channelType);
    serverBuilder.bossEventLoopGroup(bossEventLoopGroup);
    serverBuilder.workerEventLoopGroup(workerEventLoopGroup);
    setupInternal(serverBuilder);
    for (Object service : this.bindableServices) {
        if (service instanceof BindableService) {
            logger.info("Add BindableService={}, server={}", service, name);
            serverBuilder.addService((BindableService) service);
        } else if (service instanceof ServerServiceDefinition) {
            final ServerServiceDefinition definition = (ServerServiceDefinition) service;
            logger.info("Add ServerServiceDefinition={}, server={}", definition.getServiceDescriptor(), name);
            serverBuilder.addService(definition);
        }
    }
    for (ServerTransportFilter transportFilter : this.serverTransportFilters) {
        logger.info("Add transportFilter={}, server={}", transportFilter, name);
        serverBuilder.addTransportFilter(transportFilter);
    }
    for (ServerInterceptor serverInterceptor : this.serverInterceptors) {
        logger.info("Add intercept={}, server={}", serverInterceptor, name);
        serverBuilder.intercept(serverInterceptor);
    }
    serverBuilder.executor(serverExecutor);
    setupServerOption(serverBuilder);
    if (sslServerConfig.isEnable()) {
        logger.debug("Enable sslConfig.({})", sslServerConfig);
        SslContext sslContext = SslContextFactory.create(sslServerConfig);
        serverBuilder.sslContext(sslContext);
    }
    Server server = serverBuilder.build();
    if (server instanceof InternalWithLogId) {
        final InternalWithLogId logId = (InternalWithLogId) server;
        final long serverLogId = logId.getLogId().getId();
        logger.info("{} serverLogId:{}", name, serverLogId);
        if (channelzRegistry != null) {
            channelzRegistry.addServer(serverLogId, name);
        }
    }
    return server;
}
Also used : Server(io.grpc.Server) PinpointNettyServerBuilder(io.grpc.netty.PinpointNettyServerBuilder) InetSocketAddress(java.net.InetSocketAddress) ServerServiceDefinition(io.grpc.ServerServiceDefinition) ServerInterceptor(io.grpc.ServerInterceptor) InternalWithLogId(io.grpc.InternalWithLogId) ServerTransportFilter(io.grpc.ServerTransportFilter) LogIdServerListenerDelegator(io.grpc.netty.LogIdServerListenerDelegator) BindableService(io.grpc.BindableService) SslContext(io.netty.handler.ssl.SslContext)

Aggregations

BindableService (io.grpc.BindableService)7 ServerServiceDefinition (io.grpc.ServerServiceDefinition)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 BindAddress (com.navercorp.pinpoint.collector.receiver.BindAddress)1 AgentService (com.navercorp.pinpoint.collector.receiver.grpc.service.AgentService)1 MetadataService (com.navercorp.pinpoint.collector.receiver.grpc.service.MetadataService)1 PingEventHandler (com.navercorp.pinpoint.grpc.server.lifecycle.PingEventHandler)1 InternalWithLogId (io.grpc.InternalWithLogId)1 Server (io.grpc.Server)1 ServerInterceptor (io.grpc.ServerInterceptor)1 ServerTransportFilter (io.grpc.ServerTransportFilter)1 LogIdServerListenerDelegator (io.grpc.netty.LogIdServerListenerDelegator)1 PinpointNettyServerBuilder (io.grpc.netty.PinpointNettyServerBuilder)1 SslContext (io.netty.handler.ssl.SslContext)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 InetSocketAddress (java.net.InetSocketAddress)1