Package tigase.xmpp

## Class XMPPResourceConnection

- java.lang.Object
- - tigase.xmpp.RepositoryAccess
  - - tigase.xmpp.XMPPResourceConnection

- Direct Known Subclasses:
    `JabberIqPrivacy.OfflineResourceConnection`, `SMResourceConnection`

      public class XMPPResourceConnection
      extends RepositoryAccess

  Describe class XMPPResourceConnection here.
  Created: Wed Feb 8 22:30:37 2006
  Author:
    Artur Hefczyc

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static java.lang.String` | `ALL_RESOURCES_CAPS_KEY` |
    `static java.lang.String` | `ALL_RESOURCES_KEY` |
    `static java.lang.String` | `ALL_RESOURCES_PRIORITY_KEY` |
    `static java.lang.String` | `AUTHENTICATION_TIMEOUT_KEY` |
    `static java.lang.String` | `CLOSING_KEY` |
    `static java.lang.String` | `CONNECTION_CHECK_TIMESTAMP_KEY` |
    `static java.lang.String` | `ERROR_KEY` |
    `static java.lang.String` | `PRESENCE_KEY` | Constant `PRESENCE_KEY` is a key in temporary session data where the last presence sent by the user to server is stored, either initial presence or off-line presence before disconnecting.

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

      `authRepo, authState, domain, is_anonymous, NO_ACCESS_TO_REP_MSG, NOT_AUTHORIZED_MSG`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `XMPPResourceConnection​(JID connectionId, UserRepository rep, AuthRepository authRepo, SessionManagerHandler loginHandler)` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `authorizeJID​(BareJID jid, boolean anonymous)` |
    `java.lang.Object` | `computeCommonSessionDataIfAbsent​(java.lang.String key, java.util.function.Function<java.lang.String,​java.lang.Object> valueFactory)` | Method checks if in `parentSession` in session data there is value for passed `key` and returns it if exists.
    `java.lang.Object` | `computeSessionDataIfAbsent​(java.lang.String key, java.util.function.Function<java.lang.String,​java.lang.Object> valueFactory)` | Method checks if in session data is value for passed `key` and returns it if exists.
    `java.util.List<XMPPResourceConnection>` | `getActiveSessions()` | Method returns list of active connection for the same `XMPPSession`.
    `JID[]` | `getAllResourcesJIDs()` | Method returns list of jids of all connections for the same `XMPPSession` (same user).
    `AuthRepository` | `getAuthRepository()` |
    `long` | `getAuthTime()` |
    `BareJID` | `getBareJID()` | Returns user JID but without resource part.
    `java.lang.Object` | `getCommonSessionData​(java.lang.String key)` |
    `JID` | `getConnectionId()` | Gets the value of connectionId
    `JID` | `getConnectionId​(boolean updateLastAccessed)` |
    `JID` | `getConnectionId​(JID jid)` |
    `long` | `getCreationTime()` |
    `java.lang.String` | `getDefLang()` |
    `JID` | `getjid()` | Returns full user JID for this session without throwing the `NotAuthorizedException` exception if session is not authorized yet and therefore user name and resource is not known yet.
    `JID` | `getJID()` | Returns full user JID for this session or throws `NotAuthorizedException` if session is not authorized yet and therefore user name and resource is not known yet.
    `long` | `getLastAccessed()` | Gets the value of lastAccessed
    `long` | `getPacketsCounter()` |
    `XMPPSession` | `getParentSession()` |
    `Element` | `getPresence()` | Returns last presence packet with the user presence status or `null` if the user has not yet sent an initial presence.
    `int` | `getPriority()` |
    `java.lang.String` | `getResource()` | Gets the value of resource
    `java.lang.Object` | `getSessionData​(java.lang.String key)` | Retrieves session data.
    `java.lang.String` | `getSessionId()` | Gets the value of sessionId
    `JID` | `getSMComponentId()` |
    `java.lang.String` | `getUserName()` |
    `void` | `incPacketsCounter()` |
    `boolean` | `isAuthorized()` | This method allows you test this session if it already has been authorized.
    `boolean` | `isEncrypted()` |
    `boolean` | `isLocalDomain​(java.lang.String outDomain, boolean includeComponents)` |
    `boolean` | `isResourceSet()` |
    `boolean` | `isServerSession()` | Returns information whether this is a server (SessionManager) session or normal user session.
    `boolean` | `isTlsRequired()` |
    `boolean` | `isTmpSession()` |
    `boolean` | `isUserId​(BareJID bareJID)` |
    `protected void` | `login()` |
    `void` | `logout()` |
    `java.lang.String` | `nextStanzaId()` |
    `void` | `putCommonSessionData​(java.lang.String key, java.lang.Object value)` | Method sets passed value under passed key in common sessionData kept in parentSession
    `java.lang.Object` | `putCommonSessionDataIfAbsent​(java.lang.String key, java.lang.Object value)` | Method sets passed value under passed `key` in common `sessionData` kept in `parentSession` but only if there is no value for this `key` already
    `void` | `putSessionData​(java.lang.String key, java.lang.Object value)` | Saves given session data.
    `java.lang.Object` | `putSessionDataIfAbsent​(java.lang.String key, java.lang.Object value)` | Method sets passed value under passed `key` in `sessionData` but only if there is no value for this `key` already
    `void` | `queryAuth​(java.util.Map<java.lang.String,​java.lang.Object> authProps)` |
    `java.lang.Object` | `removeCommonSessionData​(java.lang.String key)` |
    `void` | `removeParentSession​(XMPPSession parent)` |
    `void` | `removeSessionData​(java.lang.String key)` |
    `void` | `setConnectionId​(JID connectionId)` | Sets the value of connectionId
    `void` | `setDefLang​(java.lang.String lang)` |
    `void` | `setLastAccessed​(long argLastAccessed)` | Sets the value of lastAccessed
    `void` | `setParentSession​(XMPPSession parent)` |
    `void` | `setPresence​(Element packet)` |
    `void` | `setPriority​(int priority)` |
    `void` | `setResource​(java.lang.String argResource)` | Sets the connection resource
    `void` | `setSessionId​(java.lang.String argSessionId)` | Sets the value of sessionId
    `void` | `setTmpSession​(boolean tmp)` |
    `void` | `streamClosed()` |
    `java.lang.String` | `toString()` |
    `Authorization` | `unregister​(java.lang.String name_param)` | Deprecated. Code moved to `JabberIqRegister.doRemoveAccount(Packet, Element, XMPPResourceConnection, Queue)`

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

      `addDataList, addOfflineDataList, addPublicDataList, changeRegistration, getAuthenticationToken, getAuthState, getData, getDataGroups, getDataKeys, getDataList, getDomain, getDomainAsJID, getOfflineData, getOfflineDataList, getPublicData, getPublicDataList, isAnonymous, removeData, removeDataGroup, removeOfflineData, removeOfflineDataGroup, removePublicData, removePublicDataGroup, setData, setDataList, setDomain, setOfflineData, setOfflineDataList, setPublicData, setPublicDataList, setRegistration`

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

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

- - ### Field Detail

    - #### ALL_RESOURCES_CAPS_KEY

          public static final java.lang.String ALL_RESOURCES_CAPS_KEY

      See Also:
        Constant Field Values

    - #### ALL_RESOURCES_KEY

          public static final java.lang.String ALL_RESOURCES_KEY

      See Also:
        Constant Field Values

    - #### ALL_RESOURCES_PRIORITY_KEY

          public static final java.lang.String ALL_RESOURCES_PRIORITY_KEY

      See Also:
        Constant Field Values

    - #### AUTHENTICATION_TIMEOUT_KEY

          public static final java.lang.String AUTHENTICATION_TIMEOUT_KEY

      See Also:
        Constant Field Values

    - #### CLOSING_KEY

          public static final java.lang.String CLOSING_KEY

      See Also:
        Constant Field Values

    - #### ERROR_KEY

          public static final java.lang.String ERROR_KEY

      See Also:
        Constant Field Values

    - #### CONNECTION_CHECK_TIMESTAMP_KEY

          public static final java.lang.String CONNECTION_CHECK_TIMESTAMP_KEY

      See Also:
        Constant Field Values

    - #### PRESENCE_KEY

          public static final java.lang.String PRESENCE_KEY

      Constant `PRESENCE_KEY` is a key in temporary session data where the last presence sent by the user to server is stored, either initial presence or off-line presence before disconnecting.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### XMPPResourceConnection

          public XMPPResourceConnection​(JID connectionId,
                                        UserRepository rep,
                                        AuthRepository authRepo,
                                        SessionManagerHandler loginHandler)

  - ### Method Detail

    - #### authorizeJID

          public void authorizeJID​(BareJID jid,
                                   boolean anonymous)
                            throws TigaseStringprepException

      Throws:
        `TigaseStringprepException`

    - #### computeCommonSessionDataIfAbsent

          public java.lang.Object computeCommonSessionDataIfAbsent​(java.lang.String key,
                                                                   java.util.function.Function<java.lang.String,​java.lang.Object> valueFactory)

      Method checks if in `parentSession` in session data there is value for passed `key` and returns it if exists. If not then it uses passed `valueFactory` to generate value and sets it in `parentSession` in session data under passed `key` and returns newly set value

    - #### computeSessionDataIfAbsent

          public java.lang.Object computeSessionDataIfAbsent​(java.lang.String key,
                                                             java.util.function.Function<java.lang.String,​java.lang.Object> valueFactory)

      Method checks if in session data is value for passed `key` and returns it if exists. If not then it uses passed `valueFactory` to generate value and sets it in session data under passed `key` and returns newly set value

    - #### getjid

          public final JID getjid()

      Returns full user JID for this session without throwing the `NotAuthorizedException` exception if session is not authorized yet and therefore user name and resource is not known yet. Please note this method is for logging using only to avoid excessive use of try/catch for debugging code. It may return null.
      Returns:
        a `String` value of calculated user full JID for this session including resource name.

    - #### incPacketsCounter

          public void incPacketsCounter()

    - #### logout

          public final void logout()
                            throws NotAuthorizedException

      Overrides:
        `logout` in class `RepositoryAccess`
      Throws:
        `NotAuthorizedException`

    - #### nextStanzaId

          public java.lang.String nextStanzaId()

    - #### putCommonSessionData

          public void putCommonSessionData​(java.lang.String key,
                                           java.lang.Object value)

      Method sets passed value under passed key in common sessionData kept in parentSession

    - #### putCommonSessionDataIfAbsent

          public java.lang.Object putCommonSessionDataIfAbsent​(java.lang.String key,
                                                               java.lang.Object value)

      Method sets passed value under passed `key` in common `sessionData` kept in `parentSession` but only if there is no value for this `key` already
      Returns:
        previous value

    - #### putSessionData

          public final void putSessionData​(java.lang.String key,
                                           java.lang.Object value)

      Saves given session data. Data are saved to temporary storage only and are accessible during this session life only and only from this session instance.
      Any `Object` can be stored and retrieved through `getSessionData(...)`.
      To access permanent storage to keep data between session instances you must use one of `get/setData...(...)` methods familly. They gives you access to hierachical permanent data base. Permanent data base however can be accessed after successuf authorization while session storage is availble all the time.
      Parameters:
        `key` - a `String` value of stored data key ID.
        `value` - a `Object` value of data stored in session.
      See Also:
        `getSessionData(String)`

    - #### putSessionDataIfAbsent

          public java.lang.Object putSessionDataIfAbsent​(java.lang.String key,
                                                         java.lang.Object value)

      Method sets passed value under passed `key` in `sessionData` but only if there is no value for this `key` already
      Returns:
        previous value

    - #### queryAuth

          public void queryAuth​(java.util.Map<java.lang.String,​java.lang.Object> authProps)
                         throws TigaseDBException

      Overrides:
        `queryAuth` in class `RepositoryAccess`
      Throws:
        `TigaseDBException`

    - #### removeCommonSessionData

          public java.lang.Object removeCommonSessionData​(java.lang.String key)

    - #### removeParentSession

          public void removeParentSession​(XMPPSession parent)

    - #### removeSessionData

          public final void removeSessionData​(java.lang.String key)

    - #### streamClosed

          public void streamClosed()

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### getActiveSessions

          public java.util.List<XMPPResourceConnection> getActiveSessions()
                                                                   throws NotAuthorizedException

      Method returns list of active connection for the same `XMPPSession`.
      Returns:
        a value of `List<XMPPResourceConnection>`
      Throws:
        `NotAuthorizedException`

    - #### getAllResourcesJIDs

          public JID[] getAllResourcesJIDs()

      Method returns list of jids of all connections for the same `XMPPSession` (same user).
      Returns:
        a value of `JID[]`

    - #### getAuthRepository

          public AuthRepository getAuthRepository()

    - #### getAuthTime

          public long getAuthTime()

    - #### getBareJID

          public final BareJID getBareJID()
                                   throws NotAuthorizedException

      Description copied from class: `RepositoryAccess`
      Returns user JID but without resource part. This is real user ID not session ID. To retrieve session ID - full JID refer to `getJID()` method.
      If session has not been authorized yet this method throws `NotAuthorizedException`.
      Specified by:
        `getBareJID` in class `RepositoryAccess`
      Returns:
        a `String` value of user ID - this is user JID without resource part. To obtain full user JID please refer to `getJID` method.
      Throws:
        `NotAuthorizedException` - when this session has not been authorized yet and some parts of user JID are not known yet.

    - #### getCommonSessionData

          public java.lang.Object getCommonSessionData​(java.lang.String key)

    - #### getConnectionId

          public JID getConnectionId()
                              throws NoConnectionIdException

      Gets the value of connectionId
      Returns:
        the value of connectionId
      Throws:
        `NoConnectionIdException`

    - #### getConnectionId

          public JID getConnectionId​(boolean updateLastAccessed)
                              throws NoConnectionIdException

      Throws:
        `NoConnectionIdException`

    - #### setConnectionId

          public void setConnectionId​(JID connectionId)

      Sets the value of connectionId
      Parameters:
        `connectionId` - is a `JID`

    - #### getConnectionId

          public JID getConnectionId​(JID jid)
                              throws NoConnectionIdException

      Throws:
        `NoConnectionIdException`

    - #### getCreationTime

          public long getCreationTime()

    - #### getDefLang

          public java.lang.String getDefLang()

    - #### setDefLang

          public void setDefLang​(java.lang.String lang)

    - #### getJID

          public final JID getJID()
                           throws NotAuthorizedException

      Returns full user JID for this session or throws `NotAuthorizedException` if session is not authorized yet and therefore user name and resource is not known yet.
      Returns:
        a `String` value of calculated user full JID for this session including resource name.
      Throws:
        `NotAuthorizedException`

    - #### getLastAccessed

          public long getLastAccessed()

      Gets the value of lastAccessed
      Returns:
        the value of lastAccessed

    - #### setLastAccessed

          public void setLastAccessed​(long argLastAccessed)

      Sets the value of lastAccessed
      Parameters:
        `argLastAccessed` - Value to assign to this.lastAccessed

    - #### getPacketsCounter

          public long getPacketsCounter()

    - #### getParentSession

          public XMPPSession getParentSession()

    - #### setParentSession

          public void setParentSession​(XMPPSession parent)
                                throws TigaseStringprepException

      Throws:
        `TigaseStringprepException`

    - #### getPresence

          public Element getPresence()

      Returns last presence packet with the user presence status or `null` if the user has not yet sent an initial presence.
      Returns:
        an `Element` with last presence status received from the user.

    - #### setPresence

          public void setPresence​(Element packet)

    - #### getPriority

          public int getPriority()

    - #### setPriority

          public void setPriority​(int priority)

    - #### getResource

          public java.lang.String getResource()

      Gets the value of resource
      Returns:
        the value of resource

    - #### setResource

          public void setResource​(java.lang.String argResource)
                           throws NotAuthorizedException,
                                  TigaseStringprepException

      Sets the connection resource
      Parameters:
        `argResource` - Value to assign to this.resource
      Throws:
        `NotAuthorizedException`
        `TigaseStringprepException`

    - #### getSessionData

          public final java.lang.Object getSessionData​(java.lang.String key)

      Retrieves session data. This method gives access to temporary session data only. You can retrieve earlier saved data giving key ID to receive needed value. Please see `putSessionData` description for more details.
      Parameters:
        `key` - a `String` value of stored data ID.
      Returns:
        a `Object` value of data for given key.
      See Also:
        `putSessionData(String, Object)`

    - #### getSessionId

          public java.lang.String getSessionId()

      Gets the value of sessionId
      Returns:
        the value of sessionId

    - #### setSessionId

          public void setSessionId​(java.lang.String argSessionId)

      Sets the value of sessionId
      Parameters:
        `argSessionId` - Value to assign to this.sessionId

    - #### getSMComponentId

          public JID getSMComponentId()

    - #### getUserName

          public final java.lang.String getUserName()
                                             throws NotAuthorizedException

      Specified by:
        `getUserName` in class `RepositoryAccess`
      Throws:
        `NotAuthorizedException`

    - #### isAuthorized

          public boolean isAuthorized()

      Description copied from class: `RepositoryAccess`
      This method allows you test this session if it already has been authorized. If `true` is returned as method result it means session has already been authorized, if `false` however session is still not authorized.
      Overrides:
        `isAuthorized` in class `RepositoryAccess`
      Returns:
        a `boolean` value which informs whether this session has been already authorized or not.

    - #### isLocalDomain

          public boolean isLocalDomain​(java.lang.String outDomain,
                                       boolean includeComponents)

    - #### isResourceSet

          public boolean isResourceSet()

    - #### isServerSession

          public boolean isServerSession()

      Returns information whether this is a server (SessionManager) session or normal user session. The server session is used to handle packets addressed to the server itself (local domain name).
      Returns:
        a `boolean` value of `true` if this is the server session and `false` otherwise.

    - #### isTmpSession

          public boolean isTmpSession()

    - #### setTmpSession

          public void setTmpSession​(boolean tmp)

    - #### isUserId

          public boolean isUserId​(BareJID bareJID)
                           throws NotAuthorizedException

      Throws:
        `NotAuthorizedException`

    - #### unregister

          @Deprecated
          public Authorization unregister​(java.lang.String name_param)
                                   throws NotAuthorizedException,
                                          TigaseDBException,
                                          TigaseStringprepException

      Deprecated.
      Code moved to `JabberIqRegister.doRemoveAccount(Packet, Element, XMPPResourceConnection, Queue)`
      Overrides:
        `unregister` in class `RepositoryAccess`
      Throws:
        `NotAuthorizedException`
        `TigaseDBException`
        `TigaseStringprepException`

    - #### isEncrypted

          public boolean isEncrypted()

    - #### isTlsRequired

          public boolean isTlsRequired()

    - #### login

          protected void login()

      Specified by:
        `login` in class `RepositoryAccess`