Search in sources :

Example 6 with Channel

use of io.grpc.Channel in project java-docs-samples by GoogleCloudPlatform.

the class BookstoreClient method createBookstoreStub.

static BookstoreGrpc.BookstoreBlockingStub createBookstoreStub(String address, String apiKey, String authToken) {
    Channel channel = ManagedChannelBuilder.forTarget(address).usePlaintext(true).build();
    channel = ClientInterceptors.intercept(channel, new Interceptor(apiKey, authToken));
    return BookstoreGrpc.newBlockingStub(channel);
}
Also used : Channel(io.grpc.Channel) ClientInterceptor(io.grpc.ClientInterceptor)

Example 7 with Channel

use of io.grpc.Channel in project dble by actiontech.

the class ClusterUcoreSender method init.

public static void init() {
    Channel channel = ManagedChannelBuilder.forAddress(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_PLUGINS_IP), Integer.parseInt(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
    stub = UcoreGrpc.newBlockingStub(channel);
}
Also used : Channel(io.grpc.Channel)

Example 8 with Channel

use of io.grpc.Channel in project dble by actiontech.

the class AlarmAppender method refreshConfig.

/**
 * refresh config of alarm address and re create the stub
 */
public static void refreshConfig() {
    try {
        AlarmConfig config = DbleServer.getInstance().getConfig().getAlarm();
        if (config != null) {
            // put the old config into  _old
            grpcUrlOld = grpcUrl;
            serverIdOld = serverId;
            alertComponentIdOld = alertComponentId;
            portOld = port;
            grpcUrlOld = grpcUrl;
            grpcLevelOld = grpcLevel;
            grpcLevel = "error".equalsIgnoreCase(config.getLevel()) ? 200 : 300;
            serverId = config.getServerId();
            port = Integer.parseInt(config.getPort());
            grpcUrl = config.getUrl();
            alertComponentId = config.getComponentId();
            if (port != portOld || !grpcUrlOld.equals(grpcUrl)) {
                Channel channel = ManagedChannelBuilder.forAddress(grpcUrl, port).usePlaintext(true).build();
                stub = UcoreGrpc.newBlockingStub(channel);
            }
        } else {
            stub = null;
        }
    } catch (Exception e) {
        // config not ready yeat
        return;
    }
}
Also used : Channel(io.grpc.Channel) AlarmConfig(com.actiontech.dble.config.model.AlarmConfig)

Example 9 with Channel

use of io.grpc.Channel in project dble by actiontech.

the class AlarmAppender method rollbackConfig.

/**
 * if the config is rollback the config of dbleAppender should be rollback too
 */
public static void rollbackConfig() {
    if (stub == null && (grpcUrlOld == null && "".equals(grpcUrlOld))) {
        grpcUrl = grpcUrlOld;
        serverId = serverIdOld;
        alertComponentId = alertComponentIdOld;
        port = portOld;
        grpcUrl = grpcUrlOld;
        grpcLevel = grpcLevelOld;
        return;
    } else {
        grpcUrl = grpcUrlOld;
        serverId = serverIdOld;
        alertComponentId = alertComponentIdOld;
        port = portOld;
        grpcUrl = grpcUrlOld;
        try {
            Channel channel = ManagedChannelBuilder.forAddress(grpcUrl, port).usePlaintext(true).build();
            stub = UcoreGrpc.newBlockingStub(channel);
        } catch (Exception e) {
            return;
        }
    }
}
Also used : Channel(io.grpc.Channel)

Example 10 with Channel

use of io.grpc.Channel in project dble by actiontech.

the class UcoreClearKeyListener method init.

public void init() {
    Channel channel = ManagedChannelBuilder.forAddress(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_PLUGINS_IP), Integer.parseInt(UcoreConfig.getInstance().getValue(ClusterParamCfg.CLUSTER_PLUGINS_PORT))).usePlaintext(true).build();
    stub = UcoreGrpc.newBlockingStub(channel);
}
Also used : Channel(io.grpc.Channel)

Aggregations

Channel (io.grpc.Channel)60 CallOptions (io.grpc.CallOptions)37 Test (org.junit.Test)33 Metadata (io.grpc.Metadata)25 MethodDescriptor (io.grpc.MethodDescriptor)20 ClientInterceptor (io.grpc.ClientInterceptor)19 ManagedChannel (io.grpc.ManagedChannel)17 ClientCall (io.grpc.ClientCall)14 SocketAddress (java.net.SocketAddress)8 ByteString (com.google.protobuf.ByteString)7 SimpleForwardingClientCall (io.grpc.ForwardingClientCall.SimpleForwardingClientCall)7 NoopClientCall (io.grpc.internal.NoopClientCall)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Duration (com.google.protobuf.Duration)5 ChannelLogger (io.grpc.ChannelLogger)5 Status (io.grpc.Status)5 ClientStreamTracer (io.grpc.ClientStreamTracer)4 ForwardingClientCall (io.grpc.ForwardingClientCall)4 SimpleForwardingClientCallListener (io.grpc.ForwardingClientCallListener.SimpleForwardingClientCallListener)4 Subchannel (io.grpc.LoadBalancer.Subchannel)4