io.grpc.MethodDescriptor#getFullMethodName ( )源码实例Demo

下面列出了io.grpc.MethodDescriptor#getFullMethodName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: grpc-nebula-java   文件: CronetClientTransport.java
@Override
public CronetClientStream newStream(final MethodDescriptor<?, ?> method, final Metadata headers,
    final CallOptions callOptions) {
  Preconditions.checkNotNull(method, "method");
  Preconditions.checkNotNull(headers, "headers");

  final String defaultPath = "/" + method.getFullMethodName();
  final String url = "https://" + authority + defaultPath;

  final StatsTraceContext statsTraceCtx =
      StatsTraceContext.newClientContext(callOptions, headers);
  class StartCallback implements Runnable {
    final CronetClientStream clientStream = new CronetClientStream(
        url, userAgent, executor, headers, CronetClientTransport.this, this, lock, maxMessageSize,
        alwaysUsePut, method, statsTraceCtx, callOptions, transportTracer);

    @Override
    public void run() {
      synchronized (lock) {
        if (goAway) {
          clientStream.transportState().transportReportStatus(goAwayStatus, true, new Metadata());
        } else if (started) {
          startStream(clientStream);
        } else {
          throw new AssertionError("Transport is not started");
        }
      }
    }
  }

  return new StartCallback().clientStream;
}
 
源代码2 项目: grpc-spring-boot-starter   文件: GrpcUtils.java
/**
 * Extracts the method name from the given method.
 *
 * @param method The method to get the method name from.
 * @return The extracted method name.
 * @see #extractServiceName(MethodDescriptor)
 */
public static String extractMethodName(final MethodDescriptor<?, ?> method) {
    // This method is the equivalent of MethodDescriptor.extractFullServiceName
    final String fullMethodName = method.getFullMethodName();
    final int index = fullMethodName.lastIndexOf('/');
    if (index == -1) {
        return fullMethodName;
    }
    return fullMethodName.substring(index + 1);
}
 
源代码3 项目: grpc-spring-boot-starter   文件: GrpcUtils.java
/**
 * Extracts the method name from the given method.
 *
 * @param method The method to get the method name from.
 * @return The extracted method name.
 * @see #extractServiceName(MethodDescriptor)
 */
public static String extractMethodName(final MethodDescriptor<?, ?> method) {
    // This method is the equivalent of MethodDescriptor.extractFullServiceName
    final String fullMethodName = method.getFullMethodName();
    final int index = fullMethodName.lastIndexOf('/');
    if (index == -1) {
        return fullMethodName;
    }
    return fullMethodName.substring(index + 1);
}
 
源代码4 项目: grpc-java   文件: CronetClientTransport.java
@Override
public CronetClientStream newStream(final MethodDescriptor<?, ?> method, final Metadata headers,
    final CallOptions callOptions) {
  Preconditions.checkNotNull(method, "method");
  Preconditions.checkNotNull(headers, "headers");

  final String defaultPath = "/" + method.getFullMethodName();
  final String url = "https://" + authority + defaultPath;

  final StatsTraceContext statsTraceCtx =
      StatsTraceContext.newClientContext(callOptions, attrs, headers);
  class StartCallback implements Runnable {
    final CronetClientStream clientStream = new CronetClientStream(
        url, userAgent, executor, headers, CronetClientTransport.this, this, lock, maxMessageSize,
        alwaysUsePut, method, statsTraceCtx, callOptions, transportTracer, useGetForSafeMethods,
        usePutForIdempotentMethods);

    @Override
    public void run() {
      synchronized (lock) {
        if (goAway) {
          clientStream.transportState().transportReportStatus(goAwayStatus, true, new Metadata());
        } else if (started) {
          startStream(clientStream);
        } else {
          throw new AssertionError("Transport is not started");
        }
      }
    }
  }

  return new StartCallback().clientStream;
}
 
源代码5 项目: grpc-java   文件: NettyClientTransport.java
@Override
public ClientStream newStream(
    MethodDescriptor<?, ?> method, Metadata headers, CallOptions callOptions) {
  Preconditions.checkNotNull(method, "method");
  Preconditions.checkNotNull(headers, "headers");
  if (channel == null) {
    return new FailingClientStream(statusExplainingWhyTheChannelIsNull);
  }
  StatsTraceContext statsTraceCtx =
      StatsTraceContext.newClientContext(callOptions, getAttributes(), headers);
  return new NettyClientStream(
      new NettyClientStream.TransportState(
          handler,
          channel.eventLoop(),
          maxMessageSize,
          statsTraceCtx,
          transportTracer,
          method.getFullMethodName()) {
        @Override
        protected Status statusFromFailedFuture(ChannelFuture f) {
          return NettyClientTransport.this.statusFromFailedFuture(f);
        }
      },
      method,
      headers,
      channel,
      authority,
      negotiationScheme,
      userAgent,
      statsTraceCtx,
      transportTracer,
      callOptions,
      useGetForSafeMethods);
}
 
源代码6 项目: genie   文件: ChannelLoggingInterceptor.java
/**
 * {@inheritDoc}
 */
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
    final MethodDescriptor<ReqT, RespT> method,
    final CallOptions callOptions,
    final Channel next
) {
    final String methodType = method.getType().toString();
    final String methodName = method.getFullMethodName();
    final int channelId = next.hashCode();
    log.info("gRPC {} call: {} (channel: {})", methodType, methodName, channelId);
    return next.newCall(method, callOptions);
}
 
源代码7 项目: google-ads-java   文件: LoggingInterceptor.java
private static <ReqT, RespT> String getMethodName(MethodDescriptor<ReqT, RespT> method) {
  return method == null ? null : method.getFullMethodName();
}
 
源代码8 项目: java-grpc   文件: OperationNameConstructor.java
@Override
public <ReqT, RespT> String constructOperationName(MethodDescriptor<ReqT, RespT> method) {
  return method.getFullMethodName();
}
 
private GrpcToReactorMethodBinding findReactorMethod(MethodDescriptor<?, ?> methodDescriptor) {
    String methodName = toMethodNameFromFullName(methodDescriptor.getFullMethodName());
    Method reactorMethod = reactorMethodMap.get(methodName);
    Preconditions.checkNotNull(reactorMethod, "Cannot find corresponding Reactor method for: {}", methodDescriptor);

    ProtoMethodDescriptorSupplier methodDescriptorSupplier = (ProtoMethodDescriptorSupplier) methodDescriptor.getSchemaDescriptor();
    Descriptors.MethodDescriptor md = methodDescriptorSupplier.getMethodDescriptor();
    String inputTypeName = md.getInputType().getName();
    String outputTypeName = md.getOutputType().getName();

    Class<?> reactorReturnType = reactorMethod.getReturnType();
    boolean isMono = reactorReturnType.isAssignableFrom(Mono.class);
    boolean isFlux = !isMono && reactorReturnType.isAssignableFrom(Flux.class);
    Preconditions.checkArgument(isMono || isFlux, "Mono or Flux return types allowed only");
    Type[] returnTypeParameters = ((ParameterizedType) reactorMethod.getGenericReturnType()).getActualTypeArguments();
    Preconditions.checkArgument(
            returnTypeParameters != null && returnTypeParameters.length == 1,
            "Expected one type parameter in the return type: %s", methodDescriptor.getFullMethodName()
    );
    Class returnTypeParameter = (Class) returnTypeParameters[0];

    // Check return types
    if (returnTypeParameter == Void.class) {
        Preconditions.checkArgument(
                outputTypeName.equals("Empty"),
                "Reactor Mono<Void>/Flux<Void> can be mapped to GRPC/Empty only: %s", methodDescriptor.getFullMethodName()
        );
    } else {
        Preconditions.checkArgument(
                returnTypeParameter.getSimpleName().equals(outputTypeName),
                "Different GRPC and Reactor API return types: %s", methodDescriptor.getFullMethodName()
        );
    }

    // Check method arguments
    if (reactorMethod.getParameterCount() == 0) {
        Preconditions.checkArgument(
                inputTypeName.equals(Empty.class.getSimpleName()),
                "Only Empty request argument allowed for Reactor methods with no parameters: %s", methodDescriptor.getFullMethodName()
        );
        return new GrpcToReactorMethodBinding<>(methodDescriptor, reactorMethod, -1, isMono, returnTypeParameter);
    }
    if (reactorMethod.getParameterCount() == 1) {
        if (reactorMethod.getParameterTypes()[0] == contextType) {
            Preconditions.checkArgument(
                    inputTypeName.equals(Empty.class.getSimpleName()),
                    "Only Empty request argument allowed for Reactor methods with no parameters: %s", methodDescriptor.getFullMethodName()
            );
            return new GrpcToReactorMethodBinding<>(methodDescriptor, reactorMethod, 0, isMono, returnTypeParameter);
        }
        Preconditions.checkArgument(
                inputTypeName.equals(reactorMethod.getParameterTypes()[0].getSimpleName()),
                "Reactor and GRPC parameter types do not match: %s", methodDescriptor.getFullMethodName()
        );
        return new GrpcToReactorMethodBinding<>(methodDescriptor, reactorMethod, -1, isMono, returnTypeParameter);
    }
    if (reactorMethod.getParameterCount() == 2) {
        Preconditions.checkArgument(
                reactorMethod.getParameterTypes()[0] == contextType || reactorMethod.getParameterTypes()[1] == contextType,
                "Expected one GRPC method argument, and one CallMetadata value in Reactor method mapped to: %s", methodDescriptor.getFullMethodName()
        );

        int callMetadataPos = reactorMethod.getParameterTypes()[0] == contextType ? 0 : 1;
        int grpcArgumentPos = callMetadataPos == 0 ? 1 : 0;
        Preconditions.checkArgument(
                inputTypeName.equals(reactorMethod.getParameterTypes()[grpcArgumentPos].getSimpleName()),
                "Reactor and GRPC parameter types do not match: %s", methodDescriptor.getFullMethodName()
        );
        return new GrpcToReactorMethodBinding<>(methodDescriptor, reactorMethod, callMetadataPos, isMono, returnTypeParameter);
    }

    throw new IllegalArgumentException("Cannot map GRPC method to any reactor method: " + methodDescriptor.getFullMethodName());
}
 
源代码10 项目: armeria   文件: ArmeriaChannel.java
@Override
public <I, O> ClientCall<I, O> newCall(
        MethodDescriptor<I, O> method, CallOptions callOptions) {
    final HttpRequestWriter req = HttpRequest.streaming(
            RequestHeaders.of(HttpMethod.POST, uri().getPath() + method.getFullMethodName(),
                              HttpHeaderNames.CONTENT_TYPE, serializationFormat.mediaType(),
                              HttpHeaderNames.TE, HttpHeaderValues.TRAILERS));
    final DefaultClientRequestContext ctx = newContext(HttpMethod.POST, req);

    final String fullMethodName = method.getFullMethodName();
    final int methodIndex = fullMethodName.lastIndexOf('/') + 1;
    ctx.logBuilder().name(method.getServiceName(), fullMethodName.substring(methodIndex));
    ctx.logBuilder().serializationFormat(serializationFormat);
    ctx.logBuilder().defer(RequestLogProperty.REQUEST_CONTENT,
                           RequestLogProperty.RESPONSE_CONTENT);

    final ClientOptions options = options();
    final int maxOutboundMessageSizeBytes = options.get(GrpcClientOptions.MAX_OUTBOUND_MESSAGE_SIZE_BYTES);
    final int maxInboundMessageSizeBytes = options.get(GrpcClientOptions.MAX_INBOUND_MESSAGE_SIZE_BYTES);
    final boolean unsafeWrapResponseBuffers = options.get(GrpcClientOptions.UNSAFE_WRAP_RESPONSE_BUFFERS);

    final PooledHttpClient client;

    final CallCredentials credentials = callOptions.getCredentials();
    if (credentials != null) {
        client = new CallCredentialsDecoratingClient(httpClient, credentials, method, authority());
    } else {
        client = httpClient;
    }

    return new ArmeriaClientCall<>(
            ctx,
            params.endpointGroup(),
            client,
            req,
            method,
            maxOutboundMessageSizeBytes,
            maxInboundMessageSizeBytes > 0 ? maxInboundMessageSizeBytes
                                           : Ints.saturatedCast(options.maxResponseLength()),
            callOptions,
            CompressorRegistry.getDefaultInstance(),
            DecompressorRegistry.getDefaultInstance(),
            serializationFormat,
            jsonMarshaller,
            unsafeWrapResponseBuffers,
            advertisedEncodingsHeader);
}
 
源代码11 项目: skywalking   文件: OperationNameFormatUtil.java
public static String formatOperationName(MethodDescriptor<?, ?> methodDescriptor) {
    String fullMethodName = methodDescriptor.getFullMethodName();
    return formatServiceName(fullMethodName) + "." + formatMethodName(fullMethodName);
}
 
源代码12 项目: grpc-java   文件: OkHttpClientStream.java
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();
}
 
源代码13 项目: brave   文件: GrpcParser.java
/** Returns the span name of the request. Defaults to the full grpc method name. */
protected <ReqT, RespT> String spanName(MethodDescriptor<ReqT, RespT> methodDescriptor) {
  return methodDescriptor.getFullMethodName();
}