本文整理汇总了Java中io.grpc.netty.NegotiationType类的典型用法代码示例。如果您正苦于以下问题:Java NegotiationType类的具体用法?Java NegotiationType怎么用?Java NegotiationType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NegotiationType类属于io.grpc.netty包,在下文中一共展示了NegotiationType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectPlugin
import io.grpc.netty.NegotiationType; //导入依赖的package包/类
public void connectPlugin(String host, int port) {
ManagedChannel channel = NettyChannelBuilder.forAddress(host, port)
.negotiationType(NegotiationType.PLAINTEXT) // TODO: gRPC encryption
.keepAliveTime(1, TimeUnit.MINUTES)
.keepAliveTimeout(5, TimeUnit.SECONDS)
.directExecutor()
.channelType(EpollSocketChannel.class)
.eventLoopGroup(new EpollEventLoopGroup())
.build();
PluginManagerGrpc.PluginManagerBlockingStub blocking = PluginManagerGrpc.newBlockingStub(channel);
PluginManagerGrpc.PluginManagerStub async = PluginManagerGrpc.newStub(channel);
ServiceConnection connection = ServiceConnection.builder()
.channel(channel)
.blockingStub(blocking)
.asyncStub(async)
.build();
this.pluginConnections.put(PLUGIN_MANAGER, connection);
}
示例2: getGenomicsManagedChannel
import io.grpc.netty.NegotiationType; //导入依赖的package包/类
private static ManagedChannel getGenomicsManagedChannel(List<ClientInterceptor> interceptors)
throws SSLException {
// Java 8's implementation of GCM ciphers is extremely slow. Therefore we disable
// them here.
List<String> defaultCiphers = GrpcSslContexts.forClient().ciphers(null).build().cipherSuites();
List<String> performantCiphers = new ArrayList<>();
for (String cipher : defaultCiphers) {
if (!cipher.contains("GCM")) {
performantCiphers.add(cipher);
}
}
return NettyChannelBuilder.forAddress(GENOMICS_ENDPOINT, 443)
.negotiationType(NegotiationType.TLS)
.sslContext(GrpcSslContexts.forClient().ciphers(performantCiphers).build())
.intercept(interceptors)
.build();
}
示例3: MemberServiceImpl
import io.grpc.netty.NegotiationType; //导入依赖的package包/类
public MemberServiceImpl(String host, int port, Crypto crypto) {
Preconditions.checkNotNull(host);
Preconditions.checkNotNull(port);
InetAddress address = null;
try {
address = InetAddress.getByName(host);
} catch (UnknownHostException e) {
logger.error("Create member service failed by unknown host exception", e);
Throwables.propagate(e);
}
final Channel channel = NettyChannelBuilder
.forAddress(new InetSocketAddress(address, port))
.negotiationType(NegotiationType.PLAINTEXT)
.build();
initializeStubs(channel);
this.crypto = crypto;
}
示例4: newClient
import io.grpc.netty.NegotiationType; //导入依赖的package包/类
@Override
public PubsubClient newClient(
@Nullable String timestampAttribute, @Nullable String idAttribute, PubsubOptions options)
throws IOException {
ManagedChannel channel = NettyChannelBuilder
.forAddress(PUBSUB_ADDRESS, PUBSUB_PORT)
.negotiationType(NegotiationType.TLS)
.sslContext(GrpcSslContexts.forClient().ciphers(null).build())
.build();
return new PubsubGrpcClient(timestampAttribute,
idAttribute,
DEFAULT_TIMEOUT_S,
channel,
options.getGcpCredential());
}
示例5: newClientChannel
import io.grpc.netty.NegotiationType; //导入依赖的package包/类
private ManagedChannel newClientChannel() throws CertificateException, IOException {
File clientCertChainFile = TestUtils.loadCert("client.pem");
File clientPrivateKeyFile = TestUtils.loadCert("client.key");
X509Certificate[] clientTrustedCaCerts = {
TestUtils.loadX509Cert("ca.pem")
};
SslContext sslContext =
GrpcSslContexts.forClient()
.keyManager(clientCertChainFile, clientPrivateKeyFile)
.trustManager(clientTrustedCaCerts)
.build();
return NettyChannelBuilder.forAddress("localhost", server.getPort())
.overrideAuthority(TestUtils.TEST_SERVER_HOST)
.negotiationType(NegotiationType.TLS)
.sslContext(sslContext)
.build();
}
示例6: newOkhttpClientChannel
import io.grpc.netty.NegotiationType; //导入依赖的package包/类
private static OkHttpChannelBuilder newOkhttpClientChannel(
SocketAddress address, boolean tls, boolean testca, @Nullable String authorityOverride) {
InetSocketAddress addr = (InetSocketAddress) address;
OkHttpChannelBuilder builder =
OkHttpChannelBuilder.forAddress(addr.getHostName(), addr.getPort());
if (tls) {
builder.negotiationType(io.grpc.okhttp.NegotiationType.TLS);
SSLSocketFactory factory;
if (testca) {
builder.overrideAuthority(
GrpcUtil.authorityFromHostAndPort(authorityOverride, addr.getPort()));
try {
factory = TestUtils.newSslSocketFactoryForCa(
Platform.get().getProvider(),
TestUtils.loadCert("ca.pem"));
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
}
builder.sslSocketFactory(factory);
} else {
builder.negotiationType(io.grpc.okhttp.NegotiationType.PLAINTEXT);
}
return builder;
}
示例7: MyServiceClient
import io.grpc.netty.NegotiationType; //导入依赖的package包/类
/**
* Constructor for the client.
* @param host The host to connect to for the server
* @param port The port to connect to on the host server
*/
public MyServiceClient(String host, int port) {
InetAddress address;
try {
address = InetAddress.getByName(host);
} catch (UnknownHostException e) {
throw new RuntimeException(e);
}
managedChannel = NettyChannelBuilder.forAddress(new InetSocketAddress(address,port))
.flowControlWindow(65 * 1024)
.negotiationType(NegotiationType.PLAINTEXT).build();
simpleBlockingStub = SimpleGrpc.newBlockingStub(managedChannel);
lessSimpleBlockingStub = LessSimpleGrpc.newBlockingStub(managedChannel);
}
示例8: initCache
import io.grpc.netty.NegotiationType; //导入依赖的package包/类
private static LoadingCache<UserAuth, String> initCache() {
try {
currentAuth = ApprcHolder.get().currentAuth();
URI uri = new URI(currentAuth.getApiserver());
logger.info(String.format("Connecting to apiserver: %s host: %s port: %s",
currentAuth.getApiserver(), uri.getHost(), uri.getPort()));
NettyChannelBuilder builder = NettyChannelBuilder
.forAddress(uri.getHost(), uri.getPort())
.nameResolverFactory(new DnsNameResolverProvider());
if (useTLS(currentAuth)) {
File trustCertCollectionFile = null;
builder
.sslContext(GrpcSslContexts.forClient().trustManager(trustCertCollectionFile).build())
.negotiationType(NegotiationType.TLS);
} else {
builder.negotiationType(NegotiationType.PLAINTEXT);
}
channel = builder.build();
return CacheBuilder.newBuilder()
.expireAfterAccess(DESCRIPTOR.getAuthCacheTtl(), TimeUnit.SECONDS)
.build(
new CacheLoader<UserAuth, String>() {
@Override
public String load(UserAuth key) throws Exception {
if (isToken(key.getSecret())) {
return checkToken(key.getUsername(),
key.getSecret().substring(BEARER_PREFIX.length()));
}
return checkPassword(key.getUsername(), key.getSecret());
}
}
);
} catch (URISyntaxException | SSLException e) {
logger.log(Level.SEVERE, e.getMessage());
}
return null;
}
示例9: addConnection
import io.grpc.netty.NegotiationType; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void addConnection(ServiceType serviceType, String host, int port) {
ManagedChannel channel = NettyChannelBuilder.forAddress(host, port)
.negotiationType(NegotiationType.PLAINTEXT) // TODO: gRPC encryption
.keepAliveTime(1, TimeUnit.MINUTES)
.keepAliveTimeout(5, TimeUnit.SECONDS)
.directExecutor()
.channelType(EpollSocketChannel.class)
.eventLoopGroup(new EpollEventLoopGroup())
.build();
AbstractStub blocking;
AbstractStub async;
switch (serviceType) {
case WORLD: {
blocking = WorldServiceGrpc.newBlockingStub(channel);
async = WorldServiceGrpc.newStub(channel);
break;
}
case PLUGIN_MANAGER: {
blocking = PluginManagerGrpc.newBlockingStub(channel);
async = PluginManagerGrpc.newStub(channel);
break;
}
default: {
throw new RuntimeException("Service type not handled: " + serviceType.name());
}
}
ServiceConnection connection = ServiceConnection.builder()
.channel(channel)
.blockingStub(blocking)
.asyncStub(async)
.build();
this.connections.put(serviceType, connection);
}
示例10: createChannel
import io.grpc.netty.NegotiationType; //导入依赖的package包/类
private ManagedChannel createChannel(URI uri) {
log.debug("Creating channel for {}", uri);
int port = GrpcRemoteServiceServer.DEFAULT_LISTEN_PORT;
if (uri.getPort() != -1) {
port = uri.getPort();
}
return NettyChannelBuilder.forAddress(uri.getHost(), port)
.negotiationType(NegotiationType.PLAINTEXT)
.build();
}
示例11: createChannelBuilder
import io.grpc.netty.NegotiationType; //导入依赖的package包/类
private NettyChannelBuilder createChannelBuilder(HostAndPort endpoint) {
if (!callConfiguration.getUseTls()) {
return NettyChannelBuilder.forAddress(endpoint.getHostText(), endpoint.getPort())
.negotiationType(NegotiationType.PLAINTEXT);
} else {
return NettyChannelBuilder.forAddress(endpoint.getHostText(), endpoint.getPort())
.sslContext(createSslContext())
.negotiationType(NegotiationType.TLS)
.intercept(metadataInterceptor());
}
}
示例12: GRPCClient
import io.grpc.netty.NegotiationType; //导入依赖的package包/类
public GRPCClient(String host, int port, int observerPort) {
log.debug("Trying to connect to GRPC host:port={}:{}, host:observerPort={}:{}, ", host, port, observerPort);
ManagedChannel channel = NettyChannelBuilder.forAddress(host, port).negotiationType(NegotiationType.PLAINTEXT).build();
ManagedChannel observerChannel = NettyChannelBuilder.forAddress(host, observerPort).negotiationType(NegotiationType.PLAINTEXT).build();
pbs = PeerGrpc.newBlockingStub(channel);
obs = OpenchainGrpc.newBlockingStub(channel);
observer = new GRPCObserver(observerChannel);
observer.connect();
}
示例13: getChannel
import io.grpc.netty.NegotiationType; //导入依赖的package包/类
/** Return {@link io.grpc.Channel} which is used by Cloud Pub/Sub gRPC API's. */
public static Channel getChannel() throws IOException {
ManagedChannel channelImpl =
NettyChannelBuilder.forAddress(ENDPOINT, 443).negotiationType(NegotiationType.TLS).build();
final ClientAuthInterceptor interceptor =
new ClientAuthInterceptor(
GoogleCredentials.getApplicationDefault().createScoped(CPS_SCOPE),
Executors.newCachedThreadPool());
return ClientInterceptors.intercept(channelImpl, interceptor);
}
示例14: GRPCClient
import io.grpc.netty.NegotiationType; //导入依赖的package包/类
public GRPCClient(String host, int port, int observerPort) {
log.debug("Trying to connect to GRPC host:port={}:{}, host:observerPort={}:{}, ", host, port, observerPort);
ManagedChannel channel = NettyChannelBuilder.forAddress(host, port).negotiationType(NegotiationType.PLAINTEXT).build();
ManagedChannel observerChannel = NettyChannelBuilder.forAddress(host, observerPort).negotiationType(NegotiationType.PLAINTEXT).build();
dbs = DevopsGrpc.newBlockingStub(channel);
obs = OpenchainGrpc.newBlockingStub(channel);
observer = new GRPCObserver(observerChannel);
observer.connect();
}
示例15: main
import io.grpc.netty.NegotiationType; //导入依赖的package包/类
public static void main(final String[] args) throws Exception {
if (args.length == 0) {
System.err.println("Please specify your project name.");
System.exit(1);
}
final String project = args[0];
ManagedChannelImpl channelImpl = NettyChannelBuilder
.forAddress("pubsub.googleapis.com", 443)
.negotiationType(NegotiationType.TLS)
.build();
GoogleCredentials creds = GoogleCredentials.getApplicationDefault();
// Down-scope the credential to just the scopes required by the service
creds = creds.createScoped(Arrays.asList("https://www.googleapis.com/auth/pubsub"));
// Intercept the channel to bind the credential
ExecutorService executor = Executors.newSingleThreadExecutor();
ClientAuthInterceptor interceptor = new ClientAuthInterceptor(creds, executor);
Channel channel = ClientInterceptors.intercept(channelImpl, interceptor);
// Create a stub using the channel that has the bound credential
PublisherGrpc.PublisherBlockingStub publisherStub = PublisherGrpc.newBlockingStub(channel);
ListTopicsRequest request = ListTopicsRequest.newBuilder()
.setPageSize(10)
.setProject("projects/" + project)
.build();
ListTopicsResponse resp = publisherStub.listTopics(request);
System.out.println("Found " + resp.getTopicsCount() + " topics.");
for (Topic topic : resp.getTopicsList()) {
System.out.println(topic.getName());
}
}