本文整理汇总了Java中io.grpc.MethodDescriptor.getType方法的典型用法代码示例。如果您正苦于以下问题:Java MethodDescriptor.getType方法的具体用法?Java MethodDescriptor.getType怎么用?Java MethodDescriptor.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.grpc.MethodDescriptor
的用法示例。
在下文中一共展示了MethodDescriptor.getType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ClientCallImpl
import io.grpc.MethodDescriptor; //导入方法依赖的package包/类
ClientCallImpl(
MethodDescriptor<ReqT, RespT> method, Executor executor, CallOptions callOptions,
ClientTransportProvider clientTransportProvider,
ScheduledExecutorService deadlineCancellationExecutor,
CallTracer channelCallsTracer) {
this.method = method;
// If we know that the executor is a direct executor, we don't need to wrap it with a
// SerializingExecutor. This is purely for performance reasons.
// See https://github.com/grpc/grpc-java/issues/368
this.callExecutor = executor == directExecutor()
? new SerializeReentrantCallsDirectExecutor()
: new SerializingExecutor(executor);
this.channelCallsTracer = channelCallsTracer;
// Propagate the context from the thread which initiated the call to all callbacks.
this.context = Context.current();
this.unaryRequest = method.getType() == MethodType.UNARY
|| method.getType() == MethodType.SERVER_STREAMING;
this.callOptions = callOptions;
this.clientTransportProvider = clientTransportProvider;
this.deadlineCancellationExecutor = deadlineCancellationExecutor;
}
示例2: of
import io.grpc.MethodDescriptor; //导入方法依赖的package包/类
static GrpcMethod of(MethodDescriptor<?, ?> method) {
String serviceName = MethodDescriptor.extractFullServiceName(method.getFullMethodName());
// Full method names are of the form: "full.serviceName/MethodName". We extract the last part.
String methodName = method.getFullMethodName().substring(serviceName.length() + 1);
return new GrpcMethod(serviceName, methodName, method.getType());
}
示例3: CronetClientStream
import io.grpc.MethodDescriptor; //导入方法依赖的package包/类
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,
method.isSafe());
this.url = Preconditions.checkNotNull(url, "url");
this.userAgent = Preconditions.checkNotNull(userAgent, "userAgent");
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);
}
示例4: methodCanBeRetried
import io.grpc.MethodDescriptor; //导入方法依赖的package包/类
private boolean methodCanBeRetried(MethodDescriptor<?, ?> methodDescriptor) {
return methodDescriptor.getType() == MethodType.UNARY
&& retriableMethods.containsKey(methodDescriptor);
}
示例5: serve
import io.grpc.MethodDescriptor; //导入方法依赖的package包/类
@Override
public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exception {
final HttpHeaders clientHeaders = req.headers();
final MediaType contentType = clientHeaders.contentType();
if (contentType == null) {
// All gRPC requests, whether framed or non-framed, must have content-type. If it's not sent, let
// the delegate return its usual error message.
return delegate().serve(ctx, req);
}
for (SerializationFormat format : GrpcSerializationFormats.values()) {
if (format.isAccepted(contentType)) {
// Framed request, so just delegate.
return delegate().serve(ctx, req);
}
}
String methodName = GrpcRequestUtil.determineMethod(ctx);
MethodDescriptor<?, ?> method = methodName != null ? methodsByName.get(methodName) : null;
if (method == null) {
// Unknown method, let the delegate return a usual error.
return delegate().serve(ctx, req);
}
if (method.getType() != MethodType.UNARY) {
return HttpResponse.of(HttpStatus.BAD_REQUEST,
MediaType.PLAIN_TEXT_UTF_8,
"Only unary methods can be used with non-framed requests.");
}
HttpHeaders grpcHeaders = HttpHeaders.copyOf(clientHeaders);
final MediaType framedContentType;
if (contentType.is(MediaType.PROTOBUF)) {
framedContentType = GrpcSerializationFormats.PROTO.mediaType();
} else if (contentType.is(MediaType.JSON_UTF_8)) {
framedContentType = GrpcSerializationFormats.JSON.mediaType();
} else {
return HttpResponse.of(HttpStatus.UNSUPPORTED_MEDIA_TYPE,
MediaType.PLAIN_TEXT_UTF_8,
"Unsupported media type. Only application/protobuf is supported.");
}
grpcHeaders.contentType(framedContentType);
if (grpcHeaders.get(GrpcHeaderNames.GRPC_ENCODING) != null) {
return HttpResponse.of(HttpStatus.UNSUPPORTED_MEDIA_TYPE,
MediaType.PLAIN_TEXT_UTF_8,
"gRPC encoding is not supported for non-framed requests.");
}
// All clients support no encoding, and we don't support gRPC encoding for non-framed requests, so just
// clear the header if it's present.
grpcHeaders.remove(GrpcHeaderNames.GRPC_ACCEPT_ENCODING);
final CompletableFuture<HttpResponse> responseFuture = new CompletableFuture<>();
final HttpResponse res = HttpResponse.from(responseFuture);
req.aggregate().whenCompleteAsync(
(clientRequest, t) -> {
if (t != null) {
responseFuture.completeExceptionally(t);
} else {
frameAndServe(ctx, grpcHeaders, clientRequest, responseFuture);
}
},
ctx.eventLoop());
return res;
}
示例6: ServiceDescriptor
import io.grpc.MethodDescriptor; //导入方法依赖的package包/类
public ServiceDescriptor(MethodDescriptor descriptor) {
this.methodType = descriptor.getType();
String fullMethodName = descriptor.getFullMethodName();
this.serviceName = formatServiceName(fullMethodName) + "." + formatMethodName(fullMethodName);
}