Class TransformerDataImpl
- java.lang.Object
-
- com.caplin.transformer.module.datasrc.TransformerDataImpl
-
- All Implemented Interfaces:
DSData
,DSPacket
,DSSerializable
,TransformerData
,TransformerFlags
,java.lang.Iterable<DSField>
- Direct Known Subclasses:
TransformerContainerImpl
,TransformerPermissionImpl
,TransformerRecordImpl
public class TransformerDataImpl extends java.lang.Object implements TransformerData
Implementation of the TransformerData interface.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
modCount
Counts the number of times a new field is added to, or a field is removed from, the update.-
Fields inherited from interface com.caplin.datasrc.interfaces.DSData
CONTAINER_TYPE, F_AUTH_UPDATE, F_AUTHGLOBAL, F_CHANGEDFIELDS, F_CLEAR_PERMISSIONS, F_CLEAR_TYPE2, F_CLEAR_TYPE3, F_CREATEOBJECT, F_CREATEPARENT, F_DELETE_PERMISSION, F_FILTER_TYPE2, F_FILTER_TYPE3, F_IMAGE, F_NONACTIVE, GENERIC_TYPE, NEWS_TYPE, PAGE_TYPE, PERMISSION_TYPE, RECORD_TYPE, STORY_TYPE, TYPE2_RECORD_TYPE, TYPE3_RECORD_TYPE, UNKNOWN_TYPE
-
Fields inherited from interface com.caplin.transformer.module.TransformerFlags
MAINTAIN_TIMESTAMP, NO_FLAGS, NO_PERSISTENCE, PUBLISH_TO_PEERS, SILENT_SEND, STORE_IN_CACHE
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
TransformerDataImpl(long dsDataPointer)
Constructor is protected to prevent a TransformerData being instantiated except by the DSFactory class.protected
TransformerDataImpl(long dsDataPointer, boolean freeDsDataPointer)
Constructor is protected to prevent a TransformerData being instantiated except by the DSFactory class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBinaryData(int fieldNumber, byte value)
Adds the byte value for the specified field number.void
addBinaryData(int fieldNumber, byte[] value)
Adds the byte array value for the specified field number.void
addBinaryData(int fieldNumber, double value)
Adds the double value for the specified field number.void
addBinaryData(int fieldNumber, float value)
Adds the float value for the specified field number.void
addBinaryData(int fieldNumber, int value)
Adds the integer value for the specified field number.void
addBinaryData(int fieldNumber, long value)
Adds the long value for the specified field number.void
addBinaryData(int fieldNumber, short value)
Adds the short value for the specified field number.void
addBinaryData(int fieldNumber, java.lang.String value)
Adds the String value for the specified field number.void
addData(int fieldNumber, char value)
Adds the String representation of the character value for the specified field number.void
addData(int fieldNumber, char[] value)
Adds the String representation of the character array for the specified field number.void
addData(int fieldNumber, double value)
Adds the String representation of the double value for the specified field number.void
addData(int fieldNumber, float value)
Adds the String representation of the float value for the specified field number.void
addData(int fieldNumber, int value)
Adds the String representation of the integer value for the specified field number.void
addData(int fieldNumber, long value)
Adds the String representation of the long value for the specified field number.void
addData(int fieldNumber, java.lang.String value)
Adds the String value for the specified field number.void
addData(DSField dsField)
Adds the DSField.protected void
addString(int fieldNumber, java.lang.String value)
Adds the String value for the specified field number with the default flag 0.protected void
addString(int fieldNumber, java.lang.String value, int flags)
Adds the String value for the specified field number with the specified flags.void
clearFields()
Removes all the fields.int
count()
Gets the number of fields that are present in this packet.java.util.Enumeration<DSField>
elements()
Returns an enumeration of the fields for this DSData.void
finalize()
Frees the memory for the underlying C ds_data struct stored within the Transformer core.long
getDSDataPointer()
Gets the pointer to the C ds_data struct that holds the state information for the update.DSField
getFieldByFieldNumber(int fieldNumber)
Gets the first occurrence of the field with the specified field number.DSField
getFieldByFieldNumber(int fieldNumber, int occurrence)
Gets the specified occurrence of the field with the specified field number.int
getFlags()
Gets the flags that are going to be sent with this packet.java.util.Enumeration<?>
getKeys()
Returns asEnumeration
ofIntegers
indicating the field number .ObjectType
getObjectType()
Gets the update's object type.int
getSequenceNumber()
Gets the update's sequence number.java.lang.String
getSubject()
Gets this object's subject.int
getType()
Gets this object's type.java.util.Enumeration<?>
getValues()
Returns asEnumeration
ofStrings
indicating the field values .java.util.Iterator<DSField>
iterator()
Returns an iterator of the fields for this DSData.int
merge(TransformerData transformerDataToMerge)
Merges the fields from the specified TransformerData with those in this TransformerData.boolean
removeField(DSField dsField)
Removes the specified field from the DSData.void
send()
Sends the update to the Transformer core.void
send(int flags)
Sends the update to the Transformer core.void
sendDirect()
Invokes thesend
method.void
sendToPeer(int peer)
Invokes thesend
method.void
setFlags(int flags)
Sets the flags to be sent with this packet.void
setSubject(java.lang.String subject)
Sets this object's subject.void
setType(int type)
Sets the object type of this DSData to the specified value.void
setType(ObjectType objectType)
Sets the update's object type to the specified type.byte[]
toBytes()
Returns null.boolean
updateData(int fieldNumber, java.lang.String value)
Sets the value of the first occurrence for the specified field number.boolean
updateData(int fieldNumber, java.lang.String value, int occurrence)
Sets the value of the specified occurrence for the specified field number.
-
-
-
Constructor Detail
-
TransformerDataImpl
protected TransformerDataImpl(long dsDataPointer)
Constructor is protected to prevent a TransformerData being instantiated except by the DSFactory class.
A TransformerData created with this constructor will be responsible for freeing the memory for the underlying C ds_data struct.
This is equivalent to calling TransformerData(dsDataPointer, true).
- Parameters:
dsDataPointer
- The pointer to the C ds_data struct that holds the state information for the update.
-
TransformerDataImpl
protected TransformerDataImpl(long dsDataPointer, boolean freeDsDataPointer)
Constructor is protected to prevent a TransformerData being instantiated except by the DSFactory class.
- Parameters:
dsDataPointer
- The pointer to the C ds_data struct that holds the state information for the update.freeDsDataPointer
- true if the TransformerData is responsible for freeing up the memory for the C ds_data struct, or false if the Transformer core is responsible.
-
-
Method Detail
-
getDSDataPointer
public long getDSDataPointer()
Description copied from interface:TransformerData
Gets the pointer to the C ds_data struct that holds the state information for the update. This method is used internally by the TransformerData.
Once the update has been sent, pointer is nulled down, and this method will throw a IllegalStateException.
- Specified by:
getDSDataPointer
in interfaceTransformerData
- Returns:
- The pointer to the ds_data struct.
-
setFlags
public void setFlags(int flags)
Description copied from interface:DSData
Sets the flags to be sent with this packet.
The flags that can be set are:
DSData.F_CREATEOBJECT
DSData.F_CREATEPARENT
DSData.F_IMAGE
DSData.F_NONACTIVE
DSData.F_AUTH_UPDATE
DSData.F_FILTER_TYPE2
DSData.F_FILTER_TYPE3
DSData.F_CLEAR_TYPE2
DSData.F_CLEAR_TYPE3
Multiple flags can be set by bitwise ORing them together (e.g. F_CREATEOBJECT|F_CREATEPARENT|F_IMAGE).
-
getFlags
public int getFlags()
Description copied from interface:DSData
Gets the flags that are going to be sent with this packet.
-
setType
public void setType(int type)
Description copied from interface:DSData
Sets the object type of this DSData to the specified value.
Valid object types are:
-
setType
public void setType(ObjectType objectType)
Description copied from interface:TransformerData
Sets the update's object type to the specified type.
- Specified by:
setType
in interfaceTransformerData
- Parameters:
objectType
- The type of object.
-
getType
public int getType()
Description copied from interface:DSData
Gets this object's type.
-
getObjectType
public ObjectType getObjectType()
Description copied from interface:TransformerData
Gets the update's object type.
- Specified by:
getObjectType
in interfaceTransformerData
- Returns:
- The ObjectType that represents the object type for this update.
-
getSequenceNumber
public int getSequenceNumber()
Description copied from interface:TransformerData
Gets the update's sequence number.
- Specified by:
getSequenceNumber
in interfaceTransformerData
- Returns:
- the sequence number of the update.
-
setSubject
public void setSubject(java.lang.String subject)
Description copied from interface:DSData
Sets this object's subject.
- Specified by:
setSubject
in interfaceDSData
- Parameters:
subject
- The subject, or object, name.
-
getSubject
public java.lang.String getSubject()
Description copied from interface:DSData
Gets this object's subject.
- Specified by:
getSubject
in interfaceDSData
- Returns:
- The subject, or object, name.
-
count
public int count()
Description copied from interface:DSData
Gets the number of fields that are present in this packet.
-
elements
public java.util.Enumeration<DSField> elements()
Description copied from interface:DSData
Returns an enumeration of the fields for this DSData. Each field is represented by a
DSField
.
-
iterator
public java.util.Iterator<DSField> iterator()
Description copied from interface:DSData
Returns an iterator of the fields for this DSData. Each field is represented by a
DSField
.
-
getKeys
public java.util.Enumeration<?> getKeys()
Description copied from interface:DSData
Returns as
Enumeration
ofIntegers
indicating the field number .
-
getValues
public java.util.Enumeration<?> getValues()
Description copied from interface:DSData
Returns as
Enumeration
ofStrings
indicating the field values .
-
getFieldByFieldNumber
public DSField getFieldByFieldNumber(int fieldNumber)
Description copied from interface:DSData
Gets the first occurrence of the field with the specified field number.
If there are three occurrences of the field 12, with values "75", "75.5" and "75.25", then calling getFieldByFieldNumber(12) will return the field that contains the value "75".
This is equivalent to calling getFieldByFieldNumber(fieldNumber, 0).
- Specified by:
getFieldByFieldNumber
in interfaceDSData
- Parameters:
fieldNumber
- The field identifier number.- Returns:
- The field for the first occurrence of the field number, or null if the specified field is not found.
-
getFieldByFieldNumber
public DSField getFieldByFieldNumber(int fieldNumber, int occurrence)
Description copied from interface:DSData
Gets the specified occurrence of the field with the specified field number.
If there are three occurrences of the field 12, with values "75", "75.5" and "75.25", then calling getFieldByFieldNumber(12, 2) will return the field that contains the value "75.25".
- Specified by:
getFieldByFieldNumber
in interfaceDSData
- Parameters:
fieldNumber
- The field identifier number.occurrence
- The occurrence of the field to be got. The first field is occurrence 0, the next occurrence 1, and so on.- Returns:
- The field for the specified occurrence of the field number, or null if the specified field is not found.
-
removeField
public boolean removeField(DSField dsField)
Description copied from interface:DSData
Removes the specified field from the DSData.
- Specified by:
removeField
in interfaceDSData
- Parameters:
dsField
- The field to remove.- Returns:
- true if the field was successfully removed, or false if the field has already been removed.
- Throws:
java.util.ConcurrentModificationException
- If the any modifications have been made to the fields since the specified field was obtained. This prevents any unexpected behaviour from this method.java.lang.NullPointerException
- If the dsField argument is null.
-
updateData
public boolean updateData(int fieldNumber, java.lang.String value, int occurrence)
Sets the value of the specified occurrence for the specified field number. The occurrence parameter is ignored in this version.
If there are three occurrences of the field 12, "75", "75.5" and "75.25", then calling updateData(12, "76", 2) will change occurrences to be "76", "75.5" and "75.25".
- Specified by:
updateData
in interfaceDSData
- Parameters:
fieldNumber
- The field identifier number.value
- The new value for the field.occurrence
- The occurrence of the field to be updated. The first field is occurrence 0, the next occurrence 1, and so on.- Returns:
- Always true. If the specified field does not exist, it will be added.
- Throws:
java.lang.NullPointerException
- If the value argument is null.
-
updateData
public boolean updateData(int fieldNumber, java.lang.String value)
Description copied from interface:DSData
Sets the value of the first occurrence for the specified field number.
If there are three occurrences of the field 12, "75", "75.5" and "75.25", then calling updateData(12, "76") will change occurrences to be "76", "75.5" and "75.25".
This is equivalent to calling updateData(fieldNumber, value, 0).
- Specified by:
updateData
in interfaceDSData
- Parameters:
fieldNumber
- The field identifier number.value
- The new value for the field.- Returns:
- Always true. If the specified field does not exist, it will be added.
- Throws:
java.lang.NullPointerException
- If the value argument is null.
-
merge
public int merge(TransformerData transformerDataToMerge)
Merges the fields from the specified TransformerData with those in this TransformerData. If a field does not exist within this TransformerData then the field will be added to it. If the field already exists, then its value will be updated.
If a field exists multiple times (as occurs with type 2 and type 3 records), only the first occurrence will be merged.
- Specified by:
merge
in interfaceTransformerData
- Parameters:
transformerDataToMerge
- The TransformerData from which the fields should be merged from.- Returns:
- The number of fields that were updated.
-
send
public void send()
Sends the update to the Transformer core. The data will be cached by the core and will be published to the DataSource peers, as well as to any Transformer modules that have subscribed to it.
As soon as the update is sent, its memory is freed by the Transformer core. Any further attempts to use the object will result in IllegalStateExceptions being thrown. If the update needs to be sent, then further changes made to the object, the
DSFactory.createTransformerData(TransformerData)
method should be used to create a copy of the object before the update is sent.This method is equivalent to calling send(STORE_IN_CACHE|PUBLISH_TO_PEERS).
-
send
public void send(int flags)
Sends the update to the Transformer core. The specified flags will determine what the core does with the update.
As soon as the update is sent, its memory is freed by the Transformer core. Any further attempts to use the object will result in IllegalStateExceptions being thrown. If the update needs to be sent, then further changes made to the object, the
DSFactory.createTransformerData(TransformerData)
method should be used to create a copy of the object before the update is sent.The valid flags are:
- NO_FLAGS
- STORE_IN_CACHE
- PUBLISH_TO_PEERS
- SILENT_SEND
- MAINTAIN_TIMESTAMP
- Specified by:
send
in interfaceTransformerData
- Parameters:
flags
- The flags that should be passed to the Transformer core to tell it how to process the update.- Throws:
java.lang.IllegalStateException
- If the update has already been sent.
-
sendDirect
public void sendDirect()
Invokes the
send
method.- Specified by:
sendDirect
in interfaceDSPacket
-
sendToPeer
public void sendToPeer(int peer)
Invokes the
send
method.- Specified by:
sendToPeer
in interfaceDSPacket
- Parameters:
peer
- theDataSource
peer.
-
toBytes
public byte[] toBytes()
Returns null.
- Specified by:
toBytes
in interfaceDSSerializable
- Returns:
null
.
-
clearFields
public void clearFields()
Description copied from interface:DSData
Removes all the fields.
- Specified by:
clearFields
in interfaceDSData
-
addData
public void addData(int fieldNumber, java.lang.String value)
Description copied from interface:DSData
Adds the String value for the specified field number.
-
addData
public void addData(int fieldNumber, char value)
Description copied from interface:DSData
Adds the String representation of the character value for the specified field number.
-
addData
public void addData(int fieldNumber, char[] value)
Description copied from interface:DSData
Adds the String representation of the character array for the specified field number.
-
addData
public void addData(int fieldNumber, double value)
Description copied from interface:DSData
Adds the String representation of the double value for the specified field number.
Warning: the underlying implementation will not guarantee any accuracy beyond 12 decimal places. If greater precision is required, the value should be formatted separately and added using the
DSData.addData(int, String)
method.
-
addData
public void addData(int fieldNumber, float value)
Description copied from interface:DSData
Adds the String representation of the float value for the specified field number.
Warning: the underlying implementation will not guarantee any accuracy beyond 6 decimal places. If greater precision is required, the value should be formatted separately and added using the
DSData.addData(int, String)
method.
-
addData
public void addData(int fieldNumber, int value)
Description copied from interface:DSData
Adds the String representation of the integer value for the specified field number.
-
addData
public void addData(int fieldNumber, long value)
Description copied from interface:DSData
Adds the String representation of the long value for the specified field number.
-
addData
public void addData(DSField dsField)
Description copied from interface:DSData
Adds the DSField.
-
addBinaryData
public void addBinaryData(int fieldNumber, byte value)
Description copied from interface:DSData
Adds the byte value for the specified field number. This method Base64 encodes the value before storing it.
- Specified by:
addBinaryData
in interfaceDSData
- Parameters:
fieldNumber
- The field identifier number.value
- The byte value to be stored in the field.
-
addBinaryData
public void addBinaryData(int fieldNumber, short value)
Description copied from interface:DSData
Adds the short value for the specified field number. This method Base64 encodes the value before storing it.
- Specified by:
addBinaryData
in interfaceDSData
- Parameters:
fieldNumber
- The field identifier number.value
- The value to be stored in the field.
-
addBinaryData
public void addBinaryData(int fieldNumber, int value)
Description copied from interface:DSData
Adds the integer value for the specified field number. This method Base64 encodes the value before storing it.
- Specified by:
addBinaryData
in interfaceDSData
- Parameters:
fieldNumber
- The field identifier number.value
- The value to be stored in the field.
-
addBinaryData
public void addBinaryData(int fieldNumber, long value)
Description copied from interface:DSData
Adds the long value for the specified field number. This method Base64 encodes the value before storing it.
- Specified by:
addBinaryData
in interfaceDSData
- Parameters:
fieldNumber
- The field identifier number.value
- The value to be stored in the field.
-
addBinaryData
public void addBinaryData(int fieldNumber, float value)
Description copied from interface:DSData
Adds the float value for the specified field number. This method Base64 encodes the value before storing it.
- Specified by:
addBinaryData
in interfaceDSData
- Parameters:
fieldNumber
- The field identifier number.value
- The value to be stored in the field.
-
addBinaryData
public void addBinaryData(int fieldNumber, double value)
Description copied from interface:DSData
Adds the double value for the specified field number. This method Base64 encodes the value before storing it.
- Specified by:
addBinaryData
in interfaceDSData
- Parameters:
fieldNumber
- The field identifier number.value
- The value to be stored in the field.
-
addBinaryData
public void addBinaryData(int fieldNumber, byte[] value)
Description copied from interface:DSData
Adds the byte array value for the specified field number. This method Base64 encodes the value before storing it.
- Specified by:
addBinaryData
in interfaceDSData
- Parameters:
fieldNumber
- The field identifier number.value
- The array of bytes to be stored in the field.- Throws:
java.lang.NullPointerException
- If the value argument is null.
-
addBinaryData
public void addBinaryData(int fieldNumber, java.lang.String value)
Description copied from interface:DSData
Adds the String value for the specified field number. This method Base64 encodes the value before storing it.
- Specified by:
addBinaryData
in interfaceDSData
- Parameters:
fieldNumber
- The field identifier number.value
- The value to be stored in the field.- Throws:
java.lang.NullPointerException
- If the value argument is null.
-
addString
protected void addString(int fieldNumber, java.lang.String value)
Adds the String value for the specified field number with the default flag 0.
- Parameters:
fieldNumber
- The field identifier number.value
- The value to be stored in the field.- Throws:
java.lang.NullPointerException
- If the value argument is null.
-
addString
protected void addString(int fieldNumber, java.lang.String value, int flags)
Adds the String value for the specified field number with the specified flags.
- Parameters:
fieldNumber
- The field identifier number.value
- The value to be stored in the field.flags
- The flags to apply to the field.- Throws:
java.lang.NullPointerException
- If the value argument is null.
-
finalize
public void finalize()
Frees the memory for the underlying C ds_data struct stored within the Transformer core. If the
send(int)
method has been invoked, this method does nothing.- Overrides:
finalize
in classjava.lang.Object
-
-