Package tigase.xmpp.impl
Class PresenceState
java.lang.Object
tigase.xmpp.XMPPProcessor
tigase.xmpp.impl.annotation.AnnotatedXMPPProcessor
tigase.xmpp.impl.PresenceAbstract
tigase.xmpp.impl.PresenceState
- All Implemented Interfaces:
Comparable<XMPPImplIfc>,XMPPImplIfc,XMPPProcessorConcurrencyAwareIfc,XMPPProcessorIfc,XMPPStopListenerIfc
@Bean(name="presence-state",
parent=SessionManager.class,
active=true)
public class PresenceState
extends PresenceAbstract
implements XMPPStopListenerIfc
- Author:
- andrzej
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDIRECT_PRESENCEis a key in temporary session data for the collection of JIDs where direct presence was sent.static final Stringstatic final Stringprotected static intprotected static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringkey allowing setting global forwarding JID address.Fields inherited from class tigase.xmpp.impl.PresenceAbstract
PRESENCE_ELEMENT_NAME, PRESENCE_PROBE_FULL_JID_KEY, probeFullJID, roster_util, SKIP_OFFLINE_PROP_KEY, SKIP_OFFLINE_SYS_PROP_KEY, skipOffline, USERS_STATUS_CHANGES, XMLNSFields inherited from class tigase.xmpp.XMPPProcessor
ALL_NAMES, ALL_PATHS, cmpInfoFields inherited from interface tigase.xmpp.XMPPImplIfc
CLIENT_XMLNS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddDirectPresenceJID(JID jid, XMPPResourceConnection session) Add JID to collection of JIDs to which direct presence was sent.protected static voidbroadcastDirectPresences(StanzaType t, XMPPResourceConnection session, Queue<Packet> results, Element pres) broadcastDirectPresencesbroadcast a direct Presence from providedpresElementobject to the collection of JIDs stored in temporary session data under keyDIRECT_PRESENCE.static voidbroadcastOffline(XMPPResourceConnection session, Queue<Packet> results, Map<String, Object> settings, RosterAbstract roster_util) sendPresenceBroadcastmethod broadcasts given presence to all buddies from roster and to all users to which direct presence was sent.protected voidbuddyOnline(XMPPResourceConnection session, JID buddy, Queue<Packet> results, boolean online) Method sends back presence to contact while it becomes online (i.e.protected booleanvoidgetStatistics(StatisticsList list) The method allows to retrieve plugin own statistics if it generates any.voidprocess(Packet packet, XMPPResourceConnection session, NonAuthUserRepository repo, Queue<Packet> results, Map<String, Object> settings)
Performs processing of presence packets and calls different methods for particularRosterAbstract.PresenceTypeprotected voidprocessError(Packet packet, XMPPResourceConnection session, Queue<Packet> results, Map<String, Object> settings, RosterAbstract.PresenceType presenceType) Process presence stanza of type Error.protected voidprocessInInitial(Packet packet, XMPPResourceConnection session, Queue<Packet> results, Map<String, Object> settings, RosterAbstract.PresenceType presenceType) Method is responsible for processing incoming initial presence (i.e.protected voidprocessInProbe(Packet packet, XMPPResourceConnection session, Queue<Packet> results, Map<String, Object> settings, RosterAbstract.PresenceType presenceType) Method is responsible for processing incoming presence probe (i.e.protected voidprocessOutInitial(Packet packet, XMPPResourceConnection session, Queue<Packet> results, Map<String, Object> settings, RosterAbstract.PresenceType type) Method is responsible for processing outgoing initial presence (i.e.voidrebroadcastPresence(XMPPResourceConnection session, Queue<Packet> results) static voidremoveDirectPresenceJID(JID jid, XMPPResourceConnection session) Remove JID from collection of JIDs to which direct presence was sent.voidresendPendingInRequests(XMPPResourceConnection session, Queue<Packet> results) Sends out all pending subscription request during user log-in.static voidsendPresenceBroadcast(StanzaType t, XMPPResourceConnection session, EnumSet<RosterAbstract.SubscriptionType> subscrs, Queue<Packet> results, Element pres, Map<String, Object> settings, RosterAbstract roster_util) sendPresenceBroadcastmethod broadcasts given presence to all buddies from roster and to all users to which direct presence was sent.protected voidsendRosterOfflinePresence(XMPPResourceConnection session, Queue<Packet> results) Method sends server generated presence unavailable for all buddies from the roster with a custom status message.voidPerforms additional processing upon closing user session (user either disconnects or logs-out).supTypes()Method returns an array of all stanza types which the plugin is able to handle.protected static voidupdateOfflineChange(XMPPResourceConnection session, Queue<Packet> results) updateOfflineChangemethod broadcast off-line presence to all other user active resources.Methods inherited from class tigase.xmpp.impl.PresenceAbstract
broadcastProbe, concurrentQueuesNo, forwardPresence, getProbeFullJID, getRosterUtil, isSkipOffline, isSkipOfflineSys, prepareProbe, requiresPresenceSending, sendPresence, sendPresence, setProbeFullJID, setSkipOffline, setSkipOfflineSys, updatePresenceChange, updateUserResourcesMethods inherited from class tigase.xmpp.impl.annotation.AnnotatedXMPPProcessor
id, supDiscoFeatures, supElementNamePaths, supNamespaces, supStreamFeaturesMethods inherited from class tigase.xmpp.XMPPProcessor
canHandle, compareTo, getComponentInfo, getInstance, getQueueSize, getThreadsNo, init, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Comparable
compareToMethods inherited from interface tigase.xmpp.XMPPImplIfc
canHandle, concurrentQueuesNo, getComponentInfo, id, init, supDiscoFeatures, supElementNamePaths, supNamespaces, supStreamFeatures
-
Field Details
-
DIRECT_PRESENCE
DIRECT_PRESENCEis a key in temporary session data for the collection of JIDs where direct presence was sent. To all these addresses unavailable presence must be sent when user disconnects.- See Also:
-
ENABLE_ROSTER_LAZY_LOADING_KEY
- See Also:
-
EXTENDED_PRESENCE_PROCESSORS_KEY
- See Also:
-
OFFLINE_BUD_SENT
- See Also:
-
OFFLINE_RES_SENT
- See Also:
-
OFFLINE_ROSTER_LAST_SEEN_PROP_KEY
- See Also:
-
PRESENCE_GLOBAL_FORWARD
key allowing setting global forwarding JID address.- See Also:
-
ID
- See Also:
-
HIGH_PRIORITY_PRESENCES_NO
protected static int HIGH_PRIORITY_PRESENCES_NO
-
-
Constructor Details
-
PresenceState
public PresenceState()
-
-
Method Details
-
forceSendingProbe
protected boolean forceSendingProbe()- Overrides:
forceSendingProbein classPresenceAbstract
-
addDirectPresenceJID
Add JID to collection of JIDs to which direct presence was sent. To all these addresses unavailable presence must be sent when user disconnects.- Parameters:
jid- to which direct presence was sent.session- user session which keeps all the user session data and also gives an access to the user's repository data.
-
broadcastDirectPresences
protected static void broadcastDirectPresences(StanzaType t, XMPPResourceConnection session, Queue<Packet> results, Element pres) throws NotAuthorizedException, TigaseDBException broadcastDirectPresencesbroadcast a direct Presence from providedpresElementobject to the collection of JIDs stored in temporary session data under keyDIRECT_PRESENCE.- Parameters:
t- specifies type of the presence to be send.session- user session which keeps all the user session data and also gives an access to the user's repository data.results- this a collection with packets which have been generated as input packet processing results.pres- an Object of typeElementholding Presence stanza to be sent.- Throws:
NotAuthorizedExceptionTigaseDBException
-
broadcastOffline
public static void broadcastOffline(XMPPResourceConnection session, Queue<Packet> results, Map<String, Object> settings, RosterAbstract roster_util) throws NotAuthorizedException, TigaseDBExceptionsendPresenceBroadcastmethod broadcasts given presence to all buddies from roster and to all users to which direct presence was sent.- Parameters:
session- user session which keeps all the user session data and also gives an access to the user's repository data.results- this a collection with packets which have been generated as input packet processing results.settings- this map keeps plugin specific settings loaded from the Tigase server configuration.roster_util- instance of class implementingRosterAbstract.- Throws:
NotAuthorizedException- if an error occursTigaseDBException
-
removeDirectPresenceJID
Remove JID from collection of JIDs to which direct presence was sent.- Parameters:
jid- to which direct presence was sent.session- user session which keeps all the user session data and also gives an access to the user's repository data.
-
sendPresenceBroadcast
public static void sendPresenceBroadcast(StanzaType t, XMPPResourceConnection session, EnumSet<RosterAbstract.SubscriptionType> subscrs, Queue<Packet> results, Element pres, Map<String, Object> settings, RosterAbstract roster_util) throws NotAuthorizedException, TigaseDBExceptionsendPresenceBroadcastmethod broadcasts given presence to all buddies from roster and to all users to which direct presence was sent. Before sending presence method callsrequiresPresenceSending()performing, if configured, both system and roster check to verify whether presence needs to be sent.- Parameters:
t- specifies type of the presence to be send.session- user session which keeps all the user session data and also gives an access to the user's repository data.subscrs- anEnumSet<SubscriptionType>holding allRosterAbstract.SubscriptionTypeto which a Presence should be broadcast.results- this a collection with packets which have been generated as input packet processing results.pres- an Object of typeElementholding Presence stanza to be sent.settings- this map keeps plugin specific settings loaded from the Tigase server configuration.roster_util- instance of class implementingRosterAbstract.- Throws:
NotAuthorizedException- if an error occursTigaseDBException
-
updateOfflineChange
protected static void updateOfflineChange(XMPPResourceConnection session, Queue<Packet> results) throws NotAuthorizedException updateOfflineChangemethod broadcast off-line presence to all other user active resources.- Parameters:
session- user session which keeps all the user session data and also gives an access to the user's repository data.results- this a collection with packets which have been generated as input packet processing results.- Throws:
NotAuthorizedException- if an error occurs
-
supTypes
Description copied from interface:XMPPImplIfcMethod returns an array of all stanza types which the plugin is able to handle. If the method returns NULL, then all stanzas of all types will be passed to the plugin for processing. Otherwise only stanzas with selected types, assuming that element names and name-spaces match as well.- Specified by:
supTypesin interfaceXMPPImplIfc- Overrides:
supTypesin classAnnotatedXMPPProcessor- Returns:
- a
StanzaType[]array of supported stanza types.
-
process
public void process(Packet packet, XMPPResourceConnection session, NonAuthUserRepository repo, Queue<Packet> results, Map<String, Object> settings) throws XMPPException
Performs processing of presence packets and calls different methods for particularRosterAbstract.PresenceType- Specified by:
processin interfaceXMPPProcessorIfc- Parameters:
packet- packet is which being processed. This parameter may never be null. Even though this is not immutable object it mustn't be altered. None of it's fields or attributes can be changed during processing.session- user session which keeps all the user session data and also gives an access to the user's repository data. It allows for storing information in a permanent storage or in memory only during the live of the online session. This parameter can be null if there is no online user session at the time of the packet processing.repo- this is a user data storage which is normally used when the user session (parameter above) is null. This is repository allows for a very restricted access only. It allows for storing some user private data (doesn't allow overwriting existing data) like messages for offline users and it also allows for reading user public data like VCard.results- this a collection with packets which have been generated as input packet processing results. Regardless a response to a user request is sent or the packet is forwarded to it's destination it is always required that a copy of the input packet is created and stored in the results queue.settings- this map keeps plugin specific settings loaded from the Tigase server configuration. In most cases it is unused, however if the plugin needs to access an external database that this is a way to pass database connection string to the plugin.- Throws:
XMPPException
-
stopped
public void stopped(XMPPResourceConnection session, Queue<Packet> results, Map<String, Object> settings) Description copied from interface:XMPPStopListenerIfcPerforms additional processing upon closing user session (user either disconnects or logs-out).- Specified by:
stoppedin interfaceXMPPStopListenerIfc- Parameters:
session- user session which keeps all the user session data and also gives an access to the user's repository data. It allows for storing information in a permanent storage or in memory only during the live of the online session. This parameter can be null if there is no online user session at the time of the packet processing.results- this a collection with packets which have been generated as input packet processing results. Regardless a response to a user request is sent or the packet is forwarded to it's destination it is always required that a copy of the input packet is created and stored in the results queue.settings- this map keeps plugin specific settings loaded from the Tigase server configuration. In most cases it is unused, however if the plugin needs to access an external database that this is a way to pass database connection string to the plugin.
-
getStatistics
Description copied from interface:XMPPImplIfcThe method allows to retrieve plugin own statistics if it generates any.- Specified by:
getStatisticsin interfaceXMPPImplIfc- Overrides:
getStatisticsin classXMPPProcessor- Parameters:
list- is a statistics collection to which plugins own metrics can be added.
-
rebroadcastPresence
public void rebroadcastPresence(XMPPResourceConnection session, Queue<Packet> results) throws NotAuthorizedException, TigaseDBException -
resendPendingInRequests
public void resendPendingInRequests(XMPPResourceConnection session, Queue<Packet> results) throws NotAuthorizedException, TigaseDBException Sends out all pending subscription request during user log-in.- Parameters:
session- user session which keeps all the user session data and also gives an access to the user's repository data.results- this a collection with packets which have been generated as input packet processing results.- Throws:
NotAuthorizedExceptionTigaseDBException
-
processError
protected void processError(Packet packet, XMPPResourceConnection session, Queue<Packet> results, Map<String, Object> settings, RosterAbstract.PresenceType presenceType) throws NotAuthorizedException, TigaseDBException, NoConnectionIdExceptionProcess presence stanza of type Error. Allows errors sent from server to user and ignore presence errors sent from the user.- Parameters:
packet- packet is which being processed.session- user session which keeps all the user session data and also gives an access to the user's repository data.results- this a collection with packets which have been generated as input packet processing results.settings- this map keeps plugin specific settings loaded from the Tigase server configuration.presenceType- specifies type of the presence- Throws:
NotAuthorizedExceptionTigaseDBExceptionNoConnectionIdException
-
processInInitial
protected void processInInitial(Packet packet, XMPPResourceConnection session, Queue<Packet> results, Map<String, Object> settings, RosterAbstract.PresenceType presenceType) throws NoConnectionIdException, NotAuthorizedException, TigaseDBExceptionMethod is responsible for processing incoming initial presence (i.e. in the receivers session manager).
It validates the packet (whether from is present or if it's a direct presence to existing resource) and subsequently set received presence for the contact that sent it.- Parameters:
packet- packet is which being processed.session- user session which keeps all the user session data and also gives an access to the user's repository data.results- this a collection with packets which have been generated as input packet processing results.settings- this map keeps plugin specific settings loaded from the Tigase server configuration.presenceType- specifies type of the presence.- Throws:
NoConnectionIdExceptionNotAuthorizedExceptionTigaseDBException
-
processInProbe
protected void processInProbe(Packet packet, XMPPResourceConnection session, Queue<Packet> results, Map<String, Object> settings, RosterAbstract.PresenceType presenceType) throws NotAuthorizedException, TigaseDBException, PacketErrorTypeExceptionMethod is responsible for processing incoming presence probe (i.e. in the receivers session manager).
It validates whether the packet comes from a contact that has correct subscription and responds with presence of all user's resources presences.- Parameters:
packet- packet is which being processed.session- user session which keeps all the user session data and also gives an access to the user's repository data.results- this a collection with packets which have been generated as input packet processing results.settings- this map keeps plugin specific settings loaded from the Tigase server configuration.presenceType- specifies type of the presence.- Throws:
NotAuthorizedExceptionTigaseDBExceptionPacketErrorTypeException
-
processOutInitial
protected void processOutInitial(Packet packet, XMPPResourceConnection session, Queue<Packet> results, Map<String, Object> settings, RosterAbstract.PresenceType type) throws NotAuthorizedException, TigaseDBExceptionMethod is responsible for processing outgoing initial presence (i.e. in the sender session manager).
Process packet accordingly whether it's a direct presence (forward it, add to proper collection of JIDs to which a direct presence has been sent) or regular presence. THe latter causes properly address the packet, store presence within session data for subsequent use, and for the first availability presence (in case there is no prior presence stored in user session data) server sends probes to all contacts and pushes out all pending subscription request or (if there i already presence stored in session data) broadcast presence update to contacts.
If there is a JID forwarding set up, presence is also forwarded to configured JID.- Parameters:
packet- packet is which being processed.session- user session which keeps all the user session data and also gives an access to the user's repository data.results- this a collection with packets which have been generated as input packet processing results.settings- this map keeps plugin specific settings loaded from the Tigase server configuration.type- specifies type of the presence.- Throws:
NotAuthorizedExceptionTigaseDBException
-
buddyOnline
protected void buddyOnline(XMPPResourceConnection session, JID buddy, Queue<Packet> results, boolean online) throws NotAuthorizedException, TigaseDBException Method sends back presence to contact while it becomes online (i.e. during processing of incoming initial presence of the contact/buddy)- Parameters:
session- user session which keeps all the user session data and also gives an access to the user's repository data.buddy-JIDof a roster element for which an online state will be setresults- this a collection with packets which have been generated as input packet processing results.online- set whether given contact is online or offline- Throws:
NotAuthorizedExceptionTigaseDBException
-
sendRosterOfflinePresence
protected void sendRosterOfflinePresence(XMPPResourceConnection session, Queue<Packet> results) throws NotAuthorizedException, TigaseDBException, NoConnectionIdException Method sends server generated presence unavailable for all buddies from the roster with a custom status message.- Parameters:
session- user session which keeps all the user session data and also gives an access to the user's repository data.results- this a collection with packets which have been generated as input packet processing results.- Throws:
NotAuthorizedExceptionTigaseDBExceptionNoConnectionIdException
-