Package spread
Class SpreadMessage
- java.lang.Object
-
- spread.SpreadMessage
-
public class SpreadMessage extends java.lang.ObjectA SpreadMessage object represents either an incoming or outgoing spread message. An outgoing message is one being sent withSpreadConnection.multicast(SpreadMessage). An incoming message is one received withSpreadConnection.receive(). To send a message on a spread connection, first create a message object:SpreadMessage message = new SpreadMessage();
Then set the data with either
setData(byte[]),setObject(Serializable), ordigest(Serializable):message.setData(data);
Select which group(s) to send the message to with
addGroup(SpreadGroup):message.setGroup(group);
When the message is read to be sent, send it with
SpreadConnection.multicast(SpreadMessage):connection.multicast(message);
-
-
Field Summary
Fields Modifier and Type Field Description protected static intAGREED_MESSprotected static intCAUSAL_MESSprotected static intCAUSED_BY_DISCONNECTprotected static intCAUSED_BY_JOINprotected static intCAUSED_BY_LEAVEprotected static intCAUSED_BY_NETWORKprotected intcontentprivate static intCONTENT_DATAprivate static intCONTENT_DIGESTprivate static intCONTENT_OBJECTprivate byte[]dataprotected java.io.ByteArrayOutputStreamdigestBytesprotected java.io.ObjectOutputStreamdigestOutputprivate booleanendianMismatchprotected static intFIFO_MESSprotected java.util.Vectorgroupsprotected static intGROUPS_MESSprotected static intJOIN_MESSprotected static intKILL_MESSprotected static intLEAVE_MESSprotected static intMEMBERSHIP_MESSprivate MembershipInfomembershipInfoprivate booleanoutgoingprotected static intREG_MEMB_MESSprotected static intREGULAR_MESSprotected static intREJECT_MESSprotected static intRELIABLE_MESSprotected static intSAFE_MESSprotected static intSELF_DISCARDprivate SpreadGroupsenderprivate intserviceTypeprotected static intTRANSITION_MESSprivate shorttypeprotected static intUNRELIABLE_MESS
-
Constructor Summary
Constructors Modifier Constructor Description SpreadMessage()Initializes a new outgoing SpreadMessage object.protectedSpreadMessage(int serviceType, java.util.Vector groups, SpreadGroup sender, byte[] data, short type, boolean endianMismatch, MembershipInfo membershipInfo)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddGroup(java.lang.String group)Adds this group to the list this message will be sent to.voidaddGroup(SpreadGroup group)Adds this group to the list this message will be sent to.voidaddGroups(java.lang.String[] groups)Adds these groups to the list this message will be sent to.voidaddGroups(SpreadGroup[] groups)Adds these groups to the list this message will be sent to.java.lang.Objectclone()Creates a copy of this message.voiddigest(java.io.Serializable object)Adds this message to the digest.byte[]getData()Gets the message data as an array of bytes.java.util.VectorgetDigest()Gets the message data as a digest.booleangetEndianMismatch()Checks for an endian mismatch.SpreadGroup[]getGroups()Gets an array containing the SpreadGroup's to which this message was sent.MembershipInfogetMembershipInfo()Get the membership info for this message.java.lang.ObjectgetObject()Gets the message data as a java object.SpreadGroupgetSender()Gets the message sender's private group.intgetServiceType()Get the message's service type.shortgetType()Gets the message type.booleanisAgreed()Checks if this is an agreed message.booleanisCausal()Checks if this is a causal message.booleanisFifo()Checks if this is a fifo message.booleanisIncoming()Check if this is an incoming message.booleanisMembership()Checks if this is a membership message.protected static booleanisMembership(int serviceType)booleanisOutgoing()Check if this is an outgoing message.booleanisRegular()Checks if this is a regular message.protected static booleanisRegular(int serviceType)booleanisReject()Checks if this is a rejected message.protected static booleanisReject(int serviceType)booleanisReliable()Checks if this is a reliable message.booleanisSafe()Checks if this is a safe message.booleanisSelfDiscard()Checks if this is a self-discard message.booleanisUnreliable()Checks if this is an unreliable message.voidsetAgreed()Sets the message to be agreed.voidsetCausal()Sets the message to be causal.voidsetData(byte[] data)Sets the message's data to this array of bytes.voidsetFifo()Sets the message to be fifo.voidsetObject(java.io.Serializable object)Sets the message's data to this object, in serialized form.voidsetReliable()Sets the message to be reliable.voidsetSafe()Sets the message to be safe.voidsetSelfDiscard(boolean selfDiscard)IfselfDiscardis true, sets the self discard flag for the message, otherwise clears the flag.voidsetServiceType(int serviceType)Sets the service type.voidsetType(short type)Set's the message type.voidsetUnreliable()Sets the message to be unreliable.
-
-
-
Field Detail
-
UNRELIABLE_MESS
protected static final int UNRELIABLE_MESS
- See Also:
- Constant Field Values
-
RELIABLE_MESS
protected static final int RELIABLE_MESS
- See Also:
- Constant Field Values
-
FIFO_MESS
protected static final int FIFO_MESS
- See Also:
- Constant Field Values
-
CAUSAL_MESS
protected static final int CAUSAL_MESS
- See Also:
- Constant Field Values
-
AGREED_MESS
protected static final int AGREED_MESS
- See Also:
- Constant Field Values
-
SAFE_MESS
protected static final int SAFE_MESS
- See Also:
- Constant Field Values
-
REGULAR_MESS
protected static final int REGULAR_MESS
- See Also:
- Constant Field Values
-
SELF_DISCARD
protected static final int SELF_DISCARD
- See Also:
- Constant Field Values
-
REG_MEMB_MESS
protected static final int REG_MEMB_MESS
- See Also:
- Constant Field Values
-
TRANSITION_MESS
protected static final int TRANSITION_MESS
- See Also:
- Constant Field Values
-
CAUSED_BY_JOIN
protected static final int CAUSED_BY_JOIN
- See Also:
- Constant Field Values
-
CAUSED_BY_LEAVE
protected static final int CAUSED_BY_LEAVE
- See Also:
- Constant Field Values
-
CAUSED_BY_DISCONNECT
protected static final int CAUSED_BY_DISCONNECT
- See Also:
- Constant Field Values
-
CAUSED_BY_NETWORK
protected static final int CAUSED_BY_NETWORK
- See Also:
- Constant Field Values
-
MEMBERSHIP_MESS
protected static final int MEMBERSHIP_MESS
- See Also:
- Constant Field Values
-
REJECT_MESS
protected static final int REJECT_MESS
- See Also:
- Constant Field Values
-
JOIN_MESS
protected static final int JOIN_MESS
- See Also:
- Constant Field Values
-
LEAVE_MESS
protected static final int LEAVE_MESS
- See Also:
- Constant Field Values
-
KILL_MESS
protected static final int KILL_MESS
- See Also:
- Constant Field Values
-
GROUPS_MESS
protected static final int GROUPS_MESS
- See Also:
- Constant Field Values
-
CONTENT_DATA
private static final int CONTENT_DATA
- See Also:
- Constant Field Values
-
CONTENT_OBJECT
private static final int CONTENT_OBJECT
- See Also:
- Constant Field Values
-
CONTENT_DIGEST
private static final int CONTENT_DIGEST
- See Also:
- Constant Field Values
-
outgoing
private boolean outgoing
-
content
protected int content
-
serviceType
private int serviceType
-
groups
protected java.util.Vector groups
-
sender
private SpreadGroup sender
-
data
private byte[] data
-
type
private short type
-
endianMismatch
private boolean endianMismatch
-
membershipInfo
private MembershipInfo membershipInfo
-
digestBytes
protected java.io.ByteArrayOutputStream digestBytes
-
digestOutput
protected java.io.ObjectOutputStream digestOutput
-
-
Constructor Detail
-
SpreadMessage
protected SpreadMessage(int serviceType, java.util.Vector groups, SpreadGroup sender, byte[] data, short type, boolean endianMismatch, MembershipInfo membershipInfo)
-
SpreadMessage
public SpreadMessage()
Initializes a new outgoing SpreadMessage object. By default the message is reliable.
-
-
Method Detail
-
isIncoming
public boolean isIncoming()
Check if this is an incoming message. This is true if it has been received withSpreadConnection.receive().- Returns:
- true if this in an incoming message
-
isOutgoing
public boolean isOutgoing()
Check if this is an outgoing message. This is true if this is a message being sent withSpreadConnection.multicast(SpreadMessage).- Returns:
- true if this is an outgoing message
-
getServiceType
public int getServiceType()
Get the message's service type. The service type is a bitfield representing the type of message.- Returns:
- the service-type
-
isRegular
public boolean isRegular()
Checks if this is a regular message. If true, the get*() functions can be used to obtain more information about the message.- Returns:
- true if this is a regular message
- See Also:
getGroups(),getSender(),getData(),getObject(),getDigest(),getType(),getEndianMismatch()
-
isRegular
protected static boolean isRegular(int serviceType)
-
isReject
public boolean isReject()
Checks if this is a rejected message. If true, the get*() methods can be used to get more information on which message or join/leave was rejected.- Returns:
- true if this is a rejected message
- See Also:
getGroups(),getSender(),getData(),getObject(),getDigest(),getType(),getEndianMismatch()
-
isReject
protected static boolean isReject(int serviceType)
-
isMembership
public boolean isMembership()
Checks if this is a membership message. If true,getMembershipInfo()can be used to get more information on the membership change.- Returns:
- true if this is a membership message
- See Also:
getMembershipInfo()
-
isMembership
protected static boolean isMembership(int serviceType)
-
isUnreliable
public boolean isUnreliable()
Checks if this is an unreliable message.- Returns:
- true if this is an unreliable message
-
isReliable
public boolean isReliable()
Checks if this is a reliable message.- Returns:
- true if this is a reliable message
-
isFifo
public boolean isFifo()
Checks if this is a fifo message.- Returns:
- true if this is a fifo message
-
isCausal
public boolean isCausal()
Checks if this is a causal message.- Returns:
- true if this is a causal message
-
isAgreed
public boolean isAgreed()
Checks if this is an agreed message.- Returns:
- true if this is an agreed message
-
isSafe
public boolean isSafe()
Checks if this is a safe message.- Returns:
- true if this is a safe message
-
isSelfDiscard
public boolean isSelfDiscard()
Checks if this is a self-discard message.- Returns:
- true if this is a self-discard message
-
setServiceType
public void setServiceType(int serviceType)
Sets the service type. The service type is a bitfield representing the type of message.- Parameters:
serviceType- the new service type
-
setUnreliable
public void setUnreliable()
Sets the message to be unreliable.
-
setReliable
public void setReliable()
Sets the message to be reliable. This is the default type for a new outgoing message.
-
setFifo
public void setFifo()
Sets the message to be fifo.
-
setCausal
public void setCausal()
Sets the message to be causal.
-
setAgreed
public void setAgreed()
Sets the message to be agreed.
-
setSafe
public void setSafe()
Sets the message to be safe.
-
setSelfDiscard
public void setSelfDiscard(boolean selfDiscard)
IfselfDiscardis true, sets the self discard flag for the message, otherwise clears the flag. If the self discard flag is set, the message will not be received at the connection it is multicast on.- Parameters:
selfDiscard- if true, set the self discard flag, if false, clear the self discard flag
-
getGroups
public SpreadGroup[] getGroups()
Gets an array containing the SpreadGroup's to which this message was sent.- Returns:
- the groups to which this message was sent
-
getSender
public SpreadGroup getSender()
Gets the message sender's private group. This can be used to uniquely identify the sender on the connection this message was received from or to send a reply to the sender.
-
getData
public byte[] getData()
Gets the message data as an array of bytes. This can be used no matter how the message was sent, but is usually used when the message was sent usingsetData(byte[])or from an application using the C library.- Returns:
- the message data
- See Also:
setData(byte[])
-
getObject
public java.lang.Object getObject() throws SpreadExceptionGets the message data as a java object. The message data should have been set usingsetObject(Serializable). Regardless of the type of object passed tosetObject(Serializable), this method returns an object of type Object, so it must be cast to the correct type.- Returns:
- the message data as an object
- Throws:
SpreadException- if there is an error reading the object- See Also:
setObject(Serializable)
-
getDigest
public java.util.Vector getDigest() throws SpreadExceptionGets the message data as a digest. The message data should have been set usingdigest(Serializable). This method returns a Vector containing all of the objects passed todigest(Serializable), in the order they were passed.- Returns:
- the message data as a list of objects
- Throws:
SpreadException- if there is an error reading the objects- See Also:
digest(Serializable)
-
getType
public short getType()
Gets the message type. The message type is set withsetType(short).- Returns:
- the message type
- See Also:
setType(short)
-
getEndianMismatch
public boolean getEndianMismatch()
Checks for an endian mismatch. If there is an endian mismatch between the machine that sent the message and the local machine, this is true. This is a signal to the application so that it can handle endian flips in its message data. Aside from the message data, spread handles all other endian mismatches itself (for example, the message type).- Returns:
- true if there is an endian mismatch
-
addGroup
public void addGroup(SpreadGroup group)
Adds this group to the list this message will be sent to. When the message is multicast, all members of this group will receive it.- Parameters:
group- a group to send this message to
-
addGroups
public void addGroups(SpreadGroup[] groups)
Adds these groups to the list this message will be sent to. When the message is multicast, all members of these groups will receive it.- Parameters:
groups- a list of groups to send this message to
-
addGroup
public void addGroup(java.lang.String group)
Adds this group to the list this message will be sent to. When the message is multicast, all members of this group will receive it.- Parameters:
group- a group to send this message to
-
addGroups
public void addGroups(java.lang.String[] groups)
Adds these groups to the list this message will be sent to. When the message is multicast, all members of these groups will receive it.- Parameters:
groups- a list of groups to send this message to
-
setData
public void setData(byte[] data)
Sets the message's data to this array of bytes. This cancels any previous calls tosetData(byte[]),setObject(Serializable),digest(Serializable).- Parameters:
data- the new message data- See Also:
getData()
-
setObject
public void setObject(java.io.Serializable object) throws SpreadExceptionSets the message's data to this object, in serialized form. The object must support the Serializable interface to use this method. This cancels any previous calls tosetData(byte[]),setObject(Serializable),digest(Serializable). This should not be used if an application using the C library needs to read this message.- Parameters:
object- the object to set the data to- Throws:
SpreadException- See Also:
getObject()
-
digest
public void digest(java.io.Serializable object) throws SpreadExceptionAdds this message to the digest. The object must support the Serializable interface to use this method. This cancels any previous calls tosetData(byte[])orsetObject(Serializable). This should not be used if an application using the C library needs to read this message. When the message is sent, all of the objects that have been passed to this method get sent as the message data.- Parameters:
object- the object to add to the digets- Throws:
SpreadException- See Also:
getDigest()
-
setType
public void setType(short type)
Set's the message type. This is a 16-bit integer that can be used by the application to identify the message.- Parameters:
type- the message type- See Also:
getType()
-
getMembershipInfo
public MembershipInfo getMembershipInfo()
Get the membership info for this message. This should only be called if this is a membership message (isMembership()is true).- Returns:
- the membership info for this message
-
clone
public java.lang.Object clone()
Creates a copy of this message.- Overrides:
clonein classjava.lang.Object- Returns:
- a copy of this message
-
-