Package org.eclipse.hono.adapter.mqtt
Class AbstractSubscription
- java.lang.Object
-
- org.eclipse.hono.adapter.mqtt.AbstractSubscription
-
- All Implemented Interfaces:
Subscription
- Direct Known Subclasses:
CommandSubscription,ErrorSubscription
public abstract class AbstractSubscription extends Object implements Subscription
Base class for an MQTT subscription of a device.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.eclipse.hono.adapter.mqtt.Subscription
Subscription.Key
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractSubscription(org.eclipse.hono.util.ResourceIdentifier topicResource, io.netty.handler.codec.mqtt.MqttQoS qos, org.eclipse.hono.auth.Device authenticatedDevice)Creates a new AbstractSubscription.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsDeviceId()Checks if the topic contains a device identifier.booleancontainsTenantId()Checks if the topic contains a tenant identifier.StringgetAuthenticatedDeviceId()Gets the device id from authentication.StringgetDeviceId()Gets the device id from topic or authentication.StringgetEndpoint()Gets the endpoint of the subscription.io.netty.handler.codec.mqtt.MqttQoSgetQos()Gets the QoS of the subscription.StringgetTenant()Gets the tenant from topic or authentication.StringgetTopic()Gets the subscription topic.booleanisAuthenticated()Gets the authentication status, which indicates the need to publish on tenant/device-id for unauthenticated devices.booleanisGatewaySubscriptionForSpecificDevice()Checks whether this subscription represents the case of a gateway subscribing for a specific device that it acts on behalf of.voidlogSubscribeFailure(io.opentracing.Span span, Throwable error)Logs a failed subscription attempt to the given span.voidlogSubscribeSuccess(io.opentracing.Span span)Logs a successful subscription attempt to the given span.voidlogUnsubscribe(io.opentracing.Span span)Logs the unsubscription to the given span.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.eclipse.hono.adapter.mqtt.Subscription
getKey
-
-
-
-
Constructor Detail
-
AbstractSubscription
protected AbstractSubscription(org.eclipse.hono.util.ResourceIdentifier topicResource, io.netty.handler.codec.mqtt.MqttQoS qos, org.eclipse.hono.auth.Device authenticatedDevice)Creates a new AbstractSubscription.- Parameters:
topicResource- The topic to subscribe for.qos- The quality-of-service level for the subscription.authenticatedDevice- The authenticated device ornull.- Throws:
NullPointerException- if topicResource or qos isnull.IllegalArgumentException- if the topic does not match the rules.
-
-
Method Detail
-
getTenant
public final String getTenant()
Description copied from interface:SubscriptionGets the tenant from topic or authentication.- Specified by:
getTenantin interfaceSubscription- Returns:
- The tenant (never
null).
-
getDeviceId
public final String getDeviceId()
Description copied from interface:SubscriptionGets the device id from topic or authentication.- Specified by:
getDeviceIdin interfaceSubscription- Returns:
- The device id (never
null).
-
getAuthenticatedDeviceId
public final String getAuthenticatedDeviceId()
Description copied from interface:SubscriptionGets the device id from authentication.- Specified by:
getAuthenticatedDeviceIdin interfaceSubscription- Returns:
- The device id or
null.
-
getEndpoint
public final String getEndpoint()
Description copied from interface:SubscriptionGets the endpoint of the subscription.- Specified by:
getEndpointin interfaceSubscription- Returns:
- The endpoint.
-
getQos
public final io.netty.handler.codec.mqtt.MqttQoS getQos()
Description copied from interface:SubscriptionGets the QoS of the subscription.- Specified by:
getQosin interfaceSubscription- Returns:
- The QoS value.
-
getTopic
public final String getTopic()
Description copied from interface:SubscriptionGets the subscription topic.- Specified by:
getTopicin interfaceSubscription- Returns:
- The topic.
-
isAuthenticated
public final boolean isAuthenticated()
Description copied from interface:SubscriptionGets the authentication status, which indicates the need to publish on tenant/device-id for unauthenticated devices.- Specified by:
isAuthenticatedin interfaceSubscription- Returns:
trueif created with an authenticated device.
-
isGatewaySubscriptionForSpecificDevice
public final boolean isGatewaySubscriptionForSpecificDevice()
Description copied from interface:SubscriptionChecks whether this subscription represents the case of a gateway subscribing for a specific device that it acts on behalf of.- Specified by:
isGatewaySubscriptionForSpecificDevicein interfaceSubscription- Returns:
trueif a gateway is subscribing for a specific device.
-
containsTenantId
public boolean containsTenantId()
Description copied from interface:SubscriptionChecks if the topic contains a tenant identifier.- Specified by:
containsTenantIdin interfaceSubscription- Returns:
trueif the topic contains a tenant id.
-
containsDeviceId
public boolean containsDeviceId()
Description copied from interface:SubscriptionChecks if the topic contains a device identifier.- Specified by:
containsDeviceIdin interfaceSubscription- Returns:
trueif the topic contains a device id.
-
logSubscribeSuccess
public final void logSubscribeSuccess(io.opentracing.Span span)
Description copied from interface:SubscriptionLogs a successful subscription attempt to the given span.- Specified by:
logSubscribeSuccessin interfaceSubscription- Parameters:
span- The span to log to.
-
logSubscribeFailure
public final void logSubscribeFailure(io.opentracing.Span span, Throwable error)Description copied from interface:SubscriptionLogs a failed subscription attempt to the given span.- Specified by:
logSubscribeFailurein interfaceSubscription- Parameters:
span- The span to log to.error- The error to log.
-
logUnsubscribe
public final void logUnsubscribe(io.opentracing.Span span)
Description copied from interface:SubscriptionLogs the unsubscription to the given span.- Specified by:
logUnsubscribein interfaceSubscription- Parameters:
span- The span to log to.
-
-