Class MQTTProtocolManager
- java.lang.Object
-
- org.apache.activemq.artemis.spi.core.protocol.AbstractProtocolManager<io.netty.handler.codec.mqtt.MqttMessage,MQTTInterceptor,MQTTConnection,MQTTRedirectHandler>
-
- org.apache.activemq.artemis.core.protocol.mqtt.MQTTProtocolManager
-
- All Implemented Interfaces:
org.apache.activemq.artemis.core.server.management.NotificationListener,org.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,MQTTRedirectHandler>
public class MQTTProtocolManager extends org.apache.activemq.artemis.spi.core.protocol.AbstractProtocolManager<io.netty.handler.codec.mqtt.MqttMessage,MQTTInterceptor,MQTTConnection,MQTTRedirectHandler> implements org.apache.activemq.artemis.core.server.management.NotificationListener
MQTTProtocolManager
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanacceptsNoHandshake()voidaddChannelHandlers(io.netty.channel.ChannelPipeline pipeline)MQTTConnectionaddConnectedClient(java.lang.String clientId, MQTTConnection connection)org.apache.activemq.artemis.spi.core.protocol.ConnectionEntrycreateConnectionEntry(org.apache.activemq.artemis.spi.core.remoting.Acceptor acceptorUsed, org.apache.activemq.artemis.spi.core.remoting.Connection connection)java.util.Map<java.lang.String,MQTTConnection>getConnectedClients()For DEBUG onlyintgetDefaultMqttSessionExpiryInterval()org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactorygetFactory()MQTTRedirectHandlergetRedirectHandler()MQTTSessionStategetSessionState(java.lang.String clientId)java.util.Map<java.lang.String,MQTTSessionState>getSessionStates()voidhandleBuffer(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, org.apache.activemq.artemis.api.core.ActiveMQBuffer buffer)voidhandshake(org.apache.activemq.artemis.core.remoting.impl.netty.NettyServerConnection connection, org.apache.activemq.artemis.api.core.ActiveMQBuffer buffer)java.lang.StringinvokeIncoming(io.netty.handler.codec.mqtt.MqttMessage mqttMessage, MQTTConnection connection)java.lang.StringinvokeOutgoing(io.netty.handler.codec.mqtt.MqttMessage mqttMessage, MQTTConnection connection)booleanisClientConnected(java.lang.String clientId, MQTTConnection connection)booleanisProtocol(byte[] array)The protocol handler passes us an 8 byte long array from the transport.voidonNotification(org.apache.activemq.artemis.core.server.management.Notification notification)voidremoveConnectedClient(java.lang.String clientId)voidremoveHandler(java.lang.String name)MQTTSessionStateremoveSessionState(java.lang.String clientId)voidscanSessions()MQTTProtocolManagersetDefaultMqttSessionExpiryInterval(int sessionExpiryInterval)voidupdateInterceptors(java.util.List incoming, java.util.List outgoing)java.util.List<java.lang.String>websocketSubprotocolIdentifiers()
-
-
-
Method Detail
-
getDefaultMqttSessionExpiryInterval
public int getDefaultMqttSessionExpiryInterval()
-
setDefaultMqttSessionExpiryInterval
public MQTTProtocolManager setDefaultMqttSessionExpiryInterval(int sessionExpiryInterval)
-
onNotification
public void onNotification(org.apache.activemq.artemis.core.server.management.Notification notification)
- Specified by:
onNotificationin interfaceorg.apache.activemq.artemis.core.server.management.NotificationListener
-
getFactory
public org.apache.activemq.artemis.spi.core.protocol.ProtocolManagerFactory getFactory()
- Specified by:
getFactoryin interfaceorg.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,MQTTRedirectHandler>
-
updateInterceptors
public void updateInterceptors(java.util.List incoming, java.util.List outgoing)- Specified by:
updateInterceptorsin interfaceorg.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,MQTTRedirectHandler>
-
scanSessions
public void scanSessions()
-
createConnectionEntry
public org.apache.activemq.artemis.spi.core.protocol.ConnectionEntry createConnectionEntry(org.apache.activemq.artemis.spi.core.remoting.Acceptor acceptorUsed, org.apache.activemq.artemis.spi.core.remoting.Connection connection)- Specified by:
createConnectionEntryin interfaceorg.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,MQTTRedirectHandler>
-
acceptsNoHandshake
public boolean acceptsNoHandshake()
- Specified by:
acceptsNoHandshakein interfaceorg.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,MQTTRedirectHandler>
-
removeHandler
public void removeHandler(java.lang.String name)
- Specified by:
removeHandlerin interfaceorg.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,MQTTRedirectHandler>
-
handleBuffer
public void handleBuffer(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection connection, org.apache.activemq.artemis.api.core.ActiveMQBuffer buffer)- Specified by:
handleBufferin interfaceorg.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,MQTTRedirectHandler>
-
addChannelHandlers
public void addChannelHandlers(io.netty.channel.ChannelPipeline pipeline)
- Specified by:
addChannelHandlersin interfaceorg.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,MQTTRedirectHandler>
-
isProtocol
public boolean isProtocol(byte[] array)
The protocol handler passes us an 8 byte long array from the transport. We sniff these first 8 bytes to see if they match the first 8 bytes from MQTT Connect packet. In many other protocols the protocol name is the first thing sent on the wire. However, in MQTT the protocol name doesn't come until later on in the CONNECT packet. In order to fully identify MQTT protocol via protocol name, we need up to 12 bytes. However, we can use other information from the connect packet to infer that the MQTT protocol is being used. This is enough to identify MQTT and add the Netty codec in the pipeline. The Netty codec takes care of things from here. MQTT CONNECT PACKET: See MQTT 3.1.1 Spec for more info. Byte 1: Fixed Header Packet Type. 0b0001000 (16) = MQTT Connect Byte 2-[N]: Remaining length of the Connect Packet (encoded with 1-4 bytes). The next set of bytes represents the UTF8 encoded string MQTT (MQTT 3.1.1) or MQIsdp (MQTT 3.1) Byte N: UTF8 MSB must be 0 Byte N+1: UTF8 LSB must be (4(MQTT) or 6(MQIsdp)) Byte N+1: M (first char from the protocol name). Max no bytes used in the sequence = 8.- Specified by:
isProtocolin interfaceorg.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,MQTTRedirectHandler>
-
handshake
public void handshake(org.apache.activemq.artemis.core.remoting.impl.netty.NettyServerConnection connection, org.apache.activemq.artemis.api.core.ActiveMQBuffer buffer)- Specified by:
handshakein interfaceorg.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,MQTTRedirectHandler>
-
websocketSubprotocolIdentifiers
public java.util.List<java.lang.String> websocketSubprotocolIdentifiers()
- Specified by:
websocketSubprotocolIdentifiersin interfaceorg.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,MQTTRedirectHandler>
-
getRedirectHandler
public MQTTRedirectHandler getRedirectHandler()
- Specified by:
getRedirectHandlerin interfaceorg.apache.activemq.artemis.spi.core.protocol.ProtocolManager<MQTTInterceptor,MQTTRedirectHandler>
-
invokeIncoming
public java.lang.String invokeIncoming(io.netty.handler.codec.mqtt.MqttMessage mqttMessage, MQTTConnection connection)
-
invokeOutgoing
public java.lang.String invokeOutgoing(io.netty.handler.codec.mqtt.MqttMessage mqttMessage, MQTTConnection connection)
-
isClientConnected
public boolean isClientConnected(java.lang.String clientId, MQTTConnection connection)
-
removeConnectedClient
public void removeConnectedClient(java.lang.String clientId)
-
addConnectedClient
public MQTTConnection addConnectedClient(java.lang.String clientId, MQTTConnection connection)
- Parameters:
clientId-connection-- Returns:
- the
MQTTConnectionthat the added connection replaced or null if there was no previous entry for theclientId
-
getSessionState
public MQTTSessionState getSessionState(java.lang.String clientId)
-
removeSessionState
public MQTTSessionState removeSessionState(java.lang.String clientId)
-
getSessionStates
public java.util.Map<java.lang.String,MQTTSessionState> getSessionStates()
-
getConnectedClients
public java.util.Map<java.lang.String,MQTTConnection> getConnectedClients()
For DEBUG only
-
-