Package com.iizix.comm
Class TransactionComm
java.lang.Object
com.iizix.comm.TransactionComm
- All Implemented Interfaces:
ITransactionCreator
Class to handle the Transaction protocol.
- Author:
- Christopher Mindus
Constructor Summary
ConstructorDescriptionTransactionComm
(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, SSLEngine engine) Creates a new Transaction Client Communication channel as UNINITIALIZED.TransactionComm
(TransactionCommProps properties, Worker worker, SocketChannel channel, TransactionCommListener listener, WebSocketAcceptor acceptor) Creates a new Transaction Client Communication channel from a socket channel.Method Summary
Modifier and TypeMethodDescriptionboolean
close()
Call this method to close the socket.void
Closes the connection with the close code and reason.final SendTransaction
Creates a Transaction using a Write Cache.final Object
Gets the attachment object for this communication link.Gets the listener of the communications link.Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.Returns the fully qualified name of the client or the last proxy that sent the request.Returns the remote address to which this channel's socket is connected.getState()
Gets the state of the connection.boolean
isClosed()
Checks if the connection is disposed of.boolean
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
Sends a heart-beat.final void
setAttachment
(Object attachment) Sets the attachment object for this communication link.setWebSocket
(IWebSocketComm comm, Object endPoint) Assigns the web socket interface and retrieves the listener for use with external web servers.
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
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
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 interfaceITransactionCreator
- Returns:
- The transaction with the WriteCache with parameters specified in the properties.
getAttachment
Gets the attachment object for this communication link.- Returns:
- Object the attachment assigned by setAttachement(object) method, null for none.
setAttachment
Sets the attachment object for this communication link.- Parameters:
attachment
- The attachment to assign to this communication link or null for no attachment.
open
Opens the communication. Do not call this method when using an external web server.- Throws:
IOException
open
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
getState
Gets the state of the connection. Do not call this method when using an external web server.getListener
Gets the listener of the communications link.- Returns:
- The listener of communication events.
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
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
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
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
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
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
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.