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
  Direct Known Subclasses:
    XMPPIOService

      public abstract class IOService<RefObject>
      extends Object
      implements Callable<IOService<?>>, TLSEventHandler

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

  If you directly implement `ServerService` interface you must take care about `SocketChannel` I/O, queuing 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$
  Author:
    Artur Hefczyc

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected CharBuffer` | `cb` Field description
    `static String` | `CERT_CHECK_RESULT` Field description
    `protected CharsetDecoder` | `decoder` Field description
    `protected CharsetEncoder` | `encoder` Field description
    `static String` | `HOSTNAME_KEY` Field description
    `protected byte[]` | `partialCharacterBytes` The saved partial bytes for multi-byte UTF-8 characters between reads
    `static String` | `PORT_TYPE_PROP_KEY` Field description
    `static String` | `SESSION_ID_KEY` This is key used to store session ID in temporary session data storage.
    `static String` | `SSL_PROTOCOLS_KEY` Field description

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `IOService()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `accept(SocketChannel socketChannel)` Method `accept` is used to perform
    `protected ByteOrder` | `byteOrder()` Method description
    `IOService<?>` | `call()` Method `run` is used to perform
    `ConnectionType` | `connectionType()` Method description
    `protected boolean` | `debug(char[] msg)` Describe `debug` method here.
    `protected boolean` | `debug(String msg, String prefix)` Describe `debug` method here.
    `void` | `forceStop()` Method description
    `long` | `getBuffOverflow(boolean reset)` Method description
    `long` | `getBytesReceived(boolean reset)` Method description
    `long` | `getBytesSent(boolean reset)` Method description
    `tigase.xmpp.JID` | `getConnectionId()`
    `tigase.xmpp.JID` | `getDataReceiver()` Method description
    `long` | `getLastTransferTime()` This method returns the time of last transfer in any direction through this service.
    `String` | `getLocalAddress()` Method description
    `List<String>` | `getPeersJIDsFromCert()` Method description
    `long[]` | `getReadCounters()` Method description
    `RefObject` | `getRefObject()` Method description
    `String` | `getRemoteAddress()` Returns a remote IP address for the TCP/IP connection.
    `ConcurrentMap<String,Object>` | `getSessionData()` Method description
    `SocketChannel` | `getSocketChannel()` Method `getSocketChannel` is used to perform
    `void` | `getStatistics(StatisticsList list, boolean reset)` Method description
    `long` | `getTotalBuffOverflow()` Method description
    `long` | `getTotalBytesReceived()` Method description
    `long` | `getTotalBytesSent()` Method description
    `String` | `getUniqueId()` Method description
    `long[]` | `getWriteCounters()` Method description
    `TrustManager[]` | `getX509TrustManagers()` Method description
    `void` | `handshakeCompleted(TLSWrapper wrapper)` Method description
    `boolean` | `isConnected()` Describe `isConnected` method here.
    `protected boolean` | `isInputBufferEmpty()` Method description
    `protected abstract void` | `processSocketData()` Method description
    `abstract void` | `processWaitingPackets()` Method description
    `protected ByteBuffer` | `readBytes()` Method description
    `protected void` | `readCompleted()` Method description
    `protected char[]` | `readData()` Describe `readData` method here.
    `protected abstract int` | `receivedPackets()` Method description
    `void` | `setConnectionId(tigase.xmpp.JID connectionId)`
    `void` | `setDataReceiver(tigase.xmpp.JID address)` Method description
    `void` | `setIOServiceListener(IOServiceListener<IOService<RefObject>> sl)` Method description
    `void` | `setRefObject(RefObject refObject)` Method description
    `void` | `setSessionData(Map<String,Object> props)` Method description
    `void` | `setX509TrustManagers(TrustManager[] trustManager)` Method description
    `void` | `startSSL(boolean clientMode, boolean wantClientAuth)` Method description
    `void` | `startTLS(boolean clientMode, boolean wantClientAuth)` Method description
    `void` | `startZLib(int level)` Method description
    `void` | `stop()` Describe `stop` method here.
    `String` | `toString()` Method description
    `boolean` | `waitingToRead()` Method description
    `boolean` | `waitingToSend()` Method description
    `int` | `waitingToSendSize()` Method description
    `protected void` | `writeBytes(ByteBuffer data)` Method description
    `protected void` | `writeData(String data)` Describe `writeData` method here.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### CERT_CHECK_RESULT

          public static final String CERT_CHECK_RESULT

      Field description
      See Also:
        Constant Field Values

    - #### HOSTNAME_KEY

          public static final String HOSTNAME_KEY

      Field description
      See Also:
        Constant Field Values

    - #### PORT_TYPE_PROP_KEY

          public static final String PORT_TYPE_PROP_KEY

      Field description
      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

      Field description
      See Also:
        Constant Field Values

    - #### partialCharacterBytes

          protected byte[] partialCharacterBytes

      The saved partial bytes for multi-byte UTF-8 characters between reads

    - #### encoder

          protected CharsetEncoder encoder

      Field description

    - #### decoder

          protected CharsetDecoder decoder

      Field description

    - #### cb

          protected CharBuffer cb

      Field description

  - ### Constructor Detail

    - #### IOService

          public IOService()

  - ### Method Detail

    - #### accept

          public void accept(SocketChannel socketChannel)
                      throws IOException

      Method `accept` is used to perform
      Parameters:
        `socketChannel` - a `SocketChannel` value
      Throws:
        `IOException`

    - #### call

          public IOService<?> call()
                            throws IOException

      Method `run` is used to perform
      Specified by:
        `call` in interface `Callable<IOService<?>>`
      Returns:
      Throws:
        `IOException`

    - #### connectionType

          public ConnectionType connectionType()

      Method description
      Returns:

    - #### forceStop

          public void forceStop()

      Method description

    - #### handshakeCompleted

          public void handshakeCompleted(TLSWrapper wrapper)

      Method description
      Specified by:
        `handshakeCompleted` in interface `TLSEventHandler`
      Parameters:
        `wrapper` -

    - #### processWaitingPackets

          public abstract void processWaitingPackets()
                                              throws IOException

      Method description
      Throws:
        `IOException`

    - #### startSSL

          public void startSSL(boolean clientMode,
                      boolean wantClientAuth)
                        throws IOException

      Method description
      Parameters:
        `clientMode` -
      Throws:
        `IOException`

    - #### startTLS

          public void startTLS(boolean clientMode,
                      boolean wantClientAuth)
                        throws IOException

      Method description
      Parameters:
        `clientMode` -
      Throws:
        `IOException`

    - #### startZLib

          public void startZLib(int level)

      Method description
      Parameters:
        `level` -

    - #### stop

          public void stop()

      Describe `stop` method here.

    - #### toString

          public String toString()

      Method description
      Overrides:
        `toString` in class `Object`
      Returns:

    - #### waitingToRead

          public boolean waitingToRead()

      Method description
      Returns:

    - #### waitingToSend

          public boolean waitingToSend()

      Method description
      Returns:

    - #### waitingToSendSize

          public int waitingToSendSize()

      Method description
      Returns:

    - #### getBuffOverflow

          public long getBuffOverflow(boolean reset)

      Method description
      Parameters:
        `reset` -
      Returns:

    - #### getBytesReceived

          public long getBytesReceived(boolean reset)

      Method description
      Parameters:
        `reset` -
      Returns:

    - #### getBytesSent

          public long getBytesSent(boolean reset)

      Method description
      Parameters:
        `reset` -
      Returns:

    - #### getConnectionId

          public tigase.xmpp.JID getConnectionId()

      Returns:
        the connectionId

    - #### getDataReceiver

          public tigase.xmpp.JID getDataReceiver()

      Method description
      Returns:

    - #### 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.
      Returns:

    - #### getLocalAddress

          public String getLocalAddress()

      Method description
      Returns:

    - #### getPeersJIDsFromCert

          public List<String> getPeersJIDsFromCert()

      Method description
      Returns:

    - #### getReadCounters

          public long[] getReadCounters()

      Method description
      Returns:

    - #### getRefObject

          public RefObject getRefObject()

      Method description
      Returns:

    - #### 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()

      Method description
      Returns:

    - #### getSocketChannel

          public SocketChannel getSocketChannel()

      Method `getSocketChannel` is used to perform
      Returns:
        a `SocketChannel` value

    - #### getStatistics

          public void getStatistics(StatisticsList list,
                           boolean reset)

      Method description
      Parameters:
        `list` -
        `reset` -

    - #### getTotalBuffOverflow

          public long getTotalBuffOverflow()

      Method description
      Returns:

    - #### getTotalBytesReceived

          public long getTotalBytesReceived()

      Method description
      Returns:

    - #### getTotalBytesSent

          public long getTotalBytesSent()

      Method description
      Returns:

    - #### getUniqueId

          public String getUniqueId()

      Method description
      Returns:

    - #### getWriteCounters

          public long[] getWriteCounters()

      Method description
      Returns:

    - #### getX509TrustManagers

          public TrustManager[] getX509TrustManagers()

      Method description
      Returns:

    - #### isConnected

          public boolean isConnected()

      Describe `isConnected` method here.
      Returns:
        a `boolean` value

    - #### setConnectionId

          public void setConnectionId(tigase.xmpp.JID connectionId)

      Parameters:
        `connectionId` - the connectionId to set

    - #### setDataReceiver

          public void setDataReceiver(tigase.xmpp.JID address)

      Method description
      Parameters:
        `address` -

    - #### setIOServiceListener

          public void setIOServiceListener(IOServiceListener<IOService<RefObject>> sl)

      Method description
      Parameters:
        `sl` -

    - #### setRefObject

          public void setRefObject(RefObject refObject)

      Method description
      Parameters:
        `refObject` -

    - #### setSessionData

          public void setSessionData(Map<String,Object> props)

      Method description
      Parameters:
        `props` -

    - #### setX509TrustManagers

          public void setX509TrustManagers(TrustManager[] trustManager)

      Method description
      Parameters:
        `trustManager` -

    - #### byteOrder

          protected ByteOrder byteOrder()

      Method description
      Returns:

    - #### debug

          protected boolean debug(char[] msg)

      Describe `debug` method here.
      Parameters:
        `msg` - a `char[]` value
      Returns:
        a `boolean` value

    - #### debug

          protected boolean debug(String msg,
                      String prefix)

      Describe `debug` method here.
      Parameters:
        `msg` - a `String` value
        `prefix` -
      Returns:
        a `boolean` value

    - #### processSocketData

          protected abstract void processSocketData()
                                             throws IOException

      Method description
      Throws:
        `IOException`

    - #### readBytes

          protected ByteBuffer readBytes()
                                  throws IOException

      Method description
      Returns:
      Throws:
        `IOException`

    - #### readCompleted

          protected void readCompleted()

      Method description

    - #### readData

          protected char[] readData()
                             throws IOException

      Describe `readData` method here.
      Returns:
        a `char[]` value
      Throws:
        `IOException` - if an error occurs

    - #### receivedPackets

          protected abstract int receivedPackets()

      Method description
      Returns:

    - #### writeBytes

          protected void writeBytes(ByteBuffer data)

      Method description
      Parameters:
        `data` -

    - #### writeData

          protected void writeData(String data)

      Describe `writeData` method here.
      Parameters:
        `data` - a `String` value

    - #### isInputBufferEmpty

          protected boolean isInputBufferEmpty()

      Method description
      Returns:

Copyright © 2013 Tigase. All rights reserved.