Package tigase.xmpp.impl

## Class PresenceSubscription

- java.lang.Object
- - tigase.xmpp.XMPPProcessor
  - - tigase.xmpp.impl.annotation.AnnotatedXMPPProcessor
    - - tigase.xmpp.impl.PresenceAbstract
      - - tigase.xmpp.impl.PresenceSubscription

- All Implemented Interfaces:
    `java.lang.Comparable<XMPPImplIfc>`, `XMPPImplIfc`, `XMPPProcessorConcurrencyAwareIfc`, `XMPPProcessorIfc`

      @Bean(name="presence-subscription",
            parent=SessionManager.class,
            active=true)
      public class PresenceSubscription
      extends PresenceAbstract

  Author:
    andrzej

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `PresenceSubscription.PresenceSubscriptionVHostItemExtension` |
    `static class` | `PresenceSubscription.PresenceSubscriptionVHostItemExtensionProvider` |

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static java.lang.String` | `AUTO_AUTHORIZE_PROP_KEY` | key allowing enabling automatic authorisation.
    `protected static java.lang.String` | `ID` |
    `protected VHostManagerIfc` | `vHostManager` |

    - ### 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, XMLNS`

    - ### Fields inherited from class tigase.xmpp.XMPPProcessor

      `ALL_NAMES, ALL_PATHS, cmpInfo`

    - ### Fields inherited from interface tigase.xmpp.XMPPImplIfc

      `CLIENT_XMLNS`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `PresenceSubscription()` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `process​(Packet packet, XMPPResourceConnection session, NonAuthUserRepository repo, java.util.Queue<Packet> results, java.util.Map<java.lang.String,​java.lang.Object> settings)` | Performs processing of presence packets and calls different methods for particular `RosterAbstract.PresenceType`
    `protected void` | `processInSubscribe​(Packet packet, XMPPResourceConnection session, java.util.Queue<Packet> results, java.util.Map<java.lang.String,​java.lang.Object> settings, RosterAbstract.PresenceType pres_type)` | Method is responsible for processing incoming subscription request (i.e. in the receivers session manager).
    `protected void` | `processInSubscribed​(Packet packet, XMPPResourceConnection session, java.util.Queue<Packet> results, java.util.Map<java.lang.String,​java.lang.Object> settings, RosterAbstract.PresenceType pres_type)` | Method is responsible for processing incoming subscribed presence (i.e. in the receivers session manager).
    `protected void` | `processInUnsubscribe​(Packet packet, XMPPResourceConnection session, java.util.Queue<Packet> results, java.util.Map<java.lang.String,​java.lang.Object> settings, RosterAbstract.PresenceType pres_type)` | Method is responsible for processing incoming unsubscribe presence (i.e. in the receivers session manager).
    `protected void` | `processInUnsubscribed​(Packet packet, XMPPResourceConnection session, java.util.Queue<Packet> results, java.util.Map<java.lang.String,​java.lang.Object> settings, RosterAbstract.PresenceType pres_type)` | Method is responsible for processing incoming unsubscribed presence (i.e. in the receivers session manager).
    `protected void` | `processOutSubscribe​(Packet packet, XMPPResourceConnection session, java.util.Queue<Packet> results, java.util.Map<java.lang.String,​java.lang.Object> settings, RosterAbstract.PresenceType pres_type)` | Method is responsible for processing outgoing subscribe and unsubscribe presence (i.e. in the sender session manager).
    `protected void` | `processOutSubscribed​(Packet packet, XMPPResourceConnection session, java.util.Queue<Packet> results, java.util.Map<java.lang.String,​java.lang.Object> settings, RosterAbstract.PresenceType pres_type)` | Method is responsible for processing outgoing subscribed and unsubscribed presence (i.e. in the sender session manager).
    `java.util.Set<StanzaType>` | `supTypes()` | Method returns an array of all stanza types which the plugin is able to handle.

    - ### Methods inherited from class tigase.xmpp.impl.PresenceAbstract

      `broadcastProbe, concurrentQueuesNo, forwardPresence, getProbeFullJID, getRosterUtil, isSkipOffline, isSkipOfflineSys, prepareProbe, requiresPresenceSending, sendPresence, sendPresence, setProbeFullJID, setSkipOffline, setSkipOfflineSys, updatePresenceChange, updateUserResources`

    - ### Methods inherited from class tigase.xmpp.impl.annotation.AnnotatedXMPPProcessor

      `id, supDiscoFeatures, supElementNamePaths, supNamespaces, supStreamFeatures`

    - ### Methods inherited from class tigase.xmpp.XMPPProcessor

      `canHandle, compareTo, getComponentInfo, getInstance, getQueueSize, getStatistics, getThreadsNo, init, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.lang.Comparable

      `compareTo`

    - ### Methods inherited from interface tigase.xmpp.XMPPImplIfc

      `canHandle, getComponentInfo, getStatistics, id, init, supDiscoFeatures, supElementNamePaths, supNamespaces, supStreamFeatures`

- - ### Field Detail

    - #### AUTO_AUTHORIZE_PROP_KEY

          public static final java.lang.String AUTO_AUTHORIZE_PROP_KEY

      key allowing enabling automatic authorisation.
      See Also:
        Constant Field Values

    - #### ID

          protected static final java.lang.String ID

      See Also:
        Constant Field Values

    - #### vHostManager

          @Inject(nullAllowed=true)
          protected VHostManagerIfc vHostManager

  - ### Constructor Detail

    - #### PresenceSubscription

          public PresenceSubscription()

  - ### Method Detail

    - #### supTypes

          public java.util.Set<StanzaType> supTypes()

      Description copied from interface: `XMPPImplIfc`
      Method 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:
        `supTypes` in interface `XMPPImplIfc`
      Overrides:
        `supTypes` in class `AnnotatedXMPPProcessor`
      Returns:
        a `StanzaType[]` array of supported stanza types.

    - #### process

          public void process​(Packet packet,
                              XMPPResourceConnection session,
                              NonAuthUserRepository repo,
                              java.util.Queue<Packet> results,
                              java.util.Map<java.lang.String,​java.lang.Object> settings)
                       throws XMPPException

      Performs processing of presence packets and calls different methods for particular `RosterAbstract.PresenceType`
      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`

    - #### processInSubscribe

          protected void processInSubscribe​(Packet packet,
                                            XMPPResourceConnection session,
                                            java.util.Queue<Packet> results,
                                            java.util.Map<java.lang.String,​java.lang.Object> settings,
                                            RosterAbstract.PresenceType pres_type)
                                     throws NotAuthorizedException,
                                            TigaseDBException,
                                            NoConnectionIdException,
                                            PolicyViolationException

      Method is responsible for processing incoming subscription request (i.e. in the receivers session manager).
      If the contact is already subscribed the an auto-reply with type='subscribded' is sent, otherwise contact is added to the roster (if it's missing/there is no current subscription), sets the subscription type to `PresenceType.in_subscribe` and subsequently broadcast presence update to all connected resources.
      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.
        `pres_type` - specifies type of the presence.
      Throws:
        `NotAuthorizedException`
        `TigaseDBException`
        `NoConnectionIdException`
        `PolicyViolationException`

    - #### processInSubscribed

          protected void processInSubscribed​(Packet packet,
                                             XMPPResourceConnection session,
                                             java.util.Queue<Packet> results,
                                             java.util.Map<java.lang.String,​java.lang.Object> settings,
                                             RosterAbstract.PresenceType pres_type)
                                      throws NotAuthorizedException,
                                             TigaseDBException,
                                             NoConnectionIdException,
                                             PolicyViolationException

      Method is responsible for processing incoming subscribed presence (i.e. in the receivers session manager).
      Contact is added to the roster (if it's missing/there is no current subscription), sets the subscription type to `PresenceType.in_subscribed` and subsequently, if subscription has changed,forwards the presence to user resource connection as well as broadcast presence update to all connected resources.
      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.
        `pres_type` - specifies type of the presence.
      Throws:
        `NotAuthorizedException`
        `TigaseDBException`
        `NoConnectionIdException`
        `PolicyViolationException`

    - #### processInUnsubscribe

          protected void processInUnsubscribe​(Packet packet,
                                              XMPPResourceConnection session,
                                              java.util.Queue<Packet> results,
                                              java.util.Map<java.lang.String,​java.lang.Object> settings,
                                              RosterAbstract.PresenceType pres_type)
                                       throws NotAuthorizedException,
                                              TigaseDBException,
                                              NoConnectionIdException,
                                              PolicyViolationException

      Method is responsible for processing incoming unsubscribe presence (i.e. in the receivers session manager).
      First method performs update of subscription of the given contact and subsequently the request is forwarded to the client to make sure it says in synch with the server (in case there was actual change in subscription). Lastly a roster push is generated to all connected resources to update them with current state of the roster and items subscriptions.
      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.
        `pres_type` - specifies type of the presence.
      Throws:
        `NotAuthorizedException`
        `TigaseDBException`
        `NoConnectionIdException`
        `PolicyViolationException`

    - #### processInUnsubscribed

          protected void processInUnsubscribed​(Packet packet,
                                               XMPPResourceConnection session,
                                               java.util.Queue<Packet> results,
                                               java.util.Map<java.lang.String,​java.lang.Object> settings,
                                               RosterAbstract.PresenceType pres_type)
                                        throws NotAuthorizedException,
                                               TigaseDBException,
                                               NoConnectionIdException,
                                               PolicyViolationException

      Method is responsible for processing incoming unsubscribed presence (i.e. in the receivers session manager).
      First method checks for the current subscription of the contact and if this verifies performs subsequent actions such as forwarding presence to the user connection to make sure it says in synch with the server, updates contact subscription with `PresenceType.in_unsubscribed` and in case that there was a change in user subscription send out a roster push to all connected resources to update them with current state of the roster and items subscriptions.
      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.
        `pres_type` - specifies type of the presence.
      Throws:
        `NotAuthorizedException`
        `TigaseDBException`
        `NoConnectionIdException`
        `PolicyViolationException`

    - #### processOutSubscribe

          protected void processOutSubscribe​(Packet packet,
                                             XMPPResourceConnection session,
                                             java.util.Queue<Packet> results,
                                             java.util.Map<java.lang.String,​java.lang.Object> settings,
                                             RosterAbstract.PresenceType pres_type)
                                      throws NotAuthorizedException,
                                             TigaseDBException,
                                             NoConnectionIdException,
                                             PolicyViolationException

      Method is responsible for processing outgoing subscribe and unsubscribe presence (i.e. in the sender session manager).
      Presence packet is forwarded to the destination with the JID stripped from the resource.

      In case of `PresenceType.out_subscribe` packet type contact is added to the roster (in case it was missing), a subscription state is being updated and, in case there was a change, a roster push is being sent to all user resources.
      In case of `PresenceType.out_unsubscribe` method updates contact subscription (and generates roster push if there was a change) and if the resulting contact subscription is NONE then contact is removed from the roster.

      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.
        `pres_type` - specifies type of the presence.
      Throws:
        `NotAuthorizedException`
        `TigaseDBException`
        `NoConnectionIdException`
        `PolicyViolationException`

    - #### processOutSubscribed

          protected void processOutSubscribed​(Packet packet,
                                              XMPPResourceConnection session,
                                              java.util.Queue<Packet> results,
                                              java.util.Map<java.lang.String,​java.lang.Object> settings,
                                              RosterAbstract.PresenceType pres_type)
                                       throws NotAuthorizedException,
                                              TigaseDBException,
                                              NoConnectionIdException,
                                              PolicyViolationException

      Method is responsible for processing outgoing subscribed and unsubscribed presence (i.e. in the sender session manager).
      Presence packet is forwarded to the destination with the JID stripped from the resource, a subscription state is being updated and, in case there was a change, a roster push is being sent to all user resources. Also, in case of presence type out_subscribed server send current presence to the user from each of the contact's available resources. For the presence type out_unsubscribed an unavailable presence is sent.
      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.
        `pres_type` - specifies type of the presence.
      Throws:
        `NotAuthorizedException`
        `TigaseDBException`
        `NoConnectionIdException`
        `PolicyViolationException`