Class NodeSubscription
PublishedItem
. Only
nodes that are configured to not deliver payloads with event notifications and to not
persist items will let publishers publish events without items thus not including
items in the notifications sent to subscribers.Node subscriptions may need to be configured by the subscriber or approved by a node owner to become active. The node configuration establishes whether configuration or approval are required. In any case, the subscriber will not get event notifications until the subscription is active.
Depending on the node configuration it may be possible for the same subscriber to subscribe
multiple times to the node. Each subscription may have a different configuration like for
instance different keywords. Keywords can be used as a way to filter the type of
PublishedItem
to be notified of. When the same subscriber has subscribed multiple
times to the node a single notification is going to be sent to the subscriber instead of
sending a notification for each subscription.
- Author:
- Matt Tucker
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
Subscriptions to a node may exist in several states.static enum
-
Constructor Summary
ConstructorsConstructorDescriptionNodeSubscription
(Node node, org.xmpp.packet.JID owner, org.xmpp.packet.JID jid, NodeSubscription.State state, String id) Creates a new subscription of the specified user with the node. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canSendPublicationEvent
(LeafNode leafNode, PublishedItem publishedItem) Returns true if an event notification can be sent to the subscriber for the specified published item based on the subscription configuration and subscriber status.void
configure
(org.xmpp.packet.IQ originalIQ, org.xmpp.forms.DataForm options) Configures the subscription based on the sentDataForm
included in the IQ packet sent by the subscriber.Returns theNodeAffiliate
that owns this subscription.org.xmpp.forms.DataForm
getConfigurationForm
(Locale preferredLocale) Returns a data form with the subscription configuration.int
getDepth()
Returns 1 when the subscriber wants to receive notifications only from first-level children of the collection.int
Returns the minimum number of milliseconds between sending any two notification digests.Returns the Date at which a leased subscription will end or has ended.getID()
Returns the ID that uniquely identifies the subscription of the user in the node.org.xmpp.packet.JID
getJID()
Returns the JID that is going to receive the event notifications.Returns the keyword that the event needs to match.getNode()
Returns the node that holds this subscription.org.xmpp.packet.JID
getOwner()
Returns the JID of the entity that owns this subscription.The presence states for which an entity wants to receive notifications.getState()
Returns the current subscription state.getType()
Returns if the owner has subscribed to receive notification of new items only or of new nodes only.boolean
isActive()
Returns true if the subscription is active.boolean
Returns true if the subscription needs to be approved by a node owner to become active.boolean
Returns true if configuration is required by the node and is still pending to be configured by the subscriber.boolean
Returns whether an entity wants to receive an XMPP message body in addition to the payload format.boolean
Returns whether an entity wants to receive digests (aggregations) of notifications or all notifications individually.void
Sends an request to authorize the pending subscription to all owners.void
sendAuthorizationRequest
(org.xmpp.packet.JID owner) Sends a request to authorize the pending subscription to the specified owner.boolean
Returns whether an entity wants to receive or has disabled notifications.toString()
-
Constructor Details
-
NodeSubscription
public NodeSubscription(Node node, org.xmpp.packet.JID owner, org.xmpp.packet.JID jid, NodeSubscription.State state, String id) Creates a new subscription of the specified user with the node.- Parameters:
node
- Node to which this subscription is interested in.owner
- the JID of the entity that owns this subscription.jid
- the JID of the user that owns the subscription.state
- the state of the subscription with the node.id
- the id the uniquely identifies this subscription within the node.
-
-
Method Details
-
getNode
Returns the node that holds this subscription.- Returns:
- the node that holds this subscription.
-
getID
Returns the ID that uniquely identifies the subscription of the user in the node.- Returns:
- the ID that uniquely identifies the subscription of the user in the node.
-
getJID
public org.xmpp.packet.JID getJID()Returns the JID that is going to receive the event notifications. This JID can be the owner JID or a full JID if the owner wants to receive the notification at a particular resource.Moreover, since subscriber and owner are separated it should be theoretically possible to have a different owner JID (e.g. gato@server1.com) and a subscriber JID (e.g. gato@server2.com). Note that letting this case to happen may open the pubsub service to get spam or security problems. However, the pubsub service should avoid this case to happen.
- Returns:
- the JID that is going to receive the event notifications.
-
getOwner
public org.xmpp.packet.JID getOwner()Returns the JID of the entity that owns this subscription. The owner entity will have aNodeAffiliate
for the owner JID. The owner may have more than one subscription with the node based on what this messageNode.isMultipleSubscriptionsEnabled()
.- Returns:
- he JID of the entity that owns this subscription.
-
getState
Returns the current subscription state. Subscriptions with status of pending should be authorized by a node owner.- Returns:
- the current subscription state.
-
isConfigurationPending
public boolean isConfigurationPending()Returns true if configuration is required by the node and is still pending to be configured by the subscriber. Otherwise return false. Once a subscription is configured it might need to be approved by a node owner to become active.- Returns:
- true if configuration is required by the node and is still pending to be configured by the subscriber.
-
isAuthorizationPending
public boolean isAuthorizationPending()Returns true if the subscription needs to be approved by a node owner to become active. Until the subscription is not activated the subscriber will not receive event notifications.- Returns:
- true if the subscription needs to be approved by a node owner to become active.
-
shouldDeliverNotifications
public boolean shouldDeliverNotifications()Returns whether an entity wants to receive or has disabled notifications.- Returns:
- true when notifications should be sent to the subscriber.
-
isUsingDigest
public boolean isUsingDigest()Returns whether an entity wants to receive digests (aggregations) of notifications or all notifications individually.- Returns:
- true when an entity wants to receive digests (aggregations) of notifications.
-
getDigestFrequency
public int getDigestFrequency()Returns the minimum number of milliseconds between sending any two notification digests. Default is 24 hours.- Returns:
- the minimum number of milliseconds between sending any two notification digests.
-
getExpire
Returns the Date at which a leased subscription will end or has ended. A value ofnull
means that the subscription will never expire.- Returns:
- the Date at which a leased subscription will end or has ended. A value of
null
means that the subscription will never expire.
-
isIncludingBody
public boolean isIncludingBody()Returns whether an entity wants to receive an XMPP message body in addition to the payload format.- Returns:
- true when an entity wants to receive an XMPP message body in addition to the payload format
-
getPresenceStates
The presence states for which an entity wants to receive notifications. When the owner is in any of the returned presence states then he is allowed to receive notifications.- Returns:
- the presence states for which an entity wants to receive notifications. (e.g. available, away, etc.)
-
getType
Returns if the owner has subscribed to receive notification of new items only or of new nodes only. When subscribed to a Leaf Node then onlyitems
is available.- Returns:
- whether the owner has subscribed to receive notification of new items only or of new nodes only.
-
getDepth
public int getDepth()Returns 1 when the subscriber wants to receive notifications only from first-level children of the collection. A value of 0 means that the subscriber wants to receive notifications from all descendents.- Returns:
- 1 when the subscriber wants to receive notifications only from first-level children of the collection or 0 when notififying only from all descendents.
-
getKeyword
Returns the keyword that the event needs to match. Whennull
all event are going to be notified to the subscriber.- Returns:
- the keyword that the event needs to match. When
null
all event are going to be notified to the subscriber.
-
configure
public void configure(org.xmpp.packet.IQ originalIQ, org.xmpp.forms.DataForm options) Configures the subscription based on the sentDataForm
included in the IQ packet sent by the subscriber. If the subscription was pending of configuration then the last published item is going to be sent to the subscriber. The originalIQ parameter may benull
when using this API internally. When no IQ packet was sent then no IQ result will be sent to the sender. The rest of the functionality is the same.- Parameters:
originalIQ
- the IQ packet sent by the subscriber to configure his subscription or null when using this API internally.options
- the data form containing the new subscription configuration.
-
getConfigurationForm
Returns a data form with the subscription configuration. The data form can be used to edit the subscription configuration.- Parameters:
preferredLocale
- The preferred locale to localize the form.- Returns:
- data form used by the subscriber to edit the subscription configuration.
-
canSendPublicationEvent
Returns true if an event notification can be sent to the subscriber for the specified published item based on the subscription configuration and subscriber status.- Parameters:
leafNode
- the node that received the publication.publishedItem
- the published item to send or null if the publication didn't contain an item.- Returns:
- true if an event notification can be sent to the subscriber for the specified published item.
-
isActive
public boolean isActive()Returns true if the subscription is active. A subscription is considered active if it has not expired, it has been approved and configured.- Returns:
- true if the subscription is active.
-
getAffiliate
Returns theNodeAffiliate
that owns this subscription. Users that have a subscription with the node will ALWAYS have an affiliation even if the affiliation is of typenone
.- Returns:
- the NodeAffiliate that owns this subscription.
-
toString
-
sendAuthorizationRequest
public void sendAuthorizationRequest(org.xmpp.packet.JID owner) Sends a request to authorize the pending subscription to the specified owner.- Parameters:
owner
- the JID of the user that will get the authorization request.
-
sendAuthorizationRequest
public void sendAuthorizationRequest()Sends an request to authorize the pending subscription to all owners. The first answer sent by a owner will be processed. Rest of the answers will be discarded.
-