Search in sources :

Example 11 with ServerAddress

use of org.thingsboard.server.common.msg.cluster.ServerAddress 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

ServerAddress (org.thingsboard.server.common.msg.cluster.ServerAddress)11 Subscription (org.thingsboard.server.extensions.core.plugin.telemetry.sub.Subscription)4 Channel (io.grpc.Channel)1 java.util (java.util)1 TimeoutException (java.util.concurrent.TimeoutException)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Setter (lombok.Setter)1 Slf4j (lombok.extern.slf4j.Slf4j)1 StringUtils (org.springframework.util.StringUtils)1 DataConstants (org.thingsboard.server.common.data.DataConstants)1 DeviceId (org.thingsboard.server.common.data.id.DeviceId)1 EntityId (org.thingsboard.server.common.data.id.EntityId)1 SessionId (org.thingsboard.server.common.data.id.SessionId)1 org.thingsboard.server.common.data.kv (org.thingsboard.server.common.data.kv)1 FromDeviceMsg (org.thingsboard.server.common.msg.session.FromDeviceMsg)1 DeviceCredentialsUpdateNotificationMsg (org.thingsboard.server.extensions.api.device.DeviceCredentialsUpdateNotificationMsg)1 DeviceNameOrTypeUpdateMsg (org.thingsboard.server.extensions.api.device.DeviceNameOrTypeUpdateMsg)1 PluginCallback (org.thingsboard.server.extensions.api.plugins.PluginCallback)1 PluginContext (org.thingsboard.server.extensions.api.plugins.PluginContext)1