Class SendTransaction
- All Implemented Interfaces:
- ITransaction
Note: All "synchronization" calls are now removed for performance reasons, so threaded access to a transaction instance should be synchronized by the calling threads.
- Author:
- Christopher Mindus
- See Also:
- Field SummaryFieldsModifier and TypeFieldDescription- static final intMaximum transaction size in bytes = 0x1FFF_FFFF.- Fields inherited from interface com.iizix.ITransaction- DESCR_BOOLEAN, DESCR_BYTE, DESCR_BYTES, DESCR_CHAR, DESCR_DOUBLE, DESCR_FLOAT, DESCR_LONG, DESCR_LONG64, DESCR_NUMBER, DESCR_SHORT, DESCR_SIGNED_INT, DESCR_STRING, DESCR_TRANSACTION, DESCR_UNSIGNED_INT, DESCR_USHORT, TYPE_BOOLEAN, TYPE_BYTE, TYPE_BYTES, TYPE_CHAR, TYPE_DOUBLE, TYPE_FLOAT, TYPE_LONG, TYPE_LONG64, TYPE_NUMBER, TYPE_SHORT, TYPE_SIGNED_INT, TYPE_STRING, TYPE_TRANSACTION, TYPE_UNSIGNED_INT, TYPE_USHORT
- Constructor SummaryConstructorsConstructorDescriptionCreates a new empty transaction that will be filled with streamed data using the append methods.- SendTransaction- (WriteCache writeCache) Creates a new empty transaction that will be filled with streamed data using the append methods.
- Method SummaryModifier and TypeMethodDescription- void- append- (byte[] appendData) Appends a byte array to the outgoing transaction.- void- append- (byte[] appendData, int len) Appends a byte array of a certain length to the outgoing transaction.- void- append- (byte[] appendData, int offset, int len) Appends a byte array of a certain length to the outgoing transaction.- voidAppends a sub-transaction to this send transaction.- void- appendBoolean- (boolean b) Appends a boolean as an 8-bit value.- void- appendByte- (int val) Appends an unsigned byte to the outgoing transaction.- void- appendChar- (char ch) Appends a character to the outgoing transaction as a one-character wide string encoded to bytes as described below.- void- appendDouble- (double val) Appends a double value to the outgoing transaction (64 bits or 8 bytes).- void- appendFloat- (float val) Appends a float value to the outgoing transaction (32 bits or 4 bytes).- int- appendLong- (int val) Appends a 32 bit signed value to the outgoing transaction.- void- appendLong64- (long val) Appends a 64 bit signed value to the outgoing transaction.- void- appendNumber- (double n) Appends a Number (JavaScript) as the shortest possible String.- void- appendShort- (int val) Appends a 16 bit signed value to the outgoing transaction.- void- appendSigned- (int val) Appends an signed integer with the range -0x1FFFFFFF to 0x1FFFFFFF.- void- appendString- (String str) Appends a String to the outgoing transaction.- void- appendString- (String str, boolean useStringCache) Appends a String to the outgoing transaction.- void- appendUnsigned- (int val) Appends an unsigned integer with the range 0x00000000 to 0x3FFFFFFF.- void- appendUShort- (int val) Appends a 16 bit unsigned value to the outgoing transaction.- boolean- close()Closes the send transaction.- dumpWriteCache- (String indent) Dumps the write cache to a String formatted with a certain indent.- protected void- finalize()Deprecated.- byte[]- getData()Gets the byte data of the transaction.- byte[]- getData- (int serial) Gets the byte data of the transaction.- intGets the size of the transaction when appending or sending the transaction.- booleanChecks if this transaction has any data in it.- static booleanReturns if data types are to be included in transactions.- static void- setDatatypeIncluded- (boolean on) Returns if data types are to be included in transactions.- void- setLong- (int val, int pos) Sets a 32 bit signed value to the outgoing transaction at the specified position.- static int- setLongData- (int val, int pos, byte[] data) Fills an array with the long data (4 bytes).
- Field Details- MAX_TRANSACTION_SIZEpublic static final int MAX_TRANSACTION_SIZEMaximum transaction size in bytes = 0x1FFF_FFFF.- See Also:
 
 
- Constructor Details- SendTransactionpublic SendTransaction()Creates a new empty transaction that will be filled with streamed data using the append methods. This transaction will then be sent on to the other part.- This method does not use a write cache. 
- SendTransactionCreates a new empty transaction that will be filled with streamed data using the append methods. This transaction will then be sent on to the other part.- Parameters:
- writeCache- The writeCache, or null for none.
 
 
- Method Details- isDatatypeIncludedpublic static boolean isDatatypeIncluded()Returns if data types are to be included in transactions. This requires an extra byte per data type indicating the type.- Returns:
- true if data types should be added, false otherwise.
 
- setDatatypeIncludedpublic static void setDatatypeIncluded- (boolean on) Returns if data types are to be included in transactions. This requires an extra byte per data type indicating the type.- Parameters:
- on- true if data types should be added, false otherwise.
 
- setLongDatapublic static int setLongData- (int val, int pos, byte[] data) Fills an array with the long data (4 bytes).- Parameters:
- val- The 32 bit value to set in the- data.
- pos- The position (offset) in the- data.
- data- The byte array of data.
- Returns:
- The new position, i.e. pos+4.
 
- closepublic boolean close()Closes the send transaction.- Returns:
- Previous closed state, i.e. falseif transaction was not closed, ortrueif transaction was already closed.
 
- finalizeDeprecated.Finalized transaction. Log an error if the transaction has a write cache but has not been closed. This is a situation that is not acceptable. If so, the transaction is closed after logging.
- getTotalSendSizepublic int getTotalSendSize()Gets the size of the transaction when appending or sending the transaction.- Returns:
- The total bytes count appended.
 
- hasAppendedDatapublic boolean hasAppendedData()Checks if this transaction has any data in it.- Returns:
- true if any data has been appended, false if transaction is new without appended data.
 
- getDatapublic byte[] getData()Gets the byte data of the transaction. The data is a copy of the internal data in the transaction and is of the exact size of the entire transaction package.- When calling this method, the SendTransaction is automatically closed, so no further additions to it can be done, otherwise an IllegalStateException will be thrown. - Returns:
- The entire transaction byte array.
 
- getDatapublic byte[] getData- (int serial) Gets the byte data of the transaction. The data is a copy of the internal data in the transaction and is of the exact size of the entire transaction package.- When calling this method, the SendTransaction is automatically closed, so no further additions to it can be done, otherwise an IllegalStateException will be thrown. - Parameters:
- serial- The serial number 0x0000 to 0xFFFF, -1 for none.
- Returns:
- The byte array of the transaction with an optional serial number.
- Throws:
- IllegalArgumentException- If serial value not -1 or not in range between 0x0000 and 0xFFFF.
 
- appendBytepublic void appendByte- (int val) Appends an unsigned byte to the outgoing transaction.- Parameters:
- val- The 8-bit value to append. Values outside of range are stripped to the 8 first bits, i.e. doing "and 0xFF" on it.
- Throws:
- IllegalStateException- If the transaction is closed or if the transaction has been sealed for further append of new data of it. A transaction becomes sealed if you call- getData()- getData(int)- append(SendTransaction)
 
- appendCharpublic void appendChar- (char ch) Appends a character to the outgoing transaction as a one-character wide string encoded to bytes as described below. The character has, due to Java itself, a code point between U+0000 and U+FFFF, i.e. 16 bits. The additional so called "surrogate pair characters" (two "char" in an array) having the code points U+000000 to U+10FFFF cannot be used here.- The range of legal code points is now U+0000 to U+10FFFF, known as Unicode scalar value. The set of characters from U+0000 to U+FFFF is sometimes referred to as the Basic Multilingual Plane (BMP). Characters whose code points are greater than U+FFFF are called supplementary characters, and not supported here. - Encoding: if the character ASCII (code point) value is up to 254 inclusive (i.e. smaller than 0xFF), a single byte is added, otherwise 3 character. - Parameters:
- ch- The character to append.
- Throws:
- IllegalStateException- If the transaction is closed or if the transaction has been sealed for further append of new data of it. A transaction becomes sealed if you call- getData()- getData(int)- append(SendTransaction)
 
- appendBooleanpublic void appendBoolean- (boolean b) Appends a boolean as an 8-bit value.- Parameters:
- b- The boolean value.
- Throws:
- IllegalStateException- If the transaction is closed or if the transaction has been sealed for further append of new data of it. A transaction becomes sealed if you call- getData()- getData(int)- append(SendTransaction)
 
- appendShortpublic void appendShort- (int val) Appends a 16 bit signed value to the outgoing transaction.- Parameters:
- val- The value.
- Throws:
- IllegalArgumentException- If value range not between -0x8000 and 0x7FFF.
- IllegalStateException- If the transaction is closed or if the transaction has been sealed for further append of new data of it. A transaction becomes sealed if you call- getData()- getData(int)- append(SendTransaction)
 
- appendUShortpublic void appendUShort- (int val) Appends a 16 bit unsigned value to the outgoing transaction.- Parameters:
- val- The value.
- Throws:
- IllegalArgumentException- If value range not between 0x0000 and 0xFFFF.
- IllegalStateException- If the transaction is closed or if the transaction has been sealed for further append of new data of it. A transaction becomes sealed if you call- getData()- getData(int)- append(SendTransaction)
 
- appendLongpublic int appendLong- (int val) Appends a 32 bit signed value to the outgoing transaction.- Parameters:
- val- The value.
- Returns:
- The position in which the long value was written in, in case the value must be filled in afterwards using a call to setLong(size,pos)used for skipping data in case of a transaction part that must be ignored.
- Throws:
- IllegalStateException- If the transaction is closed or if the transaction has been sealed for further append of new data of it. A transaction becomes sealed if you call- getData()- getData(int)- append(SendTransaction)
 
- setLongpublic void setLong- (int val, int pos) Sets a 32 bit signed value to the outgoing transaction at the specified position.- This method is used in conjunction with - getSize()in an outgoing transaction when the long value is used for skipping a transaction on the other end (the long value is the size of data to skip, but the size is not known until all sub-transactions are appended).- Parameters:
- val- the long value.
- pos- position to write the long value.
- Throws:
- IllegalStateException- If the transaction is closed or if the transaction has been sealed for further append of new data of it. A transaction becomes sealed if you call- getData()- getData(int)- append(SendTransaction)
 
- appendLong64public void appendLong64- (long val) Appends a 64 bit signed value to the outgoing transaction.- Parameters:
- val- The value.
- Throws:
- IllegalStateException- If the transaction is closed.
 
- appendSignedpublic void appendSigned- (int val) Appends an signed integer with the range -0x1FFFFFFF to 0x1FFFFFFF. The amount of bytes appended to the transaction varies from 1 to 4 bytes if the absolute value is larger than 0x1F (2 bytes), 0x1FFF (3 bytes) or 0x1F FFFF (4 bytes). If the range is wrong,- IllegalArgumentExceptionis thrown.- Parameters:
- val- the signed integer to append.
- Throws:
- IllegalArgumentException- If value is not in range -0x1FFF_FFFF to 0x1FFF_FFFF.
- IllegalStateException- If the transaction is closed or if the transaction has been sealed for further append of new data of it. A transaction becomes sealed if you call- getData()- getData(int)- append(SendTransaction)
 
- appendUnsignedpublic void appendUnsigned- (int val) Appends an unsigned integer with the range 0x00000000 to 0x3FFFFFFF. The amount of bytes appended to the transaction varies from 1 to 4 bytes if the value is larger than 0x3F (2 bytes), 0x3FFF (3 bytes) or 0x3FFFFF (4 bytes). If the range is wrong,- IllegalArgumentExceptionis thrown.- Parameters:
- val- The unsigned integer to append.
- Throws:
- IllegalStateException- If the transaction is closed.
- IllegalArgumentException- If value is not in range -0x1FFF_FFFF to 0x1FFF_FFFF.
 
- appendFloatpublic void appendFloat- (float val) Appends a float value to the outgoing transaction (32 bits or 4 bytes).- Parameters:
- val- The value.
- Throws:
- IllegalStateException- If the transaction is closed or if the transaction has been sealed for further append of new data of it. A transaction becomes sealed if you call- getData()- getData(int)- append(SendTransaction)
 
- appendDoublepublic void appendDouble- (double val) Appends a double value to the outgoing transaction (64 bits or 8 bytes).- Parameters:
- val- The value.
- Throws:
- IllegalStateException- If the transaction is closed or if the transaction has been sealed for further append of new data of it. A transaction becomes sealed if you call- getData()- getData(int)- append(SendTransaction)
 
- appendNumberpublic void appendNumber- (double n) Appends a Number (JavaScript) as the shortest possible String.- Parameters:
- n- The number.
- Throws:
- IllegalStateException- If the transaction is closed or if the transaction has been sealed for further append of new data of it. A transaction becomes sealed if you call- getData()- getData(int)- append(SendTransaction)
 
- appendStringAppends a String to the outgoing transaction. The appended string will use the String Cache (if present, and if the String meets the cache conditions).- Parameters:
- str- The string.
- Throws:
- IllegalArgumentException- If the string length is longer than 0xFF_FFFF (268_435_455), or the UTF-8 encoded string is longer than 0xFF_FFFF (268_435_455 bytes).
- IllegalStateException- If the transaction is closed or if the transaction has been sealed for further append of new data of it. A transaction becomes sealed if you call- getData()- getData(int)- append(SendTransaction)
 
- appendStringAppends a String to the outgoing transaction.- The appended string will use the String Cache depending on the "useStringCache" flag (and if the String Cache present, and the String meets the cache conditions). - Parameters:
- str- The string.
- useStringCache- Flag to avoid using the cache if false, true to use the write cache (if present).
- Throws:
- IllegalArgumentException- If the string length is longer than 0xFF_FFFF (268_435_455), or the UTF-8 encoded string is longer than 0xFF_FFFF (268_435_455 bytes).
- IllegalStateException- If the transaction is closed or if the transaction has been sealed for further append of new data of it. A transaction becomes sealed if you call- getData()- getData(int)- append(SendTransaction)
 
- appendAppends a sub-transaction to this send transaction. The send transaction as parameter will first be closed, so no further writing to it is possible.- Parameters:
- t- Another transaction to append.
- Throws:
- IllegalArgumentException- If the transaction appended does not contain data, or if the total length of the resulting transaction data exceeds 0x3FFF_FFFF.
 
- appendpublic void append- (byte[] appendData) Appends a byte array to the outgoing transaction.- Parameters:
- appendData- The array of bytes to append.
- Throws:
- IllegalStateException- If the transaction is closed or if the transaction has been sealed for further append of new data of it. A transaction becomes sealed if you call- getData()- getData(int)- append(SendTransaction)
 
- appendpublic void append- (byte[] appendData, int len) Appends a byte array of a certain length to the outgoing transaction.- Parameters:
- appendData- The array of bytes to append.
- len- The length to append (can be less than the total length of the array).
- Throws:
- IllegalStateException- If the transaction is closed or if the transaction has been sealed for further append of new data of it. A transaction becomes sealed if you call- getData()- getData(int)- append(SendTransaction)
 
- appendpublic void append- (byte[] appendData, int offset, int len) Appends a byte array of a certain length to the outgoing transaction.- Parameters:
- appendData- The array of bytes to append.
- offset- Starting offset for append in the array.
- len- The byte length to append.
- Throws:
- IllegalStateException- If the transaction is closed or if the transaction has been sealed for further append of new data of it. A transaction becomes sealed if you call- getData()- getData(int)- append(SendTransaction)
 
- dumpWriteCacheDumps the write cache to a String formatted with a certain indent.- Parameters:
- indent- The string indent for each line. The indent is preceded with '\n' for each line not being the first line.
- Returns:
- A formatted string for the write cache, or *** NO WRITE CACHE ***when a WriteCache instance is not assigned to the transaction.