io.grpc.ServerTransportFilter Java Examples

The following examples show how to use io.grpc.ServerTransportFilter. 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: ServerImpl.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Override
public Attributes transportReady(Attributes attributes) {
  handshakeTimeoutFuture.cancel(false);
  handshakeTimeoutFuture = null;

  for (ServerTransportFilter filter : transportFilters) {
    attributes = Preconditions.checkNotNull(filter.transportReady(attributes),
        "Filter %s returned null", filter);
  }
  this.attributes = attributes;
  return attributes;
}
 
Example #2
Source File: ServerImpl.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Override
public void transportTerminated() {
  if (handshakeTimeoutFuture != null) {
    handshakeTimeoutFuture.cancel(false);
    handshakeTimeoutFuture = null;
  }
  for (ServerTransportFilter filter : transportFilters) {
    filter.transportTerminated(attributes);
  }
  transportClosed(transport);
}
 
Example #3
Source File: ServerFactory.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public Server build() {
    InetSocketAddress bindAddress = new InetSocketAddress(this.hostname, this.port);
    NettyServerBuilder serverBuilder = NettyServerBuilder.forAddress(bindAddress);
    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);

    Server server = serverBuilder.build();
    return server;
}
 
Example #4
Source File: ChannelFactoryTest.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
private static void addFilter(ServerFactory serverFactory) {
    TransportMetadataFactory transportMetadataFactory = new TransportMetadataFactory(ChannelFactoryTest.class.getSimpleName());
    final ServerTransportFilter metadataTransportFilter = new MetadataServerTransportFilter(transportMetadataFactory);
    serverFactory.addTransportFilter(metadataTransportFilter);

    ServerInterceptor transportMetadataServerInterceptor = new TransportMetadataServerInterceptor();
    serverFactory.addInterceptor(transportMetadataServerInterceptor);

}
 
Example #5
Source File: ServerImpl.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public Attributes transportReady(Attributes attributes) {
  handshakeTimeoutFuture.cancel(false);
  handshakeTimeoutFuture = null;

  for (ServerTransportFilter filter : transportFilters) {
    attributes = Preconditions.checkNotNull(filter.transportReady(attributes),
        "Filter %s returned null", filter);
  }
  this.attributes = attributes;
  return attributes;
}
 
Example #6
Source File: ServerImpl.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public void transportTerminated() {
  if (handshakeTimeoutFuture != null) {
    handshakeTimeoutFuture.cancel(false);
    handshakeTimeoutFuture = null;
  }
  for (ServerTransportFilter filter : transportFilters) {
    filter.transportTerminated(attributes);
  }
  transportClosed(transport);
}
 
Example #7
Source File: AltsServerBuilder.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public AltsServerBuilder addTransportFilter(ServerTransportFilter filter) {
  delegate.addTransportFilter(filter);
  return this;
}
 
Example #8
Source File: AbstractServerImplBuilder.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Override
public final T addTransportFilter(ServerTransportFilter filter) {
  transportFilters.add(checkNotNull(filter, "filter"));
  return thisT();
}
 
Example #9
Source File: DropwizardServerBuilder.java    From dropwizard-grpc with Apache License 2.0 4 votes vote down vote up
@Override
public DropwizardServerBuilder addTransportFilter(final ServerTransportFilter filter) {
    origin.addTransportFilter(filter);
    return this;
}
 
Example #10
Source File: GrpcReceiver.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
    if (Boolean.FALSE == this.enable) {
        return;
    }

    Objects.requireNonNull(this.beanName, "beanName");
    Objects.requireNonNull(this.bindIp, "bindIp");
    Objects.requireNonNull(this.addressFilter, "addressFilter");
    Assert.isTrue(CollectionUtils.hasLength(this.serviceList), "serviceList must not be empty");
    Objects.requireNonNull(this.serverOption, "serverOption");

    this.serverFactory = new ServerFactory(beanName, this.bindIp, this.bindPort, this.executor, serverOption);
    ServerTransportFilter permissionServerTransportFilter = new PermissionServerTransportFilter(this.beanName, addressFilter);
    this.serverFactory.addTransportFilter(permissionServerTransportFilter);

    TransportMetadataFactory transportMetadataFactory = new TransportMetadataFactory(beanName);
    // Mandatory interceptor
    final ServerTransportFilter metadataTransportFilter = new MetadataServerTransportFilter(transportMetadataFactory);
    this.serverFactory.addTransportFilter(metadataTransportFilter);

    if (CollectionUtils.hasLength(transportFilterList)) {
        for (ServerTransportFilter transportFilter : transportFilterList) {
            this.serverFactory.addTransportFilter(transportFilter);
        }
    }

    // Mandatory interceptor
    ServerInterceptor transportMetadataServerInterceptor = new TransportMetadataServerInterceptor();
    this.serverFactory.addInterceptor(transportMetadataServerInterceptor);

    if (CollectionUtils.hasLength(serverInterceptorList)) {
        for (ServerInterceptor serverInterceptor : serverInterceptorList) {
            this.serverFactory.addInterceptor(serverInterceptor);
        }
    }

    // Add service
    addService();

    this.server = serverFactory.build();
    if (logger.isInfoEnabled()) {
        logger.info("Start {} server {}", this.beanName, this.server);
    }
    this.server.start();
}
 
Example #11
Source File: GrpcReceiver.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
public void setTransportFilterList(List<ServerTransportFilter> transportFilterList) {
    this.transportFilterList = transportFilterList;
}
 
Example #12
Source File: ServerFactory.java    From pinpoint with Apache License 2.0 4 votes vote down vote up
public void addTransportFilter(ServerTransportFilter serverTransportFilter) {
    Assert.requireNonNull(serverTransportFilter, "serverTransportFilter");
    this.serverTransportFilters.add(serverTransportFilter);
}
 
Example #13
Source File: XdsServerBuilder.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
public XdsServerBuilder addTransportFilter(ServerTransportFilter filter) {
  delegate.addTransportFilter(filter);
  return this;
}
 
Example #14
Source File: AltsServerBuilder.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public AltsServerBuilder addTransportFilter(ServerTransportFilter filter) {
  delegate.addTransportFilter(filter);
  return this;
}
 
Example #15
Source File: AbstractServerImplBuilder.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
public final T addTransportFilter(ServerTransportFilter filter) {
  transportFilters.add(checkNotNull(filter, "filter"));
  return thisT();
}