当前位置: 首页>>代码示例>>Java>>正文


Java ServerInterceptor类代码示例

本文整理汇总了Java中io.grpc.ServerInterceptor的典型用法代码示例。如果您正苦于以下问题:Java ServerInterceptor类的具体用法?Java ServerInterceptor怎么用?Java ServerInterceptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ServerInterceptor类属于io.grpc包,在下文中一共展示了ServerInterceptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: echoRequestHeadersInterceptor

import io.grpc.ServerInterceptor; //导入依赖的package包/类
/**
 * Echo the request headers from a client into response headers and trailers. Useful for
 * testing end-to-end metadata propagation.
 */
private static ServerInterceptor echoRequestHeadersInterceptor(final Metadata.Key<?>... keys) {
  final Set<Metadata.Key<?>> keySet = new HashSet<Metadata.Key<?>>(Arrays.asList(keys));
  return new ServerInterceptor() {
    @Override
    public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
        ServerCall<ReqT, RespT> call,
        final Metadata requestHeaders,
        ServerCallHandler<ReqT, RespT> next) {
      return next.startCall(new SimpleForwardingServerCall<ReqT, RespT>(call) {
            @Override
            public void sendHeaders(Metadata responseHeaders) {
              responseHeaders.merge(requestHeaders, keySet);
              super.sendHeaders(responseHeaders);
            }

            @Override
            public void close(Status status, Metadata trailers) {
              trailers.merge(requestHeaders, keySet);
              super.close(status, trailers);
            }
          }, requestHeaders);
    }
  };
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:29,代码来源:TestServiceImpl.java

示例2: startServer

import io.grpc.ServerInterceptor; //导入依赖的package包/类
public Server startServer() throws IOException {
  ServerInterceptor headersInterceptor = new TracingMetadataUtils.ServerHeadersInterceptor();
  NettyServerBuilder b =
      NettyServerBuilder.forPort(workerOptions.listenPort)
          .addService(ServerInterceptors.intercept(actionCacheServer, headersInterceptor))
          .addService(ServerInterceptors.intercept(bsServer, headersInterceptor))
          .addService(ServerInterceptors.intercept(casServer, headersInterceptor));

  if (execServer != null) {
    b.addService(ServerInterceptors.intercept(execServer, headersInterceptor));
    b.addService(ServerInterceptors.intercept(watchServer, headersInterceptor));
  } else {
    logger.info("Execution disabled, only serving cache requests.");
  }

  Server server = b.build();
  logger.log(INFO, "Starting gRPC server on port {0,number,#}.", workerOptions.listenPort);
  server.start();

  return server;
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:22,代码来源:RemoteWorker.java

示例3: echoRequestMetadataInHeaders

import io.grpc.ServerInterceptor; //导入依赖的package包/类
/**
 * Echoes request headers with the specified key(s) from a client into response headers only.
 */
private static ServerInterceptor echoRequestMetadataInHeaders(final Metadata.Key<?>... keys) {
  final Set<Metadata.Key<?>> keySet = new HashSet<Metadata.Key<?>>(Arrays.asList(keys));
  return new ServerInterceptor() {
    @Override
    public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
        ServerCall<ReqT, RespT> call,
        final Metadata requestHeaders,
        ServerCallHandler<ReqT, RespT> next) {
      return next.startCall(new SimpleForwardingServerCall<ReqT, RespT>(call) {
        @Override
        public void sendHeaders(Metadata responseHeaders) {
          responseHeaders.merge(requestHeaders, keySet);
          super.sendHeaders(responseHeaders);
        }

        @Override
        public void close(Status status, Metadata trailers) {
          super.close(status, trailers);
        }
      }, requestHeaders);
    }
  };
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:27,代码来源:TestServiceImpl.java

示例4: echoRequestMetadataInTrailers

import io.grpc.ServerInterceptor; //导入依赖的package包/类
/**
 * Echoes request headers with the specified key(s) from a client into response trailers only.
 */
private static ServerInterceptor echoRequestMetadataInTrailers(final Metadata.Key<?>... keys) {
  final Set<Metadata.Key<?>> keySet = new HashSet<Metadata.Key<?>>(Arrays.asList(keys));
  return new ServerInterceptor() {
    @Override
    public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
        ServerCall<ReqT, RespT> call,
        final Metadata requestHeaders,
        ServerCallHandler<ReqT, RespT> next) {
      return next.startCall(new SimpleForwardingServerCall<ReqT, RespT>(call) {
        @Override
        public void sendHeaders(Metadata responseHeaders) {
          super.sendHeaders(responseHeaders);
        }

        @Override
        public void close(Status status, Metadata trailers) {
          trailers.merge(requestHeaders, keySet);
          super.close(status, trailers);
        }
      }, requestHeaders);
    }
  };
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:27,代码来源:TestServiceImpl.java

示例5: getServerBuilder

import io.grpc.ServerInterceptor; //导入依赖的package包/类
@Override
protected AbstractServerImplBuilder<?> getServerBuilder() {
  return NettyServerBuilder.forPort(0)
      .maxMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE)
      .compressorRegistry(compressors)
      .decompressorRegistry(decompressors)
      .intercept(new ServerInterceptor() {
          @Override
          public <ReqT, RespT> Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call,
              Metadata headers, ServerCallHandler<ReqT, RespT> next) {
            Listener<ReqT> listener = next.startCall(call, headers);
            // TODO(carl-mastrangelo): check that encoding was set.
            call.setMessageCompression(true);
            return listener;
          }
        });
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:18,代码来源:TransportCompressionTest.java

示例6: ServerImpl

import io.grpc.ServerInterceptor; //导入依赖的package包/类
/**
 * Construct a server.
 *
 * @param builder builder with configuration for server
 * @param transportServer transport server that will create new incoming transports
 * @param rootContext context that callbacks for new RPCs should be derived from
 */
ServerImpl(
    AbstractServerImplBuilder<?> builder,
    InternalServer transportServer,
    Context rootContext) {
  this.executorPool = Preconditions.checkNotNull(builder.executorPool, "executorPool");
  this.registry = Preconditions.checkNotNull(builder.registryBuilder.build(), "registryBuilder");
  this.fallbackRegistry =
      Preconditions.checkNotNull(builder.fallbackRegistry, "fallbackRegistry");
  this.transportServer = Preconditions.checkNotNull(transportServer, "transportServer");
  // Fork from the passed in context so that it does not propagate cancellation, it only
  // inherits values.
  this.rootContext = Preconditions.checkNotNull(rootContext, "rootContext").fork();
  this.decompressorRegistry = builder.decompressorRegistry;
  this.compressorRegistry = builder.compressorRegistry;
  this.transportFilters = Collections.unmodifiableList(
      new ArrayList<ServerTransportFilter>(builder.transportFilters));
  this.interceptors =
      builder.interceptors.toArray(new ServerInterceptor[builder.interceptors.size()]);
  this.handshakeTimeoutMillis = builder.handshakeTimeoutMillis;
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:28,代码来源:ServerImpl.java

示例7: startCall

import io.grpc.ServerInterceptor; //导入依赖的package包/类
/** Never returns {@code null}. */
private <ReqT, RespT> ServerStreamListener startCall(ServerStream stream, String fullMethodName,
    ServerMethodDefinition<ReqT, RespT> methodDef, Metadata headers,
    Context.CancellableContext context, StatsTraceContext statsTraceCtx) {
  // TODO(ejona86): should we update fullMethodName to have the canonical path of the method?
  ServerCallImpl<ReqT, RespT> call = new ServerCallImpl<ReqT, RespT>(
      stream, methodDef.getMethodDescriptor(), headers, context,
      decompressorRegistry, compressorRegistry);
  ServerCallHandler<ReqT, RespT> callHandler = methodDef.getServerCallHandler();
  statsTraceCtx.serverCallStarted(
      new ServerCallInfoImpl<ReqT, RespT>(
          methodDef.getMethodDescriptor(),
          call.getAttributes(),
          call.getAuthority()));

  for (ServerInterceptor interceptor : interceptors) {
    callHandler = InternalServerInterceptors.interceptCallHandler(interceptor, callHandler);
  }
  ServerCall.Listener<ReqT> listener = callHandler.startCall(call, headers);
  if (listener == null) {
    throw new NullPointerException(
        "startCall() returned a null listener for method " + fullMethodName);
  }
  return call.newServerStreamListener(listener);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:26,代码来源:ServerImpl.java

示例8: buildServerServiceDefinitionsWithInterceptors

import io.grpc.ServerInterceptor; //导入依赖的package包/类
private Iterable<ServerServiceDefinition> buildServerServiceDefinitionsWithInterceptors() {
    List<ServerInterceptor> serverInterceptors = ImmutableList.copyOf(serverInterceptors());

    return ImmutableList.copyOf(Iterables.stream(serverServiceDefinitions())
            .map(s -> applyServiceInterceptor(s, serverInterceptors))
            .iterator());
}
 
开发者ID:joeyb,项目名称:undercarriage,代码行数:8,代码来源:GrpcApplicationBase.java

示例9: buildServerInterceptors

import io.grpc.ServerInterceptor; //导入依赖的package包/类
private Iterable<ServerInterceptor> buildServerInterceptors() {
    ImmutableList.Builder<ServerInterceptor> builder = ImmutableList.builder();

    builder.addAll(enabledServerInterceptors());

    for (GrpcPlugin<? super ConfigT> plugin : grpcPlugins()) {
        builder.addAll(plugin.serverInterceptors());
    }

    return builder.build();
}
 
开发者ID:joeyb,项目名称:undercarriage,代码行数:12,代码来源:GrpcApplicationBase.java

示例10: enabledServerInterceptorsDefaultsToEmpty

import io.grpc.ServerInterceptor; //导入依赖的package包/类
@Test
public void enabledServerInterceptorsDefaultsToEmpty() {
    MockGrpcApplication application = new MockGrpcApplication(configContext, serverBuilder);

    Iterable<ServerInterceptor> serverInterceptors = application.enabledServerInterceptors();

    assertThat(serverInterceptors)
            .isNotNull()
            .isEmpty();
}
 
开发者ID:joeyb,项目名称:undercarriage,代码行数:11,代码来源:GrpcApplicationBaseTests.java

示例11: serverInterceptorsIncludesApplicationAndPluginInterceptors

import io.grpc.ServerInterceptor; //导入依赖的package包/类
@Test
public void serverInterceptorsIncludesApplicationAndPluginInterceptors() {
    Iterable<ServerInterceptor> applicationInterceptors = ImmutableList.of(
            mock(ServerInterceptor.class),
            mock(ServerInterceptor.class));

    Iterable<ServerInterceptor> pluginInterceptors = ImmutableList.of(
            mock(ServerInterceptor.class),
            mock(ServerInterceptor.class));

    GrpcPlugin<GrpcConfigSection> plugin = new GrpcPluginBase<GrpcConfigSection>(
            applicationResolver,
            configContext) {
        @Override
        public Iterable<ServerInterceptor> serverInterceptors() {
            return pluginInterceptors;
        }
    };

    MockGrpcApplication application = new MockGrpcApplication(configContext, serverBuilder) {
        @Override
        protected Iterable<Plugin<? super GrpcConfigSection>> enabledPlugins() {
            return ImmutableList.of(plugin);
        }

        @Override
        protected Iterable<ServerInterceptor> enabledServerInterceptors() {
            return applicationInterceptors;
        }
    };

    assertThat(application.serverInterceptors())
            .containsAll(applicationInterceptors)
            .containsAll(pluginInterceptors);
}
 
开发者ID:joeyb,项目名称:undercarriage,代码行数:36,代码来源:GrpcApplicationBaseTests.java

示例12: startServer

import io.grpc.ServerInterceptor; //导入依赖的package包/类
private void startServer() {
  AbstractServerImplBuilder<?> builder = getServerBuilder();
  if (builder == null) {
    server = null;
    return;
  }
  testServiceExecutor = Executors.newScheduledThreadPool(2);

  List<ServerInterceptor> allInterceptors = ImmutableList.<ServerInterceptor>builder()
      .add(recordServerCallInterceptor(serverCallCapture))
      .add(TestUtils.recordRequestHeadersInterceptor(requestHeadersCapture))
      .add(recordContextInterceptor(contextCapture))
      .addAll(TestServiceImpl.interceptors())
      .build();

  builder
      .addService(
          ServerInterceptors.intercept(
              new TestServiceImpl(testServiceExecutor),
              allInterceptors))
      .addStreamTracerFactory(serverStreamTracerFactory);
  io.grpc.internal.TestingAccessor.setStatsImplementation(
      builder,
      new CensusStatsModule(
          tagger,
          tagContextBinarySerializer,
          serverStatsRecorder,
          GrpcUtil.STOPWATCH_SUPPLIER,
          true));
  try {
    server = builder.build().start();
  } catch (IOException ex) {
    throw new RuntimeException(ex);
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:36,代码来源:AbstractInteropTest.java

示例13: recordServerCallInterceptor

import io.grpc.ServerInterceptor; //导入依赖的package包/类
/**
 * Captures the request attributes. Useful for testing ServerCalls.
 * {@link ServerCall#getAttributes()}
 */
private static ServerInterceptor recordServerCallInterceptor(
    final AtomicReference<ServerCall<?, ?>> serverCallCapture) {
  return new ServerInterceptor() {
    @Override
    public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
        ServerCall<ReqT, RespT> call,
        Metadata requestHeaders,
        ServerCallHandler<ReqT, RespT> next) {
      serverCallCapture.set(call);
      return next.startCall(call, requestHeaders);
    }
  };
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:18,代码来源:AbstractInteropTest.java

示例14: recordContextInterceptor

import io.grpc.ServerInterceptor; //导入依赖的package包/类
private static ServerInterceptor recordContextInterceptor(
    final AtomicReference<Context> contextCapture) {
  return new ServerInterceptor() {
    @Override
    public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
        ServerCall<ReqT, RespT> call,
        Metadata requestHeaders,
        ServerCallHandler<ReqT, RespT> next) {
      contextCapture.set(Context.current());
      return next.startCall(call, requestHeaders);
    }
  };
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:14,代码来源:AbstractInteropTest.java

示例15: interceptors

import io.grpc.ServerInterceptor; //导入依赖的package包/类
/** Returns interceptors necessary for full service implementation. */
public static List<ServerInterceptor> interceptors() {
  return Arrays.asList(
      echoRequestHeadersInterceptor(Util.METADATA_KEY),
      echoRequestMetadataInHeaders(Util.ECHO_INITIAL_METADATA_KEY),
      echoRequestMetadataInTrailers(Util.ECHO_TRAILING_METADATA_KEY));
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:8,代码来源:TestServiceImpl.java


注:本文中的io.grpc.ServerInterceptor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。