Search in sources :

Example 1 with GrpcSession

use of org.thingsboard.server.service.cluster.rpc.GrpcSession in project thingsboard by thingsboard.

the class RpcSessionActor method initSession.

private void initSession(RpcSessionCreateRequestMsg msg) {
    log.info("[{}] Initializing session", context().self());
    ServerAddress remoteServer = msg.getRemoteAddress();
    listener = new BasicRpcSessionListener(systemContext, context().parent(), context().self());
    if (msg.getRemoteAddress() == null) {
        // Server session
        session = new GrpcSession(listener);
        session.setOutputStream(msg.getResponseObserver());
        session.initInputStream();
        session.initOutputStream();
        systemContext.getRpcService().onSessionCreated(msg.getMsgUid(), session.getInputStream());
    } else {
        // Client session
        Channel channel = ManagedChannelBuilder.forAddress(remoteServer.getHost(), remoteServer.getPort()).usePlaintext(true).build();
        session = new GrpcSession(remoteServer, listener);
        session.initInputStream();
        ClusterRpcServiceGrpc.ClusterRpcServiceStub stub = ClusterRpcServiceGrpc.newStub(channel);
        StreamObserver<ClusterAPIProtos.ToRpcServerMessage> outputStream = stub.handlePluginMsgs(session.getInputStream());
        session.setOutputStream(outputStream);
        session.initOutputStream();
        outputStream.onNext(toConnectMsg());
    }
}
Also used : GrpcSession(org.thingsboard.server.service.cluster.rpc.GrpcSession) Channel(io.grpc.Channel) ServerAddress(org.thingsboard.server.common.msg.cluster.ServerAddress) ClusterRpcServiceGrpc(org.thingsboard.server.gen.cluster.ClusterRpcServiceGrpc)

Aggregations

Channel (io.grpc.Channel)1 ServerAddress (org.thingsboard.server.common.msg.cluster.ServerAddress)1 ClusterRpcServiceGrpc (org.thingsboard.server.gen.cluster.ClusterRpcServiceGrpc)1 GrpcSession (org.thingsboard.server.service.cluster.rpc.GrpcSession)1