Package com.iizix.comm
Class TransactionComm
- java.lang.Object
- com.iizix.comm.TransactionComm
 
- All Implemented Interfaces:
- ITransactionCreator
 - public class TransactionComm extends java.lang.Object implements ITransactionCreator Class to handle the Transaction protocol.- Author:
- Christopher Mindus
 
- Constructor Summary- Constructors - Constructor - Description - 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.- TransactionComm(TransactionCommProps properties, Worker worker, TransactionCommListener listener, javax.net.ssl.SSLEngine engine)Creates a new Transaction Client Communication channel as UNINITIALIZED.- TransactionComm(TransactionCommProps properties, Worker worker, java.nio.channels.SocketChannel channel, TransactionCommListener listener, WebSocketAcceptor acceptor)Creates a new Transaction Client Communication channel from a socket channel.
 - Method Summary- All Methods Instance Methods Concrete Methods - Modifier and Type - Method - Description - boolean- close()Call this method to close the socket.- void- close(int code, java.lang.String reason)Closes the connection with the close code and reason.- SendTransaction- createTransaction()Creates a Transaction using a Write Cache.- java.lang.Object- getAttachment()Gets the attachment object for this communication link.- TransactionCommListener- getListener()Gets the listener of the communications link.- java.lang.String- getRemoteAddr()Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.- java.lang.String- getRemoteHost()Returns the fully qualified name of the client or the last proxy that sent the request.- java.net.SocketAddress- getSocketAddress()Returns the remote address to which this channel's socket is connected.- SocketCommNIO.State- getState()Gets the state of the connection.- boolean- isClosed()Checks if the connection is disposed of.- boolean- isConnected()Checks if the connection is connected, i.e.- void- open()Opens the communication.- void- open(boolean noTimeouts)Opens the communication.- int- send(SendTransaction trans, boolean doCompress)Sends a transaction.- int- send(SendTransaction trans, int serial, boolean doCompress)Sends a transaction.- boolean- sendHeartBeat()Sends a heart-beat.- void- setAttachment(java.lang.Object attachment)Sets the attachment object for this communication link.- IServerWebSocketCommListener- setWebSocket(IWebSocketComm comm, java.lang.Object endPoint)Assigns the web socket interface and retrieves the listener for use with external web servers.
 
- Constructor Detail- 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, javax.net.ssl.SSLEngine engine) throws java.io.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:
- java.io.IOException- For SSL errors.
 
 - TransactionComm- public TransactionComm(TransactionCommProps properties, Worker worker, java.nio.channels.SocketChannel channel, TransactionCommListener listener, WebSocketAcceptor acceptor) throws java.io.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:
- java.io.IOException- For I/O exceptions.
 
 
 - Method Detail- setWebSocket- public IServerWebSocketCommListener setWebSocket(IWebSocketComm comm, java.lang.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:
- createTransactionin interface- ITransactionCreator
- Returns:
- The transaction with the WriteCache with parameters specified in the properties.
 
 - getAttachment- public final java.lang.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(java.lang.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 java.io.IOExceptionOpens the communication. Do not call this method when using an external web server.- Throws:
- java.io.IOException
 
 - open- public void open(boolean noTimeouts) throws java.io.IOExceptionOpens 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:
- java.io.IOException
 
 - getState- public SocketCommNIO.State getState() Gets the state of the connection. Do not call this method when using an external web server.
 - getListener- public TransactionCommListener getListener() Gets the listener of the communications link.- Returns:
- The listener of communication events.
 
 - getRemoteAddr- public java.lang.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 java.lang.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 java.net.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; nullif the channel's socket is not connected.
 
 - send- public int send(SendTransaction trans, boolean doCompress) throws java.io.IOException Sends a transaction.- Parameters:
- trans- Transaction to send.
- doCompress- Compress transaction flag.
- Returns:
- The byte size sent.
- Throws:
- java.io.IOException- For IO errors sending the transaction.
 
 - send- public int send(SendTransaction trans, int serial, boolean doCompress) throws java.io.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:
- java.io.IOException- For IO errors sending the transaction.
 
 - sendHeartBeat- public boolean sendHeartBeat() throws java.io.IOExceptionSends a heart-beat.- Returns:
- true for success, false for failure (e.g. closing state or closed).
- Throws:
- java.io.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, java.lang.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.