tigase.net
Class IOService

java.lang.Object
  extended by tigase.net.IOService
All Implemented Interfaces:
java.util.concurrent.Callable<IOService>
Direct Known Subclasses:
XMPPIOService

public abstract class IOService
extends java.lang.Object
implements java.util.concurrent.Callable<IOService>

IOService offers thread thread safe call() method execution, however you must be prepared that other methods can be called simultanously like stop(), getProtocol() or isConnected().
It is recomended that developers extend AbsractServerService rather then implement ServerService interface directly.

If you directly implement ServerService interface you must take care about SocketChannel I/O, queueing tasks, processing results and thread safe execution of call() method. If you however extend IOService 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 in parseData(char[] data) method.

Created: Tue Sep 28 23:00:34 2004

Version:
$Rev: 1284 $
Author:
Artur Hefczyc

Field Summary
static java.lang.String HOSTNAME_KEY
           
static 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.
 
Constructor Summary
IOService()
           
 
Method Summary
 void accept(java.nio.channels.SocketChannel socketChannel)
          Method accept is used to perform
 IOService call()
          Method run is used to perform
 ConnectionType connectionType()
           
protected  boolean debug(char[] msg)
          Describe debug method here.
protected  boolean debug(java.lang.String msg, java.lang.String prefix)
          Describe debug method here.
 void forceStop()
           
 java.lang.String getDataReceiver()
           
 long getLastTransferTime()
          This method returns the time of last transfer in any direction through this service.
 java.lang.String getLocalAddress()
           
 long[] getReadCounters()
           
 java.lang.String getRemoteAddress()
           
 java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Object> getSessionData()
           
 java.nio.channels.SocketChannel getSocketChannel()
          Method getSocketChannel is used to perform
 java.lang.String getUniqueId()
           
 long[] getWriteCounters()
           
 boolean isConnected()
          Describe isConnected method here.
protected abstract  void processSocketData()
           
abstract  void processWaitingPackets()
           
protected  void readCompleted()
           
protected  char[] readData()
          Describe readData method here.
protected abstract  int receivedPackets()
           
 void setDataReceiver(java.lang.String address)
           
 void setIOServiceListener(IOServiceListener sl)
           
 void setSessionData(java.util.Map<java.lang.String,java.lang.Object> props)
           
 void setSSLId(java.lang.String id)
           
 void startSSL(boolean clientMode)
           
 void startTLS(boolean clientMode)
           
 void stop()
          Describe stop method here.
 boolean waitingToSend()
           
protected  void writeData(java.lang.String data)
          Describe writeData method here.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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

PORT_TYPE_PROP_KEY

public static final java.lang.String PORT_TYPE_PROP_KEY
See Also:
Constant Field Values

HOSTNAME_KEY

public static final java.lang.String HOSTNAME_KEY
See Also:
Constant Field Values
Constructor Detail

IOService

public IOService()
Method Detail

getReadCounters

public long[] getReadCounters()

getWriteCounters

public long[] getWriteCounters()

setDataReceiver

public void setDataReceiver(java.lang.String address)

getDataReceiver

public java.lang.String getDataReceiver()

setSSLId

public void setSSLId(java.lang.String id)

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.


startSSL

public void startSSL(boolean clientMode)
              throws java.io.IOException
Throws:
java.io.IOException

startTLS

public void startTLS(boolean clientMode)
              throws java.io.IOException
Throws:
java.io.IOException

setIOServiceListener

public void setIOServiceListener(IOServiceListener sl)

getUniqueId

public java.lang.String getUniqueId()

connectionType

public ConnectionType connectionType()

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)

isConnected

public boolean isConnected()
Describe isConnected method here.

Returns:
a boolean value

getRemoteAddress

public java.lang.String getRemoteAddress()

getLocalAddress

public java.lang.String getLocalAddress()

accept

public void accept(java.nio.channels.SocketChannel socketChannel)
            throws java.io.IOException
Method accept is used to perform

Parameters:
socketChannel - a SocketChannel value
Throws:
java.io.IOException

getSocketChannel

public java.nio.channels.SocketChannel getSocketChannel()
Method getSocketChannel is used to perform

Returns:
a SocketChannel value

stop

public void stop()
Describe stop method here.

Throws:
java.io.IOException - if an error occurs

forceStop

public void forceStop()

call

public IOService call()
               throws java.io.IOException
Method run is used to perform

Specified by:
call in interface java.util.concurrent.Callable<IOService>
Throws:
java.io.IOException

processWaitingPackets

public abstract void processWaitingPackets()
                                    throws java.io.IOException
Throws:
java.io.IOException

processSocketData

protected abstract void processSocketData()
                                   throws java.io.IOException
Throws:
java.io.IOException

receivedPackets

protected abstract int receivedPackets()

readCompleted

protected void readCompleted()

readData

protected char[] readData()
                   throws java.io.IOException
Describe readData method here.

Returns:
a char[] value
Throws:
java.io.IOException - if an error occurs

waitingToSend

public boolean waitingToSend()

writeData

protected void writeData(java.lang.String data)
Describe writeData method here.

Parameters:
data - a String value
Throws:
java.io.IOException - if an error occurs

debug

protected boolean debug(char[] msg)
Describe debug method here.

Parameters:
msg - a char[] value
Returns:
a boolean value

debug

protected boolean debug(java.lang.String msg,
                        java.lang.String prefix)
Describe debug method here.

Parameters:
msg - a String value
Returns:
a boolean value


Copyright © 2008 Tigase. All Rights Reserved.