Java Code Examples for io.grpc.MethodDescriptor#isSafe()

The following examples show how to use io.grpc.MethodDescriptor#isSafe() . 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: NettyClientStream.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
NettyClientStream(
    TransportState state,
    MethodDescriptor<?, ?> method,
    Metadata headers,
    Channel channel,
    AsciiString authority,
    AsciiString scheme,
    AsciiString userAgent,
    StatsTraceContext statsTraceCtx,
    TransportTracer transportTracer,
    CallOptions callOptions,
    boolean useGetForSafeMethods) {
  super(
      new NettyWritableBufferAllocator(channel.alloc()),
      statsTraceCtx,
      transportTracer,
      headers,
      callOptions,
      useGetForSafeMethods && method.isSafe());
  this.state = checkNotNull(state, "transportState");
  this.writeQueue = state.handler.getWriteQueue();
  this.method = checkNotNull(method, "method");
  this.authority = checkNotNull(authority, "authority");
  this.scheme = checkNotNull(scheme, "scheme");
  this.userAgent = userAgent;
}
 
Example 2
Source File: CronetClientStream.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
CronetClientStream(
    final String url,
    @Nullable String userAgent,
    Executor executor,
    final Metadata headers,
    CronetClientTransport transport,
    Runnable startCallback,
    Object lock,
    int maxMessageSize,
    boolean alwaysUsePut,
    MethodDescriptor<?, ?> method,
    StatsTraceContext statsTraceCtx,
    CallOptions callOptions,
    TransportTracer transportTracer) {
  super(
      new CronetWritableBufferAllocator(), statsTraceCtx, transportTracer, headers, callOptions,
      method.isSafe());
  this.url = Preconditions.checkNotNull(url, "url");
  this.userAgent = Preconditions.checkNotNull(userAgent, "userAgent");
  this.statsTraceCtx = Preconditions.checkNotNull(statsTraceCtx, "statsTraceCtx");
  this.executor = Preconditions.checkNotNull(executor, "executor");
  this.headers = Preconditions.checkNotNull(headers, "headers");
  this.transport = Preconditions.checkNotNull(transport, "transport");
  this.startCallback = Preconditions.checkNotNull(startCallback, "startCallback");
  this.idempotent = method.isIdempotent() || alwaysUsePut;
  // Only delay flushing header for unary rpcs.
  this.delayRequestHeader = (method.getType() == MethodDescriptor.MethodType.UNARY);
  this.annotation = callOptions.getOption(CronetCallOptions.CRONET_ANNOTATION_KEY);
  this.annotations = callOptions.getOption(CronetCallOptions.CRONET_ANNOTATIONS_KEY);
  this.state = new TransportState(maxMessageSize, statsTraceCtx, lock, transportTracer);
}
 
Example 3
Source File: OkHttpClientStream.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
OkHttpClientStream(
    MethodDescriptor<?, ?> method,
    Metadata headers,
    AsyncFrameWriter frameWriter,
    OkHttpClientTransport transport,
    OutboundFlowController outboundFlow,
    Object lock,
    int maxMessageSize,
    int initialWindowSize,
    String authority,
    String userAgent,
    StatsTraceContext statsTraceCtx,
    TransportTracer transportTracer,
    CallOptions callOptions) {
  super(
      new OkHttpWritableBufferAllocator(),
      statsTraceCtx,
      transportTracer,
      headers,
      callOptions,
      method.isSafe());
  this.statsTraceCtx = checkNotNull(statsTraceCtx, "statsTraceCtx");
  this.method = method;
  this.authority = authority;
  this.userAgent = userAgent;
  // OkHttpClientStream is only created after the transport has finished connecting,
  // so it is safe to read the transport attributes.
  // We make a copy here for convenience, even though we can ask the transport.
  this.attributes = transport.getAttributes();
  this.state =
      new TransportState(
          maxMessageSize,
          statsTraceCtx,
          lock,
          frameWriter,
          outboundFlow,
          transport,
          initialWindowSize);
}
 
Example 4
Source File: CronetClientStream.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
CronetClientStream(
    final String url,
    @Nullable String userAgent,
    Executor executor,
    final Metadata headers,
    CronetClientTransport transport,
    Runnable startCallback,
    Object lock,
    int maxMessageSize,
    boolean alwaysUsePut,
    MethodDescriptor<?, ?> method,
    StatsTraceContext statsTraceCtx,
    CallOptions callOptions,
    TransportTracer transportTracer,
    boolean useGetForSafeMethods,
    boolean usePutForIdempotentMethods) {
  super(
      new CronetWritableBufferAllocator(), statsTraceCtx, transportTracer, headers, callOptions,
      useGetForSafeMethods && method.isSafe());
  this.url = Preconditions.checkNotNull(url, "url");
  this.userAgent = Preconditions.checkNotNull(userAgent, "userAgent");
  this.statsTraceCtx = Preconditions.checkNotNull(statsTraceCtx, "statsTraceCtx");
  this.executor = Preconditions.checkNotNull(executor, "executor");
  this.headers = Preconditions.checkNotNull(headers, "headers");
  this.transport = Preconditions.checkNotNull(transport, "transport");
  this.startCallback = Preconditions.checkNotNull(startCallback, "startCallback");
  this.idempotent = (usePutForIdempotentMethods && method.isIdempotent()) || alwaysUsePut;
  // Only delay flushing header for unary rpcs.
  this.delayRequestHeader = (method.getType() == MethodDescriptor.MethodType.UNARY);
  this.annotation = callOptions.getOption(CRONET_ANNOTATION_KEY);
  this.annotations = callOptions.getOption(CRONET_ANNOTATIONS_KEY);
  this.state = new TransportState(maxMessageSize, statsTraceCtx, lock, transportTracer);

  // Tests expect the "plain" deframer behavior, not MigratingDeframer
  // https://github.com/grpc/grpc-java/issues/7140
  optimizeForDirectExecutor();
}
 
Example 5
Source File: NettyClientStream.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
private static boolean useGet(MethodDescriptor<?, ?> method) {
  return method.isSafe();
}
 
Example 6
Source File: OkHttpClientStream.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
OkHttpClientStream(
    MethodDescriptor<?, ?> method,
    Metadata headers,
    ExceptionHandlingFrameWriter frameWriter,
    OkHttpClientTransport transport,
    OutboundFlowController outboundFlow,
    Object lock,
    int maxMessageSize,
    int initialWindowSize,
    String authority,
    String userAgent,
    StatsTraceContext statsTraceCtx,
    TransportTracer transportTracer,
    CallOptions callOptions,
    boolean useGetForSafeMethods) {
  super(
      new OkHttpWritableBufferAllocator(),
      statsTraceCtx,
      transportTracer,
      headers,
      callOptions,
      useGetForSafeMethods && method.isSafe());
  this.statsTraceCtx = checkNotNull(statsTraceCtx, "statsTraceCtx");
  this.method = method;
  this.authority = authority;
  this.userAgent = userAgent;
  // OkHttpClientStream is only created after the transport has finished connecting,
  // so it is safe to read the transport attributes.
  // We make a copy here for convenience, even though we can ask the transport.
  this.attributes = transport.getAttributes();
  this.state =
      new TransportState(
          maxMessageSize,
          statsTraceCtx,
          lock,
          frameWriter,
          outboundFlow,
          transport,
          initialWindowSize,
          method.getFullMethodName());

  // TODO(#7168): fix a potential data race using MigratingThreadDeframer in OkHttp.
  // disabling MigratingThreadDeframer in OkHttp due to the race
  optimizeForDirectExecutor();
}