Class TransactionComm

java.lang.Object
com.iizix.comm.TransactionComm
All Implemented Interfaces:
ITransactionCreator

public class TransactionComm extends Object implements ITransactionCreator
Class to handle the Transaction protocol.
Author:
Christopher Mindus
  • Constructor Details

    • TransactionComm

      public TransactionComm(TransactionCommListener listener, int maxCount, int minLength, int maxLength, boolean isVerbose)
      Creates a new Transaction processor for the server-side web socket implementation for external web servers such as Jetty or GlassFish.
      Parameters:
      listener - Listener for transaction.
      maxCount - Maximum count of strings in the cache, zero = disable write cache: range 10-8192.
      minLength - The minimum length of a string in the cache: range 7 to 64.
      maxLength - The maximum length of a string in the cache: range minLength+1 to 256.
      isVerbose - Verbose tracing output flag.
    • TransactionComm

      public TransactionComm(TransactionCommProps properties, Worker worker, TransactionCommListener listener, SSLEngine engine) throws IOException
      Creates a new Transaction Client Communication channel as UNINITIALIZED.
      Parameters:
      properties - The Transaction properties.
      worker - The worker thread for transaction processing.
      listener - The listener for Transaction events.
      engine - The SSL engine or null for plain connection.
      Throws:
      IOException - For SSL errors.
    • TransactionComm

      public TransactionComm(TransactionCommProps properties, Worker worker, SocketChannel channel, TransactionCommListener listener, WebSocketAcceptor acceptor) throws IOException
      Creates a new Transaction Client Communication channel from a socket channel.
      Parameters:
      properties - The Transaction properties.
      worker - The worker thread for transaction processing.
      channel - The socket channel.
      listener - The listener for Transaction events.
      acceptor - The URI acceptor for WebSocket requests.
      Throws:
      IOException - For I/O exceptions.
  • Method Details

    • setWebSocket

      public IServerWebSocketCommListener setWebSocket(IWebSocketComm comm, Object endPoint)
      Assigns the web socket interface and retrieves the listener for use with external web servers.
      Parameters:
      comm - The comm instance.
      endPoint - The end point.
    • createTransaction

      public final SendTransaction createTransaction()
      Creates a Transaction using a Write Cache. This transaction is then used to write data into it. Be careful only to do it from a single thread as the Write Cache is not thread-safe!
      Specified by:
      createTransaction in interface ITransactionCreator
      Returns:
      The transaction with the WriteCache with parameters specified in the properties.
    • getAttachment

      public final Object getAttachment()
      Gets the attachment object for this communication link.
      Returns:
      Object the attachment assigned by setAttachement(object) method, null for none.
    • setAttachment

      public final void setAttachment(Object attachment)
      Sets the attachment object for this communication link.
      Parameters:
      attachment - The attachment to assign to this communication link or null for no attachment.
    • open

      public void open() throws IOException
      Opens the communication. Do not call this method when using an external web server.
      Throws:
      IOException
    • open

      public void open(boolean noTimeouts) throws IOException
      Opens the communication. Do not call this method when using an external web server.
      Parameters:
      noTimeouts - Connect with debug = no timeouts! This way we can set breakpoints in Eclipse.
      Throws:
      IOException
    • isCompressionSupported

      public boolean isCompressionSupported()
      Flag for supporting software compression on client side.
      Returns:
      The support flag depending on the subProtocol chosen.
    • getState

      public State getState()
      Gets the state of the connection.
      Returns:
      The state.
    • getListener

      public TransactionCommListener getListener()
      Gets the listener of the communications link.
      Returns:
      The listener of communication events.
    • getRemoteAddr

      public String getRemoteAddr()
      Returns the Internet Protocol (IP) address of the client or last proxy that sent the request. The IP address format depends if it is an IPv4 or IPv6 address.
      Returns:
      a String containing the IP address of the client that sent the request.
    • getRemoteHost

      public String getRemoteHost()
      Returns the fully qualified name of the client or the last proxy that sent the request. If the engine cannot or chooses not to resolve the host name (to improve performance), this method returns the dotted-string form of the IP address (if IPv4, colon'ed-string for IPv6).
      Returns:
      a String containing the fully qualified name of the client.
    • getSocketAddress

      public SocketAddress getSocketAddress()
      Returns the remote address to which this channel's socket is connected.

      Where the channel is bound and connected to an Internet Protocol socket address then the return value from this method is of type InetSocketAddress.

      Returns:
      The remote address; null if the channel's socket is not connected.
    • send

      public int send(SendTransaction trans, boolean doCompress) throws IOException
      Sends a transaction.
      Parameters:
      trans - Transaction to send.
      doCompress - Compress transaction flag.
      Returns:
      The byte size sent.
      Throws:
      IOException - For IO errors sending the transaction.
    • send

      public int send(SendTransaction trans, int serial, boolean doCompress) throws IOException
      Sends a transaction.
      Parameters:
      trans - The transaction to send.
      serial - The serial number 0x0001 to 0xFFFF, 0 for none.
      doCompress - Compress transaction flag.
      Returns:
      The byte size sent.
      Throws:
      IOException - For IO errors sending the transaction.
    • sendHeartBeat

      public boolean sendHeartBeat() throws IOException
      Sends a heart-beat.
      Returns:
      true for success, false for failure (e.g. closing state or closed).
      Throws:
      IOException - For send failures.
    • isConnected

      public boolean isConnected()
      Checks if the connection is connected, i.e. not initialize, connecting, closing or closed.
    • isClosed

      public boolean isClosed()
      Checks if the connection is disposed of.
    • close

      public boolean close()
      Call this method to close the socket.
      Returns:
      true if closed, false if already closed.
    • close

      public void close(int code, String reason)
      Closes the connection with the close code and reason.
      Parameters:
      code - A close code: zero for none, otherwise a code 1000 or range 4000 to 4999.
      reason - The reason code, can be null.