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:
Callable<IOService<?>>,TLSEventHandler,IOListener
- Direct Known Subclasses:
XMPPIOService
public abstract class IOService<RefObject> extends Object implements Callable<IOService<?>>, TLSEventHandler, IOListener
IOServiceoffers thread safecall()method execution, however you must be prepared that other methods can be called simultaneously likestop(),getProtocol()orisConnected().
It is recommended that developers extendAbsractServerServicerather then implementServerServiceinterface directly.If you directly implement
ServerServiceinterface you must take care aboutSocketChannelI/O, queuing tasks, processing results and thread safe execution ofcall()method. If you however extendIOServiceclass 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
- Version:
- $Rev$
- Author:
- Artur Hefczyc
-
-
Field Summary
Fields Modifier and Type Field Description protected CharBuffercbstatic StringCERT_CHECK_RESULTstatic StringCERT_REQUIRED_DOMAINprotected CharsetDecoderdecoderprotected CharsetEncoderencoderstatic StringHOSTNAME_KEYprotected byte[]partialCharacterBytesThe saved partial bytes for multi-byte UTF-8 characters between readsstatic StringPORT_TYPE_PROP_KEYstatic StringSESSION_ID_KEYThis is key used to store session ID in temporary session data storage.static StringSSL_PROTOCOLS_KEY
-
Constructor Summary
Constructors Constructor Description IOService()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaccept(SocketChannel socketChannel)protected ByteOrderbyteOrder()IOService<?>call()booleancheckBufferLimit(int bufferSize)ConnectionTypeconnectionType()protected booleandebug(char[] msg)protected booleandebug(String msg, String prefix)voidforceStop()longgetBuffOverflow(boolean reset)longgetBytesReceived(boolean reset)longgetBytesSent(boolean reset)CertificateContainerIfcgetCertificateContainer()JIDgetConnectionId()JIDgetDataReceiver()protected IOInterfacegetIO()longgetLastTransferTime()This method returns the time of last transfer in any direction through this service.StringgetLocalAddress()CertificategetLocalCertificate()intgetLocalPort()Method returns local port of opened socketCertificategetPeerCertificate()long[]getReadCounters()RefObjectgetRefObject()StringgetRemoteAddress()Returns a remote IP address for the TCP/IP connection.ConcurrentMap<String,Object>getSessionData()SocketChannelgetSocketChannel()intgetSocketInputSize()voidgetStatistics(StatisticsList list, boolean reset)byte[]getTlsUniqueId()longgetTotalBuffOverflow()longgetTotalBytesReceived()longgetTotalBytesSent()StringgetUniqueId()long[]getWriteCounters()protected booleanhandleMalformedInput(ByteBuffer buffer, CharBuffer cb)voidhandshakeCompleted(TLSWrapper wrapper)booleanisConnected()protected booleanisInputBufferEmpty()protected booleanisSocketServiceReady()protected abstract voidprocessSocketData()abstract voidprocessWaitingPackets()protected ByteBufferreadBytes()protected voidreadCompleted()protected char[]readData()protected abstract intreceivedPackets()voidsetBufferLimit(int bufferLimit)voidsetCertificateContainer(CertificateContainerIfc certificateContainer)voidsetConnectionId(JID connectionId)voidsetDataReceiver(JID address)voidsetIOServiceListener(IOServiceListener<IOService<RefObject>> sl)voidsetRefObject(RefObject refObject)voidsetSessionData(Map<String,Object> props)protected voidsetSocketServiceReady(boolean value)voidsetSslContextContainer(SSLContextContainerIfc sslContextContainer)voidsetX509TrustManagers(TrustManager[] trustManager)voidstartSSL(boolean clientMode, boolean wantClientAuth, boolean needClientAuth)voidstartTLS(boolean clientMode, boolean wantClientAuth, boolean needClientAuth)voidstartZLib(int level)voidstop()StringtoString()booleanwaitingToRead()booleanwaitingToSend()intwaitingToSendSize()protected voidwriteBytes(ByteBuffer data)protected voidwriteData(String data)
-
-
-
Field Detail
-
CERT_CHECK_RESULT
public static final String CERT_CHECK_RESULT
- See Also:
- Constant Field Values
-
CERT_REQUIRED_DOMAIN
public static final String CERT_REQUIRED_DOMAIN
- See Also:
- Constant Field Values
-
HOSTNAME_KEY
public static final String HOSTNAME_KEY
- See Also:
- Constant Field Values
-
PORT_TYPE_PROP_KEY
public static final String PORT_TYPE_PROP_KEY
- See Also:
- Constant Field Values
-
SESSION_ID_KEY
public static final 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 String SSL_PROTOCOLS_KEY
- See Also:
- Constant Field Values
-
cb
protected CharBuffer cb
-
decoder
protected CharsetDecoder decoder
-
encoder
protected CharsetEncoder encoder
-
partialCharacterBytes
protected byte[] partialCharacterBytes
The saved partial bytes for multi-byte UTF-8 characters between reads
-
-
Method Detail
-
accept
public void accept(SocketChannel socketChannel) throws IOException
- Throws:
IOException
-
call
public IOService<?> call() throws IOException
- Specified by:
callin interfaceCallable<RefObject>- Throws:
IOException
-
checkBufferLimit
public boolean checkBufferLimit(int bufferSize)
- Specified by:
checkBufferLimitin interfaceIOListener
-
connectionType
public ConnectionType connectionType()
-
forceStop
public void forceStop()
-
handshakeCompleted
public void handshakeCompleted(TLSWrapper wrapper)
- Specified by:
handshakeCompletedin interfaceTLSEventHandler
-
processWaitingPackets
public abstract void processWaitingPackets() throws IOException- Throws:
IOException
-
startSSL
public void startSSL(boolean clientMode, boolean wantClientAuth, boolean needClientAuth) throws IOException- Throws:
IOException
-
getCertificateContainer
public CertificateContainerIfc getCertificateContainer()
-
setCertificateContainer
public void setCertificateContainer(CertificateContainerIfc certificateContainer)
-
startTLS
public void startTLS(boolean clientMode, boolean wantClientAuth, boolean needClientAuth) throws IOException- Throws:
IOException
-
startZLib
public void startZLib(int level)
-
stop
public void stop()
-
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 String getLocalAddress()
-
getTlsUniqueId
public byte[] getTlsUniqueId()
-
getLocalPort
public int getLocalPort()
Method returns local port of opened socket- Returns:
-
getReadCounters
public long[] getReadCounters()
-
getRefObject
public RefObject getRefObject()
-
setRefObject
public void setRefObject(RefObject refObject)
-
getRemoteAddress
public String getRemoteAddress()
Returns a remote IP address for the TCP/IP connection.- Returns:
- a remote IP address for the TCP/IP connection.
-
getSessionData
public ConcurrentMap<String,Object> getSessionData()
-
getSocketInputSize
public int getSocketInputSize()
- Specified by:
getSocketInputSizein interfaceTLSEventHandler
-
getSocketChannel
public SocketChannel getSocketChannel()
-
getStatistics
public void getStatistics(StatisticsList list, boolean reset)
-
getTotalBuffOverflow
public long getTotalBuffOverflow()
-
getTotalBytesReceived
public long getTotalBytesReceived()
-
getTotalBytesSent
public long getTotalBytesSent()
-
getUniqueId
public 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(TrustManager[] trustManager)
-
getPeerCertificate
public Certificate getPeerCertificate()
-
getLocalCertificate
public Certificate getLocalCertificate()
-
byteOrder
protected ByteOrder byteOrder()
-
debug
protected boolean debug(char[] msg)
-
processSocketData
protected abstract void processSocketData() throws IOException- Throws:
IOException
-
readBytes
protected ByteBuffer readBytes() throws IOException
- Throws:
IOException
-
readCompleted
protected void readCompleted()
-
readData
protected char[] readData() throws IOException- Throws:
IOException
-
receivedPackets
protected abstract int receivedPackets()
-
writeBytes
protected void writeBytes(ByteBuffer data)
-
writeData
protected void writeData(String data)
-
isSocketServiceReady
protected boolean isSocketServiceReady()
-
setSocketServiceReady
protected void setSocketServiceReady(boolean value)
-
handleMalformedInput
protected boolean handleMalformedInput(ByteBuffer buffer, CharBuffer cb)
-
isInputBufferEmpty
protected boolean isInputBufferEmpty()
-
getIO
protected IOInterface getIO()
-
-