Class LocalSession
- All Implemented Interfaces:
ChannelHandler<org.xmpp.packet.Packet>,RoutableChannelHandler,Session
- Direct Known Subclasses:
LocalClientSession,LocalComponentSession,LocalConnectionMultiplexerSession,LocalServerSession
- Author:
- Gaston Dombiak
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jivesoftware.openfire.session.Session
Session.Status -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.xmpp.packet.JIDThe Address this session is authenticated as.protected ConnectionThe connection that this session represents.protected final Stringprotected SessionManagerprotected final longprotected Session.StatusThe current session status.protected final StreamIDThe stream id for this session (random and unique).protected final StreamManagerXEP-0198 Stream ManagerFields inherited from interface org.jivesoftware.openfire.session.Session
MAJOR_VERSION, MINOR_VERSION -
Constructor Summary
ConstructorsConstructorDescriptionLocalSession(String serverName, Connection connection, StreamID streamID, Locale language) Creates a session with an underlying connection and permission protection. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close this session including associated socket connection.voiddeliverRawText(String text) Delivers raw text to this connection.org.xmpp.packet.JIDObtain the address of the session.abstract List<org.dom4j.Element>Returns a text with the available stream features.Returns the TLS cipher suite name used by the connection of the session, if any.Returns the connection associated with this Session.Obtain the date the session was created.Returns the IP address string in textual presentation.Gets the host name for this IP address.final LocaleReturns the locale that is used for this session (e.g.Obtain the time the session last had activity.longObtain the number of packets sent from the client to the server.longObtain the number of packets sent from the server to the client.Returns the peer certificates associated with this session, if any.Obtain the name of the server this session belongs to.getSessionData(String key) Retrieves session data.Retrieves Software Version data.Obtain the current status of this session.Obtain the stream ID associated with this sesison.Get XEP-0198 Stream manager for sessionReturns the TLS protocol name used by the connection of the session, if any.voidIncrements the number of packets sent from the client to the server.voidIncrements the number of packets sent from the server to the client.booleanisClosed()Returns true if the connection/session is closed.booleanReturns true if the session is detached (that is, if the underlying connection has been closed while the session instance itself has not been closed).booleanReturns true if this session uses encrypted connections.booleanReturns true if the other peer of this session presented a self-signed certificate.voidprocess(org.xmpp.packet.Packet packet) Process an XMPP packet.voidreattach(LocalSession connectionProvider, long h) Reattach the (existing) session to the connection provided by a new session (a session that will be replaced by the older, pre-existing session).removeSessionData(String key) Removes session data.voidsetAddress(org.xmpp.packet.JID address) Sets the new address of this session.voidSet the session to detached mode, indicating that the underlying connection has been closed.setSessionData(String key, Object value) Saves given session data.voidsetSoftwareVersionData(String key, String value) Saves given session data.voidsetStatus(Session.Status status) Set the new status of this session.toString()booleanvalidate()Verifies that the connection is still live.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jivesoftware.openfire.session.Session
isAuthenticated
-
Field Details
-
address
@Nonnull protected org.xmpp.packet.JID addressThe Address this session is authenticated as. -
streamID
The stream id for this session (random and unique). -
status
The current session status. -
conn
The connection that this session represents. -
sessionManager
-
serverName
-
startDate
protected final long startDate -
streamManager
XEP-0198 Stream Manager
-
-
Constructor Details
-
LocalSession
Creates a session with an underlying connection and permission protection.- Parameters:
serverName- domain of the XMPP server where the new session belongs.connection- The connection we are proxying.streamID- unique identifier for this session.language- The language to use for this session.
-
-
Method Details
-
isDetached
public boolean isDetached()Returns true if the session is detached (that is, if the underlying connection has been closed while the session instance itself has not been closed).- Returns:
- true if session detached
-
setDetached
public void setDetached()Set the session to detached mode, indicating that the underlying connection has been closed. -
reattach
Reattach the (existing) session to the connection provided by a new session (a session that will be replaced by the older, pre-existing session). The connection must already be initialized as a running XML Stream, normally by having run through XEP-0198 resumption.- Parameters:
connectionProvider- Session from which to obtain the connection from.h- the sequence number of the last handled stanza sent over the former stream
-
getAddress
@Nonnull public org.xmpp.packet.JID getAddress()Obtain the address of the session. The address is used by services like the core server packet router to determine if a packet should be sent to the handler. Handlers that are working on behalf of the server should use the generic server hostname address (e.g. server.com).- Specified by:
getAddressin interfaceRoutableChannelHandler- Specified by:
getAddressin interfaceSession- Returns:
- the address of the packet handler.
-
setAddress
public void setAddress(@Nonnull org.xmpp.packet.JID address) Sets the new address of this session. The address is used by services like the core server packet router to determine if a packet should be sent to the handler. Handlers that are working on behalf of the server should use the generic server hostname address (e.g. server.com).- Parameters:
address- the new address of this session.
-
getConnection
Returns the connection associated with this Session. Note that null can be returned, for example when the session is detached.- Returns:
- The connection for this session
-
getStatus
Obtain the current status of this session. -
setStatus
Set the new status of this session. Setting a status may trigger certain events to occur (setting a closed status will close this session).- Parameters:
status- The new status code for this session
-
getStreamID
Obtain the stream ID associated with this sesison. Stream ID's are generated by the server and should be unique and random.- Specified by:
getStreamIDin interfaceSession- Returns:
- This session's assigned stream ID
-
getServerName
Obtain the name of the server this session belongs to.- Specified by:
getServerNamein interfaceSession- Returns:
- the server name.
-
getCreationDate
Obtain the date the session was created.- Specified by:
getCreationDatein interfaceSession- Returns:
- the session's creation date.
-
getLastActiveDate
Obtain the time the session last had activity.- Specified by:
getLastActiveDatein interfaceSession- Returns:
- The last time the session received activity.
-
incrementClientPacketCount
public void incrementClientPacketCount()Increments the number of packets sent from the client to the server. -
incrementServerPacketCount
public void incrementServerPacketCount()Increments the number of packets sent from the server to the client. -
getNumClientPackets
public long getNumClientPackets()Obtain the number of packets sent from the client to the server.- Specified by:
getNumClientPacketsin interfaceSession- Returns:
- The number of packets sent from the client to the server.
-
getNumServerPackets
public long getNumServerPackets()Obtain the number of packets sent from the server to the client.- Specified by:
getNumServerPacketsin interfaceSession- Returns:
- The number of packets sent from the server to the client.
-
setSessionData
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.- Parameters:
key- aStringvalue of stored data key ID.value- aObjectvalue of data stored in session.- Returns:
- the previous value associated with
key, ornullif there was no mapping forkey. (Anullreturn can also indicate that the map previously associatednullwithkey.) - See Also:
-
getSessionData
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 seesetSessionData(String, Object)description for more details.- Parameters:
key- aStringvalue of stored data ID.- Returns:
- a
Objectvalue of data for given key. - See Also:
-
removeSessionData
Removes session data. Please seesetSessionData(String, Object)description for more details.- Parameters:
key- aStringvalue of stored data ID.- Returns:
- the previous value associated with
key, ornullif there was no mapping forkey. - See Also:
-
getStreamManager
Get XEP-0198 Stream manager for session- Returns:
- The StreamManager for the session.
-
process
public void process(org.xmpp.packet.Packet packet) Description copied from interface:ChannelHandlerProcess an XMPP packet.- Specified by:
processin interfaceChannelHandler<org.xmpp.packet.Packet>- Specified by:
processin interfaceSession- Parameters:
packet- a packet to process.
-
deliverRawText
Description copied from interface:SessionDelivers raw text to this connection. This is a very low level way for sending XML stanzas to the client. This method should not be used unless you have very good reasons for not usingSession.process(Packet).This method avoids having to get the writer of this connection and mess directly with the writer. Therefore, this method ensures a correct delivery of the stanza even if other threads were sending data concurrently.
- Specified by:
deliverRawTextin interfaceSession- Parameters:
text- the XML stanzas represented kept in a String.
-
getAvailableStreamFeatures
Returns a text with the available stream features. Each subclass may return different values depending whether the session has been authenticated or not.- Returns:
- a text with the available stream features or
nullto add nothing.
-
close
public void close()Description copied from interface:SessionClose this session including associated socket connection. The order of events for closing the session is:- Set closing flag to prevent redundant shutdowns.
- Call notifyEvent all listeners that the channel is shutting down.
- Close the socket.
Session.getStatus()will be CLOSED. -
validate
public boolean validate()Description copied from interface:SessionVerifies that the connection is still live. Typically this is done by sending a whitespace character between packets. // TODO No one is sending this message now. Delete it? -
isEncrypted
public boolean isEncrypted()Description copied from interface:SessionReturns true if this session uses encrypted connections.- Specified by:
isEncryptedin interfaceSession- Returns:
- true if the session is encrypted (e.g. TLS)
-
getPeerCertificates
Description copied from interface:SessionReturns the peer certificates associated with this session, if any.- Specified by:
getPeerCertificatesin interfaceSession- Returns:
- certificates, possibly empty or null.
-
isClosed
public boolean isClosed()Description copied from interface:SessionReturns true if the connection/session is closed. -
getHostAddress
Description copied from interface:SessionReturns the IP address string in textual presentation.- Specified by:
getHostAddressin interfaceSession- Returns:
- the raw IP address in a string format.
- Throws:
UnknownHostException- if IP address of host could not be determined.
-
getHostName
Description copied from interface:SessionGets the host name for this IP address.If this InetAddress was created with a host name, this host name will be remembered and returned; otherwise, a reverse name lookup will be performed and the result will be returned based on the system configured name lookup service. If a lookup of the name service is required, call
getCanonicalHostName.If there is a security manager, its
checkConnectmethod is first called with the hostname and-1as its arguments to see if the operation is allowed. If the operation is not allowed, it will return the textual representation of the IP address.- Specified by:
getHostNamein interfaceSession- Returns:
- the host name for this IP address, or if the operation is not allowed by the security check, the textual representation of the IP address.
- Throws:
UnknownHostException- if IP address of host could not be determined.- See Also:
-
toString
-
isUsingSelfSignedCertificate
public boolean isUsingSelfSignedCertificate()Returns true if the other peer of this session presented a self-signed certificate. When using self-signed certificate for server-2-server sessions then SASL EXTERNAL will not be used and instead server-dialback will be preferred for vcerifying the identify of the remote server.- Returns:
- true if the other peer of this session presented a self-signed certificate.
-
getTLSProtocolName
Description copied from interface:SessionReturns the TLS protocol name used by the connection of the session, if any. Always returns a valid string, though the string may be "NONE"- Specified by:
getTLSProtocolNamein interfaceSession- Returns:
- a TLS protocol (version) name.
-
getCipherSuiteName
Description copied from interface:SessionReturns the TLS cipher suite name used by the connection of the session, if any. Always returns a valid string, though the string may be "NONE"- Specified by:
getCipherSuiteNamein interfaceSession- Returns:
- cipher suite name.
-
getLanguage
Description copied from interface:SessionReturns the locale that is used for this session (e.g.Locale.ENGLISH).- Specified by:
getLanguagein interfaceSession- Returns:
- The language for the session.
-
getSoftwareVersion
Retrieves Software Version data. This method gives access to temporary Software Version data only.- Specified by:
getSoftwareVersionin interfaceSession- Returns:
- a Map collection value of data .
-
setSoftwareVersionData
Saves given session data. Data is saved to temporary storage only and is accessible during this session life only and only from this session instance.- Parameters:
key- aStringvalue of stored data key ID.value- aStringvalue of data stored in session.
-