Package org.openremote.manager.mqtt
Class ConnectionMonitorHandler
java.lang.Object
org.openremote.manager.mqtt.MQTTHandler
org.openremote.manager.mqtt.ConnectionMonitorHandler
This
MQTTHandler just monitors connected users and handles updating of
Attributes with MetaItemType.USER_CONNECTED
MetaItem. It doesn't handle any publishes or subscriptions.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AssetProcessingServiceprotected AssetStorageServiceprotected ExecutorServiceprotected GatewayServiceprotected static final Loggerprotected MQTTBrokerServiceprotected org.openremote.container.persistence.PersistenceServiceprotected ConcurrentMap<String, Set<org.openremote.model.attribute.AttributeRef>> Fields inherited from class org.openremote.manager.mqtt.MQTTHandler
clientEventService, clientSession, identityProvider, isKeycloak, messageBrokerService, producer, timerService, TOKEN_MULTI_LEVEL_WILDCARD, TOKEN_SINGLE_LEVEL_WILDCARD -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddSessionAttribute(String userID, org.openremote.model.attribute.AttributeRef attributeRef) protected voidaddSessionAttributes(String realm, List<org.openremote.model.util.Pair<String, org.openremote.model.attribute.Attribute<?>>> assetIdsAttrs) protected static booleanattributeMatches(org.openremote.model.attribute.Attribute<?> attr) booleancanPublish(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, org.keycloak.KeycloakSecurityContext securityContext, Topic topic) Called to authorise a publish ifMQTTHandler.handlesTopic(org.openremote.manager.mqtt.Topic)returned true; should return true if the publish is allowed otherwise return false.booleancanSubscribe(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, org.keycloak.KeycloakSecurityContext securityContext, Topic topic) Called to authorise a subscription ifMQTTHandler.handlesTopic(org.openremote.manager.mqtt.Topic)returned true; should return true if the subscription is allowed otherwise return false.protected LoggerGet the set of topics this handler wants to subscribe to for incoming publish messages; messages that match these topics will be passed toMQTTHandler.onPublish(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection, org.openremote.manager.mqtt.Topic, io.netty.buffer.ByteBuf).getUserIDAndAttributeRefs(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection) voidinit(org.openremote.model.Container container, org.apache.activemq.artemis.core.config.Configuration serverConfiguration) Called when the system starts to allow for initialisation.voidonConnect(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection) Will be called when any client connects; if returns false then subsequent handlers will not be calledvoidonConnectionAuthenticated(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection) Called when an existingRemotingConnectionis authenticated sometime after initially connecting (seeUserAssetProvisioningMQTTHandler); the authenticatedSubjectcan be retrieved usingRemotingConnection.getSubject()voidonConnectionLost(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection) Will be called when any client loses connectionvoidonDisconnect(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection) Will be called when any client disconnectsvoidonPublish(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, Topic topic, io.netty.buffer.ByteBuf body) Called to handle publish ifMQTTHandler.canPublish(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection, org.keycloak.KeycloakSecurityContext, org.openremote.manager.mqtt.Topic)returned true.voidonSubscribe(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, Topic topic) Called to handle subscribe ifMQTTHandler.canSubscribe(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection, org.keycloak.KeycloakSecurityContext, org.openremote.manager.mqtt.Topic)returned true.voidonUnsubscribe(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, Topic topic) Called to handle unsubscribe ifMQTTHandler.handlesTopic(org.openremote.manager.mqtt.Topic)returned true.protected voidremoveSessionAttribute(String userID, org.openremote.model.attribute.AttributeRef attributeRef) voidstart(org.openremote.model.Container container) Called when the system starts to allow for initialisation.voidstop()Called when the system stops to allow for any cleanup.protected booleantopicMatches(Topic topic) Indicates if this handler will handle the specified topic; independent of whether it is a publish or subscribe.protected voidupdateUserConnectedStatus(String userID, Collection<org.openremote.model.attribute.AttributeRef> attributeRefs, boolean connected) Methods inherited from class org.openremote.manager.mqtt.MQTTHandler
addPublishConsumer, addPublishTopicServerConfiguration, checkCanPublish, checkCanSubscribe, getAuthContextFromConnection, getAuthContextFromSecurityContext, getName, getPriority, getPublishTopicAddressSettings, getSecurityContextFromSubject, getSubjectFromConnection, handlesTopic, onUserAssetLinksChanged, publishMessage, topicClientID, topicClientIdMatches, topicRealm, topicRealmAllowed, topicTokenCountGreaterThan, topicTokenIndexToString
-
Field Details
-
LOG
-
mqttBrokerService
-
executorService
-
assetStorageService
-
assetProcessingService
-
gatewayService
-
persistenceService
protected org.openremote.container.persistence.PersistenceService persistenceService -
userIDAttributeRefs
protected ConcurrentMap<String,Set<org.openremote.model.attribute.AttributeRef>> userIDAttributeRefs
-
-
Constructor Details
-
ConnectionMonitorHandler
public ConnectionMonitorHandler()
-
-
Method Details
-
init
public void init(org.openremote.model.Container container, org.apache.activemq.artemis.core.config.Configuration serverConfiguration) throws Exception Description copied from class:MQTTHandlerCalled when the system starts to allow for initialisation.- Overrides:
initin classMQTTHandler- Throws:
Exception
-
start
Description copied from class:MQTTHandlerCalled when the system starts to allow for initialisation.- Overrides:
startin classMQTTHandler- Throws:
Exception
-
stop
Description copied from class:MQTTHandlerCalled when the system stops to allow for any cleanup.- Overrides:
stopin classMQTTHandler- Throws:
Exception
-
onConnect
public void onConnect(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection) Description copied from class:MQTTHandlerWill be called when any client connects; if returns false then subsequent handlers will not be called- Overrides:
onConnectin classMQTTHandler
-
onDisconnect
public void onDisconnect(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection) Description copied from class:MQTTHandlerWill be called when any client disconnects- Overrides:
onDisconnectin classMQTTHandler
-
onConnectionLost
public void onConnectionLost(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection) Description copied from class:MQTTHandlerWill be called when any client loses connection- Overrides:
onConnectionLostin classMQTTHandler
-
onConnectionAuthenticated
public void onConnectionAuthenticated(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection) Description copied from class:MQTTHandlerCalled when an existingRemotingConnectionis authenticated sometime after initially connecting (seeUserAssetProvisioningMQTTHandler); the authenticatedSubjectcan be retrieved usingRemotingConnection.getSubject()- Overrides:
onConnectionAuthenticatedin classMQTTHandler
-
topicMatches
Description copied from class:MQTTHandlerIndicates if this handler will handle the specified topic; independent of whether it is a publish or subscribe. Should generally check the third token onwards unlessMQTTHandler.handlesTopic(org.openremote.manager.mqtt.Topic)has been overridden.- Specified by:
topicMatchesin classMQTTHandler
-
getLogger
- Specified by:
getLoggerin classMQTTHandler
-
canSubscribe
public boolean canSubscribe(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, org.keycloak.KeycloakSecurityContext securityContext, Topic topic) Description copied from class:MQTTHandlerCalled to authorise a subscription ifMQTTHandler.handlesTopic(org.openremote.manager.mqtt.Topic)returned true; should return true if the subscription is allowed otherwise return false.- Specified by:
canSubscribein classMQTTHandler
-
canPublish
public boolean canPublish(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, org.keycloak.KeycloakSecurityContext securityContext, Topic topic) Description copied from class:MQTTHandlerCalled to authorise a publish ifMQTTHandler.handlesTopic(org.openremote.manager.mqtt.Topic)returned true; should return true if the publish is allowed otherwise return false.- Specified by:
canPublishin classMQTTHandler
-
getPublishListenerTopics
Description copied from class:MQTTHandlerGet the set of topics this handler wants to subscribe to for incoming publish messages; messages that match these topics will be passed toMQTTHandler.onPublish(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection, org.openremote.manager.mqtt.Topic, io.netty.buffer.ByteBuf).- Specified by:
getPublishListenerTopicsin classMQTTHandler
-
onPublish
public void onPublish(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, Topic topic, io.netty.buffer.ByteBuf body) Description copied from class:MQTTHandlerCalled to handle publish ifMQTTHandler.canPublish(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection, org.keycloak.KeycloakSecurityContext, org.openremote.manager.mqtt.Topic)returned true.- Specified by:
onPublishin classMQTTHandler
-
onSubscribe
public void onSubscribe(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, Topic topic) Description copied from class:MQTTHandlerCalled to handle subscribe ifMQTTHandler.canSubscribe(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection, org.keycloak.KeycloakSecurityContext, org.openremote.manager.mqtt.Topic)returned true.- Specified by:
onSubscribein classMQTTHandler
-
onUnsubscribe
public void onUnsubscribe(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, Topic topic) Description copied from class:MQTTHandlerCalled to handle unsubscribe ifMQTTHandler.handlesTopic(org.openremote.manager.mqtt.Topic)returned true.- Specified by:
onUnsubscribein classMQTTHandler
-
addSessionAttributes
-
addSessionAttribute
protected void addSessionAttribute(String userID, org.openremote.model.attribute.AttributeRef attributeRef) -
removeSessionAttribute
protected void removeSessionAttribute(String userID, org.openremote.model.attribute.AttributeRef attributeRef) -
updateUserConnectedStatus
protected void updateUserConnectedStatus(String userID, Collection<org.openremote.model.attribute.AttributeRef> attributeRefs, boolean connected) -
getUserIDAndAttributeRefs
-
attributeMatches
protected static boolean attributeMatches(org.openremote.model.attribute.Attribute<?> attr)
-