本文整理汇总了Java中io.grpc.Channel.newCall方法的典型用法代码示例。如果您正苦于以下问题:Java Channel.newCall方法的具体用法?Java Channel.newCall怎么用?Java Channel.newCall使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.grpc.Channel
的用法示例。
在下文中一共展示了Channel.newCall方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: metadataInterceptor
import io.grpc.Channel; //导入方法依赖的package包/类
private ClientInterceptor metadataInterceptor() {
ClientInterceptor interceptor = new ClientInterceptor() {
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
final io.grpc.MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, final Channel next) {
return new ClientInterceptors.CheckedForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {
@Override
protected void checkedStart(Listener<RespT> responseListener, Metadata headers)
throws StatusException {
for (ConfigProto.CallMetadataEntry entry : callConfiguration.getMetadataList()) {
Metadata.Key<String> key = Metadata.Key.of(entry.getName(), Metadata.ASCII_STRING_MARSHALLER);
headers.put(key, entry.getValue());
}
delegate().start(responseListener, headers);
}
};
}
};
return interceptor;
}
示例2: interceptCall
import io.grpc.Channel; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
final MethodDescriptor<ReqT, RespT> method, CallOptions callOptions,
final Channel next) {
return new ClientInterceptors.CheckedForwardingClientCall<ReqT, RespT>(
next.newCall(method, callOptions)) {
@Override
protected void checkedStart(Listener<RespT> responseListener, Metadata headers)
throws StatusException {
Metadata cachedSaved;
URI uri = serviceUri(next, method);
synchronized (this) {
Map<String, List<String>> latestMetadata = getRequestMetadata(uri);
if (mLastMetadata == null || mLastMetadata != latestMetadata) {
mLastMetadata = latestMetadata;
mCached = toHeaders(mLastMetadata);
}
cachedSaved = mCached;
}
headers.merge(cachedSaved);
delegate().start(responseListener, headers);
}
};
}
示例3: interceptCall
import io.grpc.Channel; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(final MethodDescriptor<ReqT, RespT> method,
CallOptions callOptions, final Channel next) {
return new ClientInterceptors.CheckedForwardingClientCall<ReqT, RespT>(
next.newCall(method, callOptions)) {
@Override
protected void checkedStart(Listener<RespT> responseListener, Metadata headers)
throws StatusException {
Metadata cachedSaved;
URI uri = serviceUri(next, method);
synchronized (GoogleCredentialsInterceptor.this) {
Map<String, List<String>> latestMetadata = getRequestMetadata(uri);
if (mLastMetadata == null || mLastMetadata != latestMetadata) {
mLastMetadata = latestMetadata;
mCached = toHeaders(mLastMetadata);
}
cachedSaved = mCached;
}
headers.merge(cachedSaved);
delegate().start(responseListener, headers);
}
};
}
示例4: interceptCall
import io.grpc.Channel; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
return new SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
getToken(next).ifPresent(t -> headers.put(TOKEN, t));
super.start(new SimpleForwardingClientCallListener<RespT>(responseListener) {
@Override
public void onClose(Status status, Metadata trailers) {
if (isInvalidTokenError(status)) {
try {
refreshToken(next);
} catch (Exception e) {
// don't throw any error here.
// rpc will retry on expired auth token.
}
}
super.onClose(status, trailers);
}
}, headers);
}
};
}
示例5: createCloseableChannel
import io.grpc.Channel; //导入方法依赖的package包/类
/**
* Given a channel, create a CloseableChannel that invokces onClientClose when the close
* method is invoked.
*/
private static CloseableChannel createCloseableChannel(
final Channel channel, final ClientCloseHandler onClientClose) {
return new CloseableChannel() {
@Override
public void close() throws IOException {
onClientClose.close();
}
@Override
public <ReqT, RespT> Call<ReqT, RespT> newCall(
MethodDescriptor<ReqT, RespT> methodDescriptor) {
return channel.newCall(methodDescriptor);
}
};
}
示例6: interceptCall
import io.grpc.Channel; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
MethodDescriptor<ReqT,RespT> method, CallOptions callOptions, Channel next) {
LOGGER.info("Intercepted " + method.getFullMethodName());
ClientCall<ReqT, RespT> call = next.newCall(method, callOptions);
call = new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(call) {
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
if (apiKey != null && !apiKey.isEmpty()) {
LOGGER.info("Attaching API Key: " + apiKey);
headers.put(API_KEY_HEADER, apiKey);
}
super.start(responseListener, headers);
}
};
return call;
}
示例7: interceptCall
import io.grpc.Channel; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
MethodDescriptor<ReqT,RespT> method, CallOptions callOptions, Channel next) {
LOGGER.info("Intercepted " + method.getFullMethodName());
ClientCall<ReqT, RespT> call = next.newCall(method, callOptions);
call = new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(call) {
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
if (apiKey != null && !apiKey.isEmpty()) {
LOGGER.info("Attaching API Key: " + apiKey);
headers.put(API_KEY_HEADER, apiKey);
}
if (authToken != null && !authToken.isEmpty()) {
System.out.println("Attaching auth token");
headers.put(AUTHORIZATION_HEADER, "Bearer " + authToken);
}
super.start(responseListener, headers);
}
};
return call;
}
示例8: interceptCall
import io.grpc.Channel; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
MethodDescriptor<ReqT, RespT> method,
CallOptions callOptions,
Channel next) {
ClientInterceptor binlogInterceptor = getClientInterceptor(method.getFullMethodName());
if (binlogInterceptor == null) {
return next.newCall(method, callOptions);
} else {
return InternalClientInterceptors
.wrapClientInterceptor(
binlogInterceptor,
IDENTITY_MARSHALLER,
IDENTITY_MARSHALLER)
.interceptCall(method, callOptions, next);
}
}
示例9: interceptCall
import io.grpc.Channel; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
// New RPCs on client-side inherit the tag context from the current Context.
TagContext parentCtx = tagger.getCurrentTagContext();
final ClientCallTracer tracerFactory =
newClientCallTracer(parentCtx, method.getFullMethodName(),
recordStartedRpcs, recordFinishedRpcs);
ClientCall<ReqT, RespT> call =
next.newCall(method, callOptions.withStreamTracerFactory(tracerFactory));
return new SimpleForwardingClientCall<ReqT, RespT>(call) {
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
delegate().start(
new SimpleForwardingClientCallListener<RespT>(responseListener) {
@Override
public void onClose(Status status, Metadata trailers) {
tracerFactory.callEnded(status);
super.onClose(status, trailers);
}
},
headers);
}
};
}
示例10: interceptCall
import io.grpc.Channel; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
// New RPCs on client-side inherit the tracing context from the current Context.
// Safe usage of the unsafe trace API because CONTEXT_SPAN_KEY.get() returns the same value
// as Tracer.getCurrentSpan() except when no value available when the return value is null
// for the direct access and BlankSpan when Tracer API is used.
final ClientCallTracer tracerFactory = newClientCallTracer(CONTEXT_SPAN_KEY.get(), method);
ClientCall<ReqT, RespT> call =
next.newCall(method, callOptions.withStreamTracerFactory(tracerFactory));
return new SimpleForwardingClientCall<ReqT, RespT>(call) {
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
delegate().start(
new SimpleForwardingClientCallListener<RespT>(responseListener) {
@Override
public void onClose(io.grpc.Status status, Metadata trailers) {
tracerFactory.callEnded(status);
super.onClose(status, trailers);
}
},
headers);
}
};
}
示例11: wrapChannel_methodDescriptor
import io.grpc.Channel; //导入方法依赖的package包/类
@Test
public void wrapChannel_methodDescriptor() throws Exception {
final AtomicReference<MethodDescriptor<?, ?>> methodRef =
new AtomicReference<MethodDescriptor<?, ?>>();
Channel channel = new Channel() {
@Override
public <RequestT, ResponseT> ClientCall<RequestT, ResponseT> newCall(
MethodDescriptor<RequestT, ResponseT> method, CallOptions callOptions) {
methodRef.set(method);
return new NoopClientCall<RequestT, ResponseT>();
}
@Override
public String authority() {
throw new UnsupportedOperationException();
}
};
Channel wChannel = binlogProvider.wrapChannel(channel);
ClientCall<String, Integer> ignoredClientCall = wChannel.newCall(method, CallOptions.DEFAULT);
validateWrappedMethod(methodRef.get());
}
示例12: interceptCall
import io.grpc.Channel; //导入方法依赖的package包/类
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method,
CallOptions callOptions, Channel next) {
Integer timeout = callOptions.getOption(DEADLINE_KEY);
CallOptions callOptionsWithTimeout = null != timeout && timeout > 0 ?
callOptions.withDeadlineAfter(timeout, TimeUnit.MILLISECONDS) : callOptions;
return next.newCall(method, callOptionsWithTimeout);
}
示例13: interceptCall
import io.grpc.Channel; //导入方法依赖的package包/类
@Override
public <R, S> ClientCall<R, S> interceptCall(
MethodDescriptor<R, S> methodDescriptor, CallOptions callOptions, Channel channel) {
ClientMetrics metrics = clientMetricsFactory.createMetricsForMethod(methodDescriptor);
return new MonitoringClientCall<>(
channel.newCall(methodDescriptor, callOptions),
metrics,
GrpcMethod.of(methodDescriptor),
configuration,
clock);
}
示例14: listenableAsyncCall
import io.grpc.Channel; //导入方法依赖的package包/类
protected static <T, V> ListenableFuture<V> listenableAsyncCall(
Channel channel,
MethodDescriptor<T, V> method, T request) {
Call<T, V> call = channel.newCall(method);
AsyncUnaryOperationObserver<V> observer = new AsyncUnaryOperationObserver<>();
Calls.asyncUnaryCall(call, request, observer);
return observer.getCompletionFuture();
}
示例15: interceptCall
import io.grpc.Channel; //导入方法依赖的package包/类
@Override
public <RequestT, ResponseT> ClientCall<RequestT, ResponseT> interceptCall(
MethodDescriptor<RequestT, ResponseT> method, CallOptions callOptions, Channel next) {
assertThat(callOptions.getCredentials()).isEqualTo(credentials);
// Remove the call credentials to allow testing with dummy ones.
return next.newCall(method, callOptions.withCallCredentials(null));
}