use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project flink by apache.
the class PubSubSubscriberFactoryForEmulator method getSubscriber.
@Override
public PubSubSubscriber getSubscriber(Credentials credentials) throws IOException {
ManagedChannel managedChannel = NettyChannelBuilder.forTarget(hostAndPort).usePlaintext().build();
PullRequest pullRequest = PullRequest.newBuilder().setMaxMessages(maxMessagesPerPull).setSubscription(projectSubscriptionName).build();
SubscriberGrpc.SubscriberBlockingStub stub = SubscriberGrpc.newBlockingStub(managedChannel);
return new BlockingGrpcPubSubSubscriber(projectSubscriptionName, managedChannel, stub, pullRequest, retries, timeout);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project pinpoint by naver.
the class GrpcDataSender method release.
protected void release() {
ExecutorUtils.shutdownExecutorService(name, executor);
final ManagedChannel managedChannel = this.managedChannel;
if (managedChannel != null) {
ManagedChannelUtils.shutdownManagedChannel(name, managedChannel);
}
final ChannelFactory channelFactory = this.channelFactory;
if (channelFactory != null) {
channelFactory.close();
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project pinpoint by naver.
the class DefaultChannelFactory method build.
@Override
public ManagedChannel build(String channelName, String host, int port) {
final NettyChannelBuilder channelBuilder = NettyChannelBuilder.forAddress(host, port);
channelBuilder.usePlaintext();
logger.info("ChannelType:{}", channelType.getSimpleName());
channelBuilder.channelType(channelType);
channelBuilder.eventLoopGroup(eventLoopGroup);
setupInternal(channelBuilder);
channelBuilder.defaultLoadBalancingPolicy(GrpcUtil.DEFAULT_LB_POLICY);
addHeader(channelBuilder);
addClientInterceptor(channelBuilder);
channelBuilder.executor(executorService);
if (nameResolverProvider != null) {
logger.info("Set nameResolverProvider {}. channelName={}, host={}, port={}", this.nameResolverProvider, channelName, host, port);
setNameResolverFactory(channelBuilder, this.nameResolverProvider);
}
setupClientOption(channelBuilder);
if (sslClientConfig.isEnable()) {
SslContext sslContext = null;
try {
sslContext = SslContextFactory.create(sslClientConfig);
} catch (SSLException e) {
throw new SecurityException(e);
}
channelBuilder.sslContext(sslContext);
channelBuilder.negotiationType(NegotiationType.TLS);
}
channelBuilder.maxTraceEvents(clientOption.getMaxTraceEvent());
final ManagedChannel channel = channelBuilder.build();
return channel;
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project instrumentation-java by census-instrumentation.
the class OcAgentMetricsExporterWorker method connect.
private void connect() {
ManagedChannelBuilder<?> channelBuilder;
if (useInsecure) {
channelBuilder = ManagedChannelBuilder.forTarget(endPoint).usePlaintext();
} else {
channelBuilder = NettyChannelBuilder.forTarget(endPoint).negotiationType(NegotiationType.TLS).sslContext(sslContext);
}
ManagedChannel channel = channelBuilder.build();
MetricsServiceGrpc.MetricsServiceStub stub = MetricsServiceGrpc.newStub(channel);
exportRpcHandler = OcAgentMetricsServiceExportRpcHandler.create(stub);
ExportMetricsServiceRequest.Builder builder = ExportMetricsServiceRequest.newBuilder().setNode(OcAgentNodeUtils.getNodeInfo(serviceName));
@Nullable Resource resourceProto = OcAgentNodeUtils.getAutoDetectedResourceProto();
if (resourceProto != null) {
builder.setResource(resourceProto);
}
exportRpcHandler.onExport(builder.build());
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project alluxio by Alluxio.
the class GrpcConnectionPool method acquireConnection.
/**
* Acquires and increases the ref-count for the {@link ManagedChannel}.
*
* @param channelKey the channel key
* @param conf the Alluxio configuration
* @return a {@link GrpcConnection}
*/
public GrpcConnection acquireConnection(GrpcChannelKey channelKey, AlluxioConfiguration conf) {
// Get a connection key.
GrpcConnectionKey connectionKey = getConnectionKey(channelKey, conf);
// Acquire connection.
CountingReference<ManagedChannel> connectionRef = mChannels.compute(connectionKey, (key, ref) -> {
boolean shutdownExistingConnection = false;
int existingRefCount = 0;
if (ref != null) {
// Connection exists, wait for health check.
if (waitForConnectionReady(ref.get(), conf)) {
LOG.debug("Acquiring an existing connection. ConnectionKey: {}. Ref-count: {}", key, ref.getRefCount());
return ref.reference();
} else {
// Health check failed.
shutdownExistingConnection = true;
}
}
// Existing connection should shut-down.
if (shutdownExistingConnection) {
// TODO(ggezer): Implement GrpcConnectionListener for receiving notification.
existingRefCount = ref.getRefCount();
LOG.debug("Shutting down an existing unhealthy connection. " + "ConnectionKey: {}. Ref-count: {}", key, existingRefCount);
// Shutdown the channel forcefully as it's already unhealthy.
shutdownManagedChannel(ref.get(), conf);
}
// Create a new managed channel.
LOG.debug("Creating a new managed channel. ConnectionKey: {}. Ref-count:{}", key, existingRefCount);
ManagedChannel managedChannel = createManagedChannel(channelKey, conf);
// Set map reference.
return new CountingReference(managedChannel, existingRefCount).reference();
});
// Wrap connection reference and the connection.
return new GrpcConnection(connectionKey, connectionRef.get(), conf);
}
Aggregations