Notification for DeviceStateService about created Device
This commit is contained in:
		
							parent
							
								
									50bfe1ffc8
								
							
						
					
					
						commit
						622300181f
					
				@ -32,6 +32,7 @@ import org.thingsboard.server.actors.rpc.RpcManagerActor;
 | 
			
		||||
import org.thingsboard.server.actors.rpc.RpcSessionCreateRequestMsg;
 | 
			
		||||
import org.thingsboard.server.actors.session.SessionManagerActor;
 | 
			
		||||
import org.thingsboard.server.actors.stats.StatsActor;
 | 
			
		||||
import org.thingsboard.server.common.data.Device;
 | 
			
		||||
import org.thingsboard.server.common.data.id.DeviceId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.EntityId;
 | 
			
		||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
			
		||||
@ -48,6 +49,7 @@ import org.thingsboard.server.gen.cluster.ClusterAPIProtos;
 | 
			
		||||
import org.thingsboard.server.service.cluster.discovery.DiscoveryService;
 | 
			
		||||
import org.thingsboard.server.service.cluster.discovery.ServerInstance;
 | 
			
		||||
import org.thingsboard.server.service.cluster.rpc.ClusterRpcService;
 | 
			
		||||
import org.thingsboard.server.service.state.DeviceStateService;
 | 
			
		||||
import scala.concurrent.Await;
 | 
			
		||||
import scala.concurrent.Future;
 | 
			
		||||
import scala.concurrent.duration.Duration;
 | 
			
		||||
@ -81,6 +83,9 @@ public class DefaultActorService implements ActorService {
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private DiscoveryService discoveryService;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private DeviceStateService deviceStateService;
 | 
			
		||||
 | 
			
		||||
    private ActorSystem system;
 | 
			
		||||
 | 
			
		||||
    private ActorRef appActor;
 | 
			
		||||
@ -199,7 +204,7 @@ public class DefaultActorService implements ActorService {
 | 
			
		||||
    public void onReceivedMsg(ServerAddress source, ClusterAPIProtos.ClusterMessage msg) {
 | 
			
		||||
        ServerAddress serverAddress = new ServerAddress(source.getHost(), source.getPort());
 | 
			
		||||
        log.info("Received msg [{}] from [{}]", msg.getMessageType().name(), serverAddress);
 | 
			
		||||
        if(log.isDebugEnabled()){
 | 
			
		||||
        if (log.isDebugEnabled()) {
 | 
			
		||||
            log.info("MSG: ", msg);
 | 
			
		||||
        }
 | 
			
		||||
        switch (msg.getMessageType()) {
 | 
			
		||||
@ -254,4 +259,8 @@ public class DefaultActorService implements ActorService {
 | 
			
		||||
        rpcManagerActor.tell(msg, ActorRef.noSender());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onDeviceAdded(Device device) {
 | 
			
		||||
        deviceStateService.onDeviceAdded(device);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -15,11 +15,13 @@
 | 
			
		||||
 */
 | 
			
		||||
package org.thingsboard.server.common.transport;
 | 
			
		||||
 | 
			
		||||
import org.thingsboard.server.common.data.security.DeviceCredentialsFilter;
 | 
			
		||||
import org.thingsboard.server.common.data.Device;
 | 
			
		||||
import org.thingsboard.server.common.msg.aware.SessionAwareMsg;
 | 
			
		||||
 | 
			
		||||
public interface SessionMsgProcessor {
 | 
			
		||||
 | 
			
		||||
    void process(SessionAwareMsg msg);
 | 
			
		||||
 | 
			
		||||
    void onDeviceAdded(Device device);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -130,6 +130,13 @@ public class CoapServerTest {
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                @Override
 | 
			
		||||
                public void onDeviceAdded(Device device) {
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -92,6 +92,7 @@ public class GatewaySessionCtx {
 | 
			
		||||
                device.setType(deviceType);
 | 
			
		||||
                device = deviceService.saveDevice(device);
 | 
			
		||||
                relationService.saveRelationAsync(new EntityRelation(gateway.getId(), device.getId(), "Created"));
 | 
			
		||||
                processor.onDeviceAdded(device);
 | 
			
		||||
            }
 | 
			
		||||
            GatewayDeviceSessionCtx ctx = new GatewayDeviceSessionCtx(this, device);
 | 
			
		||||
            devices.put(deviceName, ctx);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user