OSMQ
v2.0.1

osmq.messages
Class MessageBean

java.lang.Object
  extended byosmq.util.ImmutableImpl
      extended byosmq.messages.MessageBean
All Implemented Interfaces:
java.lang.Cloneable, Immutable, KeyedData, Message, MessageAttributes, java.io.Serializable
Direct Known Subclasses:
BinaryMessageBean

public class MessageBean
extends ImmutableImpl
implements Message, java.lang.Cloneable, java.io.Serializable

A MessageBean is an implementation of the Message interface, and an alternative to the DataSetMessageBean implementation (DATASET). It has header attributes, but unlike the DataSetMessage, the body is not necessarily a record with multiple elements, but rather contains any array of bytes.

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface osmq.messages.MessageAttributes
CONTENT_FORMAT, CORRELATION_ID, DATA_KEY, ORIGINATOR, RECIPIENT, SEND_TIMESTAMP, SENDER_SEQ, TOPIC, TOTAL_ATTRIBUTES, TRANS_ADD, TRANS_DELETE, TRANS_UPDATE, TRANSACTION, TYPE
 
Constructor Summary
MessageBean()
           
MessageBean(byte[] body)
           
MessageBean(java.lang.String bodytext)
           
 
Method Summary
 byte[] _duplicate(byte[] original)
           
 java.lang.Object clone()
           
 byte[] getClientBytes()
          Returns the client (body) data as an array of bytes.
 java.lang.String getClientText()
          Returns the client (body) data as a text String
 long getCorrelationNumber()
          Gets the identifier used to identify a group of transactions as related.
 java.lang.String getCorrelationString()
           
 DataRecord getDataRecord()
          Returns the client (body) data as a DataRecord.
 char getFormat()
          Identifies the body format as either text or binary.
 MessageHeader getHeader()
          Returns the message header values.
 byte[] getHeaderBytes()
          Returns the header data as an array of bytes.
 java.lang.String getKey()
          Returns the unique identifier for the data contained in the message.
 int getKeyAsInt()
           
 byte[] getMessageAsBytes()
          Returns the message (header and body) as an array of bytes
 java.lang.String getMessageAsString()
          Returns the message (header and body) as a text String.
 java.lang.String getOriginator()
          Returns the identifier of the message sender (publisher).
 java.lang.String getRecipient()
          Returns the identifier of the message recipient, or null if the message is intended for all subscriber to the message topic.
 long getSequenceNumber()
          Returns the relative sequence number of this message.
 long getTimeStamp()
          Returns a timestamp indicating when the message was sent.
 java.lang.String getTopic()
          Returns the topic of the message.
 java.lang.String getTransaction()
          Returns the identifier of the event or activity that caused the transaction to be generated.
 char getTransactionAsChar()
          Returns the first character of the event identifer, or a null character if there is no event identifer
 char getType()
          Identifies whether the message type is a NOTIFICATION or REQUEST .
 boolean hasAssignedCorrelationNumber()
          Determines if there is a correlation identifier value.
 boolean hasAssignedKey()
          Determines if there is a key value identifier.
 boolean hasAssignedOriginator()
          Determines whether a position has a value (versus null)
 boolean hasAssignedRecipient()
          Determine if there is a recipient identifier value.
 boolean hasAssignedTopic()
          Determines if there is a topic identifier value.
static void main(java.lang.String[] args)
           
 void setClientBytes(byte[] data)
          Sets the client (body) data from values in a message body.
 void setClientText(java.lang.String s)
          Sets the body values to a String.
 void setCorrelationNumber(long n)
          Sets the identifier used to identify a group of transactions as related.
 void setCorrelationString(java.lang.String s)
          Sets the identifier used to identify a group of transactions as related.
 void setDataRecord(DataRecord record)
          Sets the body values to a DataRecord.
 void setFormat(char t)
          Sets the attributes that identifies the type of data contained in the message body.
 void setHeader(MessageHeader header)
          Sets the message header values.
 void setHeaderBytes(byte[] value)
          Sets the header data from an array of bytes.
 void setImmutable()
          Sets the message state to immutable. The values of an immutable message cannot be modified.
 void setKey(java.lang.String s)
          Sets the unique identifier for the data contained in the message.
 void setKeyAsInt(int n)
           
 void setOriginator(java.lang.String t)
          Sets the identifier of the message sender (publisher).
 void setRecipient(java.lang.String t)
          Sets the unique recipient that will receive the message.
 void setSequenceNumber(long n)
          Sets the sequence number for this message.
 void setTimeStamp(long n)
          Sets the time the message was publisherd.
 void setTopic(java.lang.String topic)
          Sets the topic that identifies the message contents.
 void setTransaction(java.lang.String t)
          Sets the transaction identifer.
 void setTransactionAsChar(char c)
           
 void setType(char t)
          Sets the event type.
 
Methods inherited from class osmq.util.ImmutableImpl
isImmutable
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface osmq.util.Immutable
isImmutable
 

Constructor Detail

MessageBean

public MessageBean()

MessageBean

public MessageBean(java.lang.String bodytext)

MessageBean

public MessageBean(byte[] body)
Method Detail

setImmutable

public void setImmutable()
Sets the message state to immutable. The values of an immutable message cannot be modified. Any attempt to modify those values will result in an ImmutableException being thrown.

Specified by:
setImmutable in interface Immutable
Overrides:
setImmutable in class ImmutableImpl
See Also:
ImmutableException

setHeader

public void setHeader(MessageHeader header)
Sets the message header values.

Throws:
ImmutableDataException - if the message is immutable.

getHeader

public MessageHeader getHeader()
Returns the message header values.


getHeaderBytes

public byte[] getHeaderBytes()
Returns the header data as an array of bytes.


setHeaderBytes

public void setHeaderBytes(byte[] value)
Sets the header data from an array of bytes.

Throws:
ImmutableDataException - if the message is immutable.

getClientBytes

public byte[] getClientBytes()
Returns the client (body) data as an array of bytes.


setClientBytes

public void setClientBytes(byte[] data)
Sets the client (body) data from values in a message body. The message format will be set to BINARY.

Throws:
ImmutableDataException - if the message is immutable.

getClientText

public java.lang.String getClientText()
Returns the client (body) data as a text String


setClientText

public void setClientText(java.lang.String s)
Sets the body values to a String. The message format will be set to TEXT.

Throws:
ImmutableDataException - if the message is immutable.

getMessageAsString

public java.lang.String getMessageAsString()
Returns the message (header and body) as a text String.


setDataRecord

public void setDataRecord(DataRecord record)
Sets the body values to a DataRecord. The message format will be set to DATASET.

Throws:
ImmutableDataException - if the message is immutable.

getDataRecord

public DataRecord getDataRecord()
Returns the client (body) data as a DataRecord.


getTopic

public java.lang.String getTopic()
Returns the topic of the message.

Specified by:
getTopic in interface MessageAttributes
Returns:
A string containing the topic. The topic defines the message contents for a subscriber (number of elements and the data type of each element).

setTopic

public void setTopic(java.lang.String topic)
Sets the topic that identifies the message contents.

Specified by:
setTopic in interface MessageAttributes
Throws:
ImmutableDataException - if the message is immutable.

getKey

public java.lang.String getKey()
Returns the unique identifier for the data contained in the message. (This "key" is relative to the the topic.)

Specified by:
getKey in interface MessageAttributes
Returns:
A string containing the unique identifier.

setKey

public void setKey(java.lang.String s)
Sets the unique identifier for the data contained in the message. (This "key" is relative to the the topic.)

Specified by:
setKey in interface MessageAttributes
Parameters:
s - the unique key value

setKeyAsInt

public void setKeyAsInt(int n)
Specified by:
setKeyAsInt in interface MessageAttributes

getKeyAsInt

public int getKeyAsInt()
Specified by:
getKeyAsInt in interface MessageAttributes

getTransaction

public java.lang.String getTransaction()
Returns the identifier of the event or activity that caused the transaction to be generated. This is a value that is based on the topic.

Standard events used for down-stream subscribers that maintain databases are DataSetMessage.EVENT_ADD, DataSetMessage.EVENT_DELETE and DataSetMessage.and EVENT_UPDATE.

Specified by:
getTransaction in interface MessageAttributes
Returns:
A string containing the transaction event.

getTransactionAsChar

public char getTransactionAsChar()
Returns the first character of the event identifer, or a null character if there is no event identifer

Specified by:
getTransactionAsChar in interface MessageAttributes
Returns:
A char containing the transaction event.

setTransaction

public void setTransaction(java.lang.String t)
Sets the transaction identifer. This identifier is useful to subscribers that perform database updates based on topical messages. (The identifiers typically translate into add/update/delete functions)

Specified by:
setTransaction in interface MessageAttributes
Parameters:
t - the transaction value

setTransactionAsChar

public void setTransactionAsChar(char c)
Specified by:
setTransactionAsChar in interface MessageAttributes

getCorrelationNumber

public long getCorrelationNumber()
Gets the identifier used to identify a group of transactions as related. The relationship is likely a unit-of-work that resulted in tranaction-related topics being generated. This is an optional header attribute.

Specified by:
getCorrelationNumber in interface MessageAttributes
Returns:
An int containing the correlation identifier.

setCorrelationNumber

public void setCorrelationNumber(long n)
Sets the identifier used to identify a group of transactions as related. The relationship is likely a unit-of-work that resulted in tranaction-related topics being generated. This is an optional header attribute, and is set automatically by the Publisher.

Specified by:
setCorrelationNumber in interface MessageAttributes
Parameters:
n - the correlation identifier

getCorrelationString

public java.lang.String getCorrelationString()
Specified by:
getCorrelationString in interface MessageAttributes

setCorrelationString

public void setCorrelationString(java.lang.String s)
Sets the identifier used to identify a group of transactions as related.

Specified by:
setCorrelationString in interface MessageAttributes
Parameters:
s - the correlation identifier
See Also:
setCorrelationNumber(long)

getOriginator

public java.lang.String getOriginator()
Returns the identifier of the message sender (publisher). The sender identifies a unique client process (instance).

Specified by:
getOriginator in interface MessageAttributes
Returns:
A string containing the message sender.

setOriginator

public void setOriginator(java.lang.String t)
Sets the identifier of the message sender (publisher). The sender identifies a unique client process (instance).

Normally, this value is not set by an application, and defaults to the client identifier used to attach to the message broker.

Specified by:
setOriginator in interface MessageAttributes
Parameters:
t - the message originator (sender)

getRecipient

public java.lang.String getRecipient()
Returns the identifier of the message recipient, or null if the message is intended for all subscriber to the message topic.

Specified by:
getRecipient in interface MessageAttributes
Returns:
A string containing the recipient identifier.

setRecipient

public void setRecipient(java.lang.String t)
Sets the unique recipient that will receive the message. If a recipient value is set, only that recipient will receive the message. (Point-to-point messaging). Setting the recipient should be reserved for clients requesting a service (type of TYPE_REQUEST) and for OLTP systems that receive a request that is being rejected. In the latter case, the OLTP system would send a point-to-point rejection message to the originator of the request.

Specified by:
setRecipient in interface MessageAttributes

getType

public char getType()
Identifies whether the message type is a NOTIFICATION or REQUEST .

Specified by:
getType in interface MessageAttributes
Returns:
A char containing either the value TYPE_NOTIFICATION or TYPE_REQUEST.
See Also:
MessageAttributes.setType(char)

setType

public void setType(char t)
Sets the event type. The message type is the category of event that caused a message to be generated. Standard types include MessageAttributes.TYPE_NOTIFICATION and MessageAttributes.TYPE_REQUEST.

TYPE_NOTIFICATION messages are published by OLTP systems after it commits a transaction. (Batch applications can also publisher TYPE_NOTIFICATION messages.)

TYPE_REQUEST messages are point-to-point routed client requests for service. (Point-to-point messages are sent to a single recipient, and have the recipient identified in the message header, verus publish-subscribe messages that have no recipeint and are published to all subscribers to the message topic.)

Specified by:
setType in interface MessageAttributes
See Also:
setRecipient(String t)

setTimeStamp

public void setTimeStamp(long n)
Sets the time the message was publisherd. This function is called by the message publisher after client submits the message for delivery.

NOTE This value should be set by the underlying client middleware, and not the application.

Specified by:
setTimeStamp in interface MessageAttributes
Parameters:
n - the time as a long.

setSequenceNumber

public void setSequenceNumber(long n)
Sets the sequence number for this message.

NOTE This value should be set by the underlying client middleware, and not the application.

Specified by:
setSequenceNumber in interface MessageAttributes

getTimeStamp

public long getTimeStamp()
Returns a timestamp indicating when the message was sent.

Specified by:
getTimeStamp in interface MessageAttributes
Returns:
A long containing the time in milli-seconds.

getSequenceNumber

public long getSequenceNumber()
Returns the relative sequence number of this message. When a message is sent by a client, it denotes the relative sending sequence. When a message is received, it denotes the relative sequence of all messages fetched by the recipient, regardless of the sender.

Specified by:
getSequenceNumber in interface MessageAttributes
Returns:
A long identifying the message sequence.

getFormat

public char getFormat()
Identifies the body format as either text or binary.

Specified by:
getFormat in interface MessageAttributes

setFormat

public void setFormat(char t)
Description copied from interface: MessageAttributes
Sets the attributes that identifies the type of data contained in the message body.

Valid values include

FORMAT_UNKNOWN ('U')

FORMAT_TEXT ('T')

FORMAT_DATASET ('D')

FORMAT_BINARY ('B')

DataSetMessages default to a format of FORMAT_DATASET.

Specified by:
setFormat in interface MessageAttributes

hasAssignedRecipient

public boolean hasAssignedRecipient()
Determine if there is a recipient identifier value.

Specified by:
hasAssignedRecipient in interface MessageAttributes
Returns:
true if there is a non-null recipient identifier.

hasAssignedTopic

public boolean hasAssignedTopic()
Determines if there is a topic identifier value.

Specified by:
hasAssignedTopic in interface MessageAttributes
Returns:
true if there is a non-null topic identifier.

hasAssignedCorrelationNumber

public boolean hasAssignedCorrelationNumber()
Determines if there is a correlation identifier value.

Specified by:
hasAssignedCorrelationNumber in interface MessageAttributes
Returns:
true if there is a non-null numeric correlation identifier.

hasAssignedKey

public boolean hasAssignedKey()
Determines if there is a key value identifier.

Specified by:
hasAssignedKey in interface MessageAttributes
Returns:
true if there is a non-null key identifier.

hasAssignedOriginator

public boolean hasAssignedOriginator()
Determines whether a position has a value (versus null)

Specified by:
hasAssignedOriginator in interface MessageAttributes
Returns:
true of there is a non-null value at position p, else false
Throws:
java.lang.ArrayIndexOutOfBoundsException - if p is not a valid element position.

_duplicate

public byte[] _duplicate(byte[] original)

getMessageAsBytes

public byte[] getMessageAsBytes()
Returns the message (header and body) as an array of bytes

Specified by:
getMessageAsBytes in interface Message

clone

public java.lang.Object clone()
Specified by:
clone in interface MessageAttributes

main

public static void main(java.lang.String[] args)

(c) 2000 - 2003 MQue Systems
All Rights Reserved