|
Openfire 3.4.3 Javadoc | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jivesoftware.openfire.net.SocketConnection
public class SocketConnection
An object to track the state of a XMPP client-server session. Currently this class contains the socket channel connecting the client and server.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface org.jivesoftware.openfire.Connection |
---|
Connection.ClientAuth, Connection.CompressionPolicy, Connection.TLSPolicy |
Field Summary | |
---|---|
static String |
CHARSET
The utf-8 charset for decoding and encoding XMPP packet streams. |
Constructor Summary | |
---|---|
SocketConnection(PacketDeliverer backupDeliverer,
Socket socket,
boolean isSecure)
Create a new session using the supplied socket. |
Method Summary | |
---|---|
void |
addCompression()
Adds the compression filter to the connection but only filter incoming traffic. |
void |
close()
Close this session including associated socket connection. |
void |
deliver(Packet packet)
Delivers the packet to this connection without checking the recipient. |
void |
deliverRawText(String text)
Delivers raw text to this connection. |
byte[] |
getAddress()
Returns the raw IP address of this InetAddress
object. |
Connection.CompressionPolicy |
getCompressionPolicy()
Returns whether compression is optional or is disabled. |
String |
getHostAddress()
Returns the IP address string in textual presentation. |
String |
getHostName()
Gets the host name for this IP address. |
long |
getIdleTimeout()
|
static Collection<SocketConnection> |
getInstances()
|
String |
getLanguage()
Returns the language code that should be used for this connection (e.g. |
int |
getMajorXMPPVersion()
Returns the major version of XMPP being used by this connection (major_version.minor_version. |
int |
getMinorXMPPVersion()
Returns the minor version of XMPP being used by this connection (major_version.minor_version. |
PacketDeliverer |
getPacketDeliverer()
Returns the packet deliverer to use when delivering a packet over the socket fails. |
int |
getPort()
Returns the port that the connection uses. |
SSLSession |
getSSLSession()
Returns the underlying SSLSession for the connection. |
Connection.TLSPolicy |
getTlsPolicy()
Returns whether TLS is mandatory, optional or is disabled. |
TLSStreamHandler |
getTLSStreamHandler()
Returns the stream handler responsible for securing the plain connection and providing the corresponding input and output streams. |
Writer |
getWriter()
Returns the Writer used to send data to the connection. |
void |
init(LocalSession owner)
Initializes the connection with it's owning session. |
boolean |
isClosed()
Returns true if the connection/session is closed. |
boolean |
isCompressed()
Returns true if the connection is using compression. |
boolean |
isFlashClient()
Returns true if the connected client is a flash client. |
boolean |
isSecure()
Returns true if this connection is secure. |
void |
registerCloseListener(ConnectionCloseListener listener,
Object handbackMessage)
Registers a listener for close event notification. |
void |
removeCloseListener(ConnectionCloseListener listener)
Removes a registered close event listener. |
void |
setCompressionPolicy(Connection.CompressionPolicy compressionPolicy)
Sets whether compression is enabled or is disabled. |
void |
setFlashClient(boolean flashClient)
Sets whether the connected client is a flash client. |
void |
setIdleTimeout(long timeout)
Sets the number of milliseconds a connection has to be idle to be closed. |
void |
setLanaguage(String language)
Sets the language code that should be used for this connection (e.g. |
void |
setSocketReader(SocketReader socketReader)
|
void |
setTlsPolicy(Connection.TLSPolicy tlsPolicy)
Sets whether TLS is mandatory, optional or is disabled. |
void |
setXMPPVersion(int majorVersion,
int minorVersion)
Sets the XMPP version information. |
void |
startCompression()
Start compressing outgoing traffic for this connection. |
void |
startTLS(boolean clientMode,
String remoteServer,
Connection.ClientAuth authentication)
Secures the plain connection by negotiating TLS with the other peer. |
void |
systemShutdown()
Notification message indicating that the server is being shutdown. |
String |
toString()
|
boolean |
validate()
Verifies that the connection is still live. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String CHARSET
Constructor Detail |
---|
public SocketConnection(PacketDeliverer backupDeliverer, Socket socket, boolean isSecure) throws IOException
backupDeliverer
- the packet deliverer this connection will use when socket is closed.socket
- the socket to represent.isSecure
- true if this is a secure connection.
IOException
- if there was a socket error while sending the packet.Method Detail |
---|
public static Collection<SocketConnection> getInstances()
public TLSStreamHandler getTLSStreamHandler()
public void startTLS(boolean clientMode, String remoteServer, Connection.ClientAuth authentication) throws IOException
Connection
true
in the clientMode parameter and the server
receiving the TLS request must pass false
in the clientMode parameter.
Both servers should specify the xmpp domain of the other server in the remoteServer
parameter.
In the case of client-2-server the XMPP server must pass false
in the
clientMode parameter since it will behave as the server in the TLS negotiation. The
remoteServer parameter will always be null.
startTLS
in interface Connection
clientMode
- boolean indicating if this entity is a client or a server in the TLS negotiation.remoteServer
- xmpp domain of the remote server or null. When null a
ClientTrustManager
will be used for verifying certificates
otherwise a ServerTrustManager
will be used.authentication
- policy to use for authenticating the remote peer.
IOException
public void addCompression()
Connection
addCompression
in interface Connection
public void startCompression()
Connection
startCompression
in interface Connection
public boolean validate()
Connection
validate
in interface Connection
public void init(LocalSession owner)
Connection
init
in interface Connection
owner
- the session that owns this connectionpublic void registerCloseListener(ConnectionCloseListener listener, Object handbackMessage)
Connection
registerCloseListener
in interface Connection
listener
- the listener to register for events.handbackMessage
- the object to send in the event notification.public void removeCloseListener(ConnectionCloseListener listener)
Connection
removeCloseListener
in interface Connection
listener
- the listener to deregister for close events.public byte[] getAddress() throws UnknownHostException
Connection
InetAddress
object. The result is in network byte order: the highest order
byte of the address is in getAddress()[0]
.
getAddress
in interface Connection
UnknownHostException
- if IP address of host could not be determined.public String getHostAddress() throws UnknownHostException
Connection
getHostAddress
in interface Connection
UnknownHostException
- if IP address of host could not be determined.public String getHostName() throws UnknownHostException
Connection
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
checkConnect
method is first called
with the hostname and -1
as 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.
getHostName
in interface Connection
UnknownHostException
- if IP address of host could not be determined.InetAddress.getCanonicalHostName()
,
SecurityManager.checkConnect(java.lang.String, int)
public int getPort()
public Writer getWriter()
deliver(Packet)
method should be used to send data instead of using the writer directly.
You must synchronize on the writer before writing data to it to ensure
data consistency:
Writer writer = connection.getWriter(); synchronized(writer) { // write data.... }
public boolean isClosed()
Connection
isClosed
in interface Connection
public boolean isSecure()
Connection
isSecure
in interface Connection
public boolean isCompressed()
Connection
isCompressed
in interface Connection
public Connection.TLSPolicy getTlsPolicy()
Connection
getTlsPolicy
in interface Connection
public void setTlsPolicy(Connection.TLSPolicy tlsPolicy)
setTlsPolicy
in interface Connection
tlsPolicy
- whether TLS is mandatory, optional or is disabled.public Connection.CompressionPolicy getCompressionPolicy()
Connection
getCompressionPolicy
in interface Connection
public void setCompressionPolicy(Connection.CompressionPolicy compressionPolicy)
setCompressionPolicy
in interface Connection
compressionPolicy
- whether Compression is enabled or is disabled.public long getIdleTimeout()
public void setIdleTimeout(long timeout)
timeout
- the number of milliseconds a connection has to be idle to be closed.public int getMajorXMPPVersion()
Connection
getMajorXMPPVersion
in interface Connection
public int getMinorXMPPVersion()
Connection
getMinorXMPPVersion
in interface Connection
public void setXMPPVersion(int majorVersion, int minorVersion)
setXMPPVersion
in interface Connection
majorVersion
- the major version.minorVersion
- the minor version.public String getLanguage()
Connection
getLanguage
in interface Connection
public void setLanaguage(String language)
setLanaguage
in interface Connection
language
- the language code.public boolean isFlashClient()
Connection
isFlashClient
in interface Connection
public void setFlashClient(boolean flashClient)
setFlashClient
in interface Connection
flashClient
- true if the if the connection is a flash client.public SSLSession getSSLSession()
Connection
SSLSession
for the connection.
getSSLSession
in interface Connection
SSLSession
is initialized yet.public PacketDeliverer getPacketDeliverer()
Connection
getPacketDeliverer
in interface Connection
public void close()
Connection
close
in interface Connection
public void systemShutdown()
Connection
systemShutdown
in interface Connection
public void deliver(Packet packet) throws UnauthorizedException, PacketException
Connection
socket.send(packet.getWriteBuffer())
.
deliver
in interface Connection
packet
- the packet to deliver.
UnauthorizedException
- if a permission error was detected.
PacketException
public void deliverRawText(String text)
Connection
Connection.deliver(org.xmpp.packet.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.
deliverRawText
in interface Connection
text
- the XML stanzas represented kept in a String.public String toString()
toString
in class Object
public void setSocketReader(SocketReader socketReader)
|
Openfire 3.4.3 Javadoc | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |