org.springframework.integration.gemfire.store
Class KeyValueMessageGroup

java.lang.Object
  extended by org.springframework.integration.gemfire.store.KeyValueMessageGroup
All Implemented Interfaces:
java.io.Serializable, MessageGroup

public class KeyValueMessageGroup
extends java.lang.Object
implements MessageGroup, java.io.Serializable

A MessageGroup that manipulates keys and values to provide persistence. Responsible for managing one group's messages as a MessageGroup.

Since:
2.1
See Also:
Serialized Form

Constructor Summary
KeyValueMessageGroup()
          default javabean ctor (so that this object plays well as a Serializable object)
KeyValueMessageGroup(java.lang.Object groupId)
           
KeyValueMessageGroup(java.lang.Object groupId, java.util.concurrent.ConcurrentMap<java.lang.String,Message<?>> marked, java.util.concurrent.ConcurrentMap<java.lang.String,Message<?>> unmarked)
           
KeyValueMessageGroup(java.lang.Object groupId, long timestamp, java.util.concurrent.ConcurrentMap<java.lang.String,Message<?>> marked, java.util.concurrent.ConcurrentMap<java.lang.String,Message<?>> unmarked)
           
 
Method Summary
 void add(Message<?> message)
          Add this Message to the MessageGroup, delegating in this case to the unmarked field
protected  java.lang.String baseKey(Message<?> msg)
           
 boolean canAdd(Message<?> message)
          Query if the message can be added.
protected  boolean containsSequenceNumber(java.util.Collection<Message<?>> messages, java.lang.Integer messageSequenceNumber)
           
 boolean equals(java.lang.Object obj)
           
 java.lang.Object getGroupId()
           
 java.util.Collection<Message<?>> getMarked()
           
protected  java.util.Collection<Message<?>> getMessagesForMessageGroup(java.util.Map<java.lang.String,Message<?>> region)
          this method will be used to discover all the messages for a given group in a Region
 Message<?> getOne()
           
 int getSequenceSize()
           
 long getTimestamp()
           
 java.util.Collection<Message<?>> getUnmarked()
           
protected  java.lang.String groupKey()
          the groupKey is based on the groupID and it sits at the beginning of all the keys for this MessageGroups keys
 int hashCode()
           
 boolean isComplete()
           
protected  boolean isMember(Message<?> message)
          This method determines whether messages have been added to this group that supersede the given message based on its sequence id.
 void mark(Message<?> messageToMark)
          Mark the given message in this group.
 void markAll()
           
protected  java.lang.String markedKey(Message<?> msg)
          the only reason we differentiate the keys is so that conceptually you could use the same Map instance for both marked and unmarked messages.
 void remove(Message<?> message)
          Removes this Message from this MessageGroup's memory
 void setMarked(java.util.Map<java.lang.String,Message<?>> marked)
           
 void setUnmarked(java.util.Map<java.lang.String,Message<?>> unmarked)
           
 int size()
           
protected  java.lang.String unmarkedKey(Message<?> msg)
          the only reason we differentiate the keys is so that conceptually you could use the same Map instance for both marked and unmarked messages.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyValueMessageGroup

public KeyValueMessageGroup()
default javabean ctor (so that this object plays well as a Serializable object)


KeyValueMessageGroup

public KeyValueMessageGroup(java.lang.Object groupId)

KeyValueMessageGroup

public KeyValueMessageGroup(java.lang.Object groupId,
                            long timestamp,
                            java.util.concurrent.ConcurrentMap<java.lang.String,Message<?>> marked,
                            java.util.concurrent.ConcurrentMap<java.lang.String,Message<?>> unmarked)

KeyValueMessageGroup

public KeyValueMessageGroup(java.lang.Object groupId,
                            java.util.concurrent.ConcurrentMap<java.lang.String,Message<?>> marked,
                            java.util.concurrent.ConcurrentMap<java.lang.String,Message<?>> unmarked)
Method Detail

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

setUnmarked

public void setUnmarked(java.util.Map<java.lang.String,Message<?>> unmarked)

setMarked

public void setMarked(java.util.Map<java.lang.String,Message<?>> marked)

getTimestamp

public long getTimestamp()
Specified by:
getTimestamp in interface MessageGroup
Returns:
the timestamp (milliseconds since epoch) associated with the creation of this group

canAdd

public boolean canAdd(Message<?> message)
Query if the message can be added.

Specified by:
canAdd in interface MessageGroup

add

public void add(Message<?> message)
Add this Message to the MessageGroup, delegating in this case to the unmarked field

Parameters:
message - the Message you are adding to the Map

markedKey

protected java.lang.String markedKey(Message<?> msg)
the only reason we differentiate the keys is so that conceptually you could use the same Map instance for both marked and unmarked messages. This method simply differentiates the key, building on baseKey(org.springframework.integration.Message)'s return value

Parameters:
msg - the Message from which the key should be generated.
Returns:
a String to be used as a key

unmarkedKey

protected java.lang.String unmarkedKey(Message<?> msg)
the only reason we differentiate the keys is so that conceptually you could use the same Map instance for both marked and unmarked messages. This method simply differentiates the key, building on baseKey(org.springframework.integration.Message)'s return value

Parameters:
msg - the Message from which the key should be generated.
Returns:
a String to be used as a key

remove

public void remove(Message<?> message)
Removes this Message from this MessageGroup's memory

Parameters:
message - the message to remove

groupKey

protected java.lang.String groupKey()
the groupKey is based on the groupID and it sits at the beginning of all the keys for this MessageGroups keys

Returns:
a string based on getGroupId()

baseKey

protected java.lang.String baseKey(Message<?> msg)

getUnmarked

public java.util.Collection<Message<?>> getUnmarked()
Specified by:
getUnmarked in interface MessageGroup
Returns:
unmarked messages in the group at time of the invocation

getMessagesForMessageGroup

protected java.util.Collection<Message<?>> getMessagesForMessageGroup(java.util.Map<java.lang.String,Message<?>> region)
this method will be used to discover all the messages for a given group in a Region

Parameters:
region - the region from which we're hoping to discover these Messages
Returns:
a collection of messages

getMarked

public java.util.Collection<Message<?>> getMarked()
Specified by:
getMarked in interface MessageGroup
Returns:
marked messages in the group at the time of the invocation

getGroupId

public java.lang.Object getGroupId()
Specified by:
getGroupId in interface MessageGroup
Returns:
the key that links these messages together

isComplete

public boolean isComplete()
Specified by:
isComplete in interface MessageGroup
Returns:
true if the group is complete (i.e. no more messages are expected to be added)

getSequenceSize

public int getSequenceSize()
Specified by:
getSequenceSize in interface MessageGroup
Returns:
the size of the sequence expected 0 if unknown

mark

public void mark(Message<?> messageToMark)
Mark the given message in this group. If the message is not part of this group then this call has no effect.

Parameters:
messageToMark - the message that should be marked

markAll

public void markAll()

size

public int size()
Specified by:
size in interface MessageGroup
Returns:
the total number of messages (marked and unmarked) in this group

getOne

public Message<?> getOne()
Specified by:
getOne in interface MessageGroup
Returns:
a single message from the group

isMember

protected boolean isMember(Message<?> message)
This method determines whether messages have been added to this group that supersede the given message based on its sequence id. This can be helpful to avoid ending up with sequences larger than their required sequence size or sequences that are missing certain sequence numbers.

Parameters:
message - the message to test for candidacy
Returns:
whether or not the message is a member of the group

containsSequenceNumber

protected boolean containsSequenceNumber(java.util.Collection<Message<?>> messages,
                                         java.lang.Integer messageSequenceNumber)