Package tigase.net
Class IOService<RefObject>
- java.lang.Object
-
- tigase.net.IOService<RefObject>
-
- Type Parameters:
RefObject
- is a reference object stored by this service. This is e reference to higher level data object keeping more information about the connection.
- All Implemented Interfaces:
java.util.concurrent.Callable<IOService<?>>
,TLSEventHandler
,IOListener
- Direct Known Subclasses:
XMPPIOService
public abstract class IOService<RefObject> extends java.lang.Object implements java.util.concurrent.Callable<IOService<?>>, TLSEventHandler, IOListener
IOService
offers thread safecall()
method execution, however you must be prepared that other methods can be called simultaneously likestop()
,getProtocol()
orisConnected()
.
It is recommended that developers extendAbsractServerService
rather then implementServerService
interface directly.If you directly implement
ServerService
interface you must take care aboutSocketChannel
I/O, queuing tasks, processing results and thread safe execution ofcall()
method. If you however extendIOService
class all this basic operation are implemented and you have only to take care about parsing data received from network socket. Parsing data is expected to be implemented inparseData(char[] data)
method.
Created: Tue Sep 28 23:00:34 2004
- Author:
- Artur Hefczyc
-
-
Field Summary
Fields Modifier and Type Field Description protected java.nio.CharBuffer
cb
static java.lang.String
CERT_CHECK_RESULT
static java.lang.String
CERT_REQUIRED_DOMAIN
protected java.nio.charset.CharsetDecoder
decoder
protected java.nio.charset.CharsetEncoder
encoder
static java.lang.String
HOSTNAME_KEY
static java.lang.String
LOCAL_CERT_CHECK_RESULT
protected byte[]
partialCharacterBytes
The saved partial bytes for multi-byte UTF-8 characters between readsstatic java.lang.String
PORT_TYPE_PROP_KEY
static java.lang.String
SESSION_ID_KEY
This is key used to store session ID in temporary session data storage.static java.lang.String
SSL_PROTOCOLS_KEY
-
Constructor Summary
Constructors Constructor Description IOService()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
accept(java.nio.channels.SocketChannel socketChannel)
protected java.nio.ByteOrder
byteOrder()
IOService<?>
call()
boolean
checkBufferLimit(int bufferSize)
ConnectionType
connectionType()
protected boolean
debug(char[] msg)
protected boolean
debug(java.lang.String msg, java.lang.String prefix)
void
forceStop()
long
getBuffOverflow(boolean reset)
long
getBytesReceived(boolean reset)
long
getBytesSent(boolean reset)
CertificateContainerIfc
getCertificateContainer()
JID
getConnectionId()
JID
getDataReceiver()
protected IOInterface
getIO()
long
getLastTransferTime()
This method returns the time of last transfer in any direction through this service.java.lang.String
getLocalAddress()
java.security.cert.Certificate
getLocalCertificate()
int
getLocalPort()
Method returns local port of opened socketjava.security.cert.Certificate
getPeerCertificate()
long[]
getReadCounters()
RefObject
getRefObject()
java.lang.String
getRemoteAddress()
Returns a remote IP address for the TCP/IP connection.java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object>
getSessionData()
java.nio.channels.SocketChannel
getSocketChannel()
int
getSocketInputSize()
void
getStatistics(StatisticsList list, boolean reset)
byte[]
getTlsUniqueId()
long
getTotalBuffOverflow()
long
getTotalBytesReceived()
long
getTotalBytesSent()
java.lang.String
getUniqueId()
long[]
getWriteCounters()
protected boolean
handleMalformedInput(java.nio.ByteBuffer buffer, java.nio.CharBuffer cb)
void
handshakeCompleted(TLSWrapper wrapper)
boolean
isConnected()
protected boolean
isInputBufferEmpty()
protected boolean
isSocketServiceReady()
protected abstract void
processSocketData()
abstract void
processWaitingPackets()
protected java.nio.ByteBuffer
readBytes()
protected void
readCompleted()
protected char[]
readData()
protected abstract int
receivedPackets()
void
setBufferLimit(int bufferLimit)
void
setCertificateContainer(CertificateContainerIfc certificateContainer)
void
setConnectionId(JID connectionId)
void
setDataReceiver(JID address)
void
setIOServiceListener(IOServiceListener<IOService<RefObject>> sl)
void
setRefObject(RefObject refObject)
void
setSessionData(java.util.Map<java.lang.String,java.lang.Object> props)
protected void
setSocketServiceReady(boolean value)
void
setSslContextContainer(SSLContextContainerIfc sslContextContainer)
void
setX509TrustManagers(javax.net.ssl.TrustManager[] trustManager)
void
startSSL(boolean clientMode, boolean wantClientAuth, boolean needClientAuth)
void
startTLS(boolean clientMode, boolean wantClientAuth, boolean needClientAuth)
void
startZLib(int level)
void
stop()
java.lang.String
toString()
boolean
waitingToRead()
boolean
waitingToSend()
int
waitingToSendSize()
protected void
writeBytes(java.nio.ByteBuffer data)
protected void
writeData(java.lang.String data)
-
-
-
Field Detail
-
CERT_CHECK_RESULT
public static final java.lang.String CERT_CHECK_RESULT
- See Also:
- Constant Field Values
-
LOCAL_CERT_CHECK_RESULT
public static final java.lang.String LOCAL_CERT_CHECK_RESULT
- See Also:
- Constant Field Values
-
CERT_REQUIRED_DOMAIN
public static final java.lang.String CERT_REQUIRED_DOMAIN
- See Also:
- Constant Field Values
-
HOSTNAME_KEY
public static final java.lang.String HOSTNAME_KEY
- See Also:
- Constant Field Values
-
PORT_TYPE_PROP_KEY
public static final java.lang.String PORT_TYPE_PROP_KEY
- See Also:
- Constant Field Values
-
SESSION_ID_KEY
public static final java.lang.String SESSION_ID_KEY
This is key used to store session ID in temporary session data storage. As it is used by many components it is required that all components access session ID with this constant.- See Also:
- Constant Field Values
-
SSL_PROTOCOLS_KEY
public static final java.lang.String SSL_PROTOCOLS_KEY
- See Also:
- Constant Field Values
-
cb
protected java.nio.CharBuffer cb
-
decoder
protected java.nio.charset.CharsetDecoder decoder
-
encoder
protected java.nio.charset.CharsetEncoder encoder
-
partialCharacterBytes
protected byte[] partialCharacterBytes
The saved partial bytes for multi-byte UTF-8 characters between reads
-
-
Method Detail
-
accept
public void accept(java.nio.channels.SocketChannel socketChannel) throws java.io.IOException
- Throws:
java.io.IOException
-
call
public IOService<?> call() throws java.io.IOException
- Specified by:
call
in interfacejava.util.concurrent.Callable<RefObject>
- Throws:
java.io.IOException
-
checkBufferLimit
public boolean checkBufferLimit(int bufferSize)
- Specified by:
checkBufferLimit
in interfaceIOListener
-
connectionType
public ConnectionType connectionType()
-
forceStop
public void forceStop()
-
handshakeCompleted
public void handshakeCompleted(TLSWrapper wrapper)
- Specified by:
handshakeCompleted
in interfaceTLSEventHandler
-
processWaitingPackets
public abstract void processWaitingPackets() throws java.io.IOException
- Throws:
java.io.IOException
-
startSSL
public void startSSL(boolean clientMode, boolean wantClientAuth, boolean needClientAuth) throws java.io.IOException
- Throws:
java.io.IOException
-
getCertificateContainer
public CertificateContainerIfc getCertificateContainer()
-
setCertificateContainer
public void setCertificateContainer(CertificateContainerIfc certificateContainer)
-
startTLS
public void startTLS(boolean clientMode, boolean wantClientAuth, boolean needClientAuth) throws java.io.IOException
- Throws:
java.io.IOException
-
startZLib
public void startZLib(int level)
-
stop
public void stop()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
waitingToRead
public boolean waitingToRead()
-
waitingToSend
public boolean waitingToSend()
-
waitingToSendSize
public int waitingToSendSize()
-
getBuffOverflow
public long getBuffOverflow(boolean reset)
-
getBytesReceived
public long getBytesReceived(boolean reset)
-
getBytesSent
public long getBytesSent(boolean reset)
-
getConnectionId
public JID getConnectionId()
-
setConnectionId
public void setConnectionId(JID connectionId)
-
getDataReceiver
public JID getDataReceiver()
-
setDataReceiver
public void setDataReceiver(JID address)
-
getLastTransferTime
public long getLastTransferTime()
This method returns the time of last transfer in any direction through this service. It is used to help detect dead connections.
-
getLocalAddress
public java.lang.String getLocalAddress()
-
getTlsUniqueId
public byte[] getTlsUniqueId()
-
getLocalPort
public int getLocalPort()
Method returns local port of opened socket
-
getReadCounters
public long[] getReadCounters()
-
getRefObject
public RefObject getRefObject()
-
setRefObject
public void setRefObject(RefObject refObject)
-
getRemoteAddress
public java.lang.String getRemoteAddress()
Returns a remote IP address for the TCP/IP connection.- Returns:
- a remote IP address for the TCP/IP connection.
-
getSessionData
public java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> getSessionData()
-
setSessionData
public void setSessionData(java.util.Map<java.lang.String,java.lang.Object> props)
-
getSocketInputSize
public int getSocketInputSize()
- Specified by:
getSocketInputSize
in interfaceTLSEventHandler
-
getSocketChannel
public java.nio.channels.SocketChannel getSocketChannel()
-
getStatistics
public void getStatistics(StatisticsList list, boolean reset)
-
getTotalBuffOverflow
public long getTotalBuffOverflow()
-
getTotalBytesReceived
public long getTotalBytesReceived()
-
getTotalBytesSent
public long getTotalBytesSent()
-
getUniqueId
public java.lang.String getUniqueId()
-
getWriteCounters
public long[] getWriteCounters()
-
isConnected
public boolean isConnected()
-
setBufferLimit
public void setBufferLimit(int bufferLimit)
-
setIOServiceListener
public void setIOServiceListener(IOServiceListener<IOService<RefObject>> sl)
-
setSslContextContainer
public void setSslContextContainer(SSLContextContainerIfc sslContextContainer)
-
setX509TrustManagers
public void setX509TrustManagers(javax.net.ssl.TrustManager[] trustManager)
-
getPeerCertificate
public java.security.cert.Certificate getPeerCertificate()
-
getLocalCertificate
public java.security.cert.Certificate getLocalCertificate()
-
byteOrder
protected java.nio.ByteOrder byteOrder()
-
debug
protected boolean debug(char[] msg)
-
debug
protected boolean debug(java.lang.String msg, java.lang.String prefix)
-
processSocketData
protected abstract void processSocketData() throws java.io.IOException
- Throws:
java.io.IOException
-
readBytes
protected java.nio.ByteBuffer readBytes() throws java.io.IOException
- Throws:
java.io.IOException
-
readCompleted
protected void readCompleted()
-
readData
protected char[] readData() throws java.io.IOException
- Throws:
java.io.IOException
-
receivedPackets
protected abstract int receivedPackets()
-
writeBytes
protected void writeBytes(java.nio.ByteBuffer data)
-
writeData
protected void writeData(java.lang.String data)
-
isSocketServiceReady
protected boolean isSocketServiceReady()
-
setSocketServiceReady
protected void setSocketServiceReady(boolean value)
-
handleMalformedInput
protected boolean handleMalformedInput(java.nio.ByteBuffer buffer, java.nio.CharBuffer cb)
-
isInputBufferEmpty
protected boolean isInputBufferEmpty()
-
getIO
protected IOInterface getIO()
-
-