public class SocialCommitment extends Observable implements Observer, Comparable<SocialCommitment>, Describable
SocialCommitment
is a class to track a social commitment.
The following chart shows the possible states and their transitions.
The state machine follows the following rules:
created
state.
fulfilled
,
canceled
, or
violated
states.
created
, then the current state is
set to started
.
started
, then the current state is
set to perform-action
.
started
,
and the perform action event has previously occurred, then the
current state is set to
perform-action
.
started
or
perform-action
, then
the current state is set to fulfilled
.
started
,
and the stop event has previously occurred, then the current state is set
to fulfilled
.
execute(PolicyAgentInterface)
is called and the current
state is perform-action
, then
the current state is set to
ready-fulfilled
.
designateFulfilled()
is called and the current state is not
an end state, then the current state is set to
fulfilled
.
designateCanceled()
is called and the current state is not
an end state, then the current state is set to
canceled
.
designateStarted()
is called and the current state is not
an end state, then the current state is set to
started
.
violated
.
Modifier and Type | Class and Description |
---|---|
static class |
SocialCommitment.CommitmentState
The
CommitmentState enumeration is used to describe the set of possible states that a social commitment may be in. |
Modifier and Type | Field and Description |
---|---|
private Act |
act
The act of this commitment.
|
private Action |
action
The action that should fulfil this commitment.
|
private PolicyAgentInterface |
agent
The agent that "owns" this SocialCommitment.
|
private long |
createdTime
The time that this social commitment was created.
|
private URLDescriptor |
creditor
The creditor of this commitment.
|
private SocialCommitment.CommitmentState |
currentState
The current state of the commitment.
|
private URLDescriptor |
debtor
The debtor of this commitment.
|
(package private) static long |
DEFAULT_TIMEOUT
The time from current that the SocialCommitment will go Violated if not otherwise specified.
|
private long |
endTime
The time when this commitment ended (was fulfilled, canceled or violated).
|
private Event |
event
The event that caused the creation of this social commitment.
|
private Map<String,Event> |
events
A map which contains the events associated with this commitment.
|
static Set<SocialCommitmentStatusFlags> |
MASK_ALL
An empty set of status flags.
|
static Set<SocialCommitmentStatusFlags> |
MASK_EXECUTABLE
The set of status flags that, if set, indicate that a social commitment is
executable.
|
static Set<SocialCommitmentStatusFlags> |
MASK_OBLIGATED
The set of status flags that, if set, indicate that a social commitment
represents an obligation for the debtor of that social commitment.
|
static Set<SocialCommitmentStatusFlags> |
MASK_OUTSTANDING
The set of status flags that, if set, indicate that a social commitment is
outstanding.
|
private static long |
nextSerialNumber
This is the next serial number to be used.
|
private String |
ownerConversationID
The ID of the Conversation in which the Social Commitment was formed
|
private TreeMap<String,String> |
params
Supports the
Describable interface |
private boolean |
performActionEventOccurred
Used to indicate that the perform action event has occurred, but had no
effect because it fired before the start event.
|
private String |
performative
The performative of this commitment.
|
private int |
priority
The priority of this commitment.
|
private long |
serialNumber
This is a unique serial number for each social commitment.
|
private static CasaLispOperator |
SOCIALCOMMITMENT |
private static Set<SocialCommitmentStatusFlags> |
STATIC_STATUS_FLAGS
The set of status flags which do not change when the state of a social
commitment changes.
|
private EnumSet<SocialCommitmentStatusFlags> |
statusFlags
A set of status flags for this social commitment.
|
private boolean |
stopEventOccurred
Used to indicate that the stop event has occurred, but had no effect because it fired before the agent
|
Constructor and Description |
---|
SocialCommitment(PolicyAgentInterface agent,
URLDescriptor newDebtor,
URLDescriptor newCreditor,
String newPerformative,
Act newAct,
Event event,
Action newAction)
Constructs a new social commitment from the given information.
|
SocialCommitment(PolicyAgentInterface agent,
URLDescriptor newDebtor,
URLDescriptor newCreditor,
String newPerformative,
Act newAct,
Event event,
Action newAction,
Event... newEvents)
Constructs a new social commitment from the given information.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addObserver(SocialCommitment sco)
TODO Document the addObserver method.
|
protected StringBuffer |
attributesString()
Creates a
StringBuffer object and fills it with some attributes of
this social commitment. |
SocialCommitment |
clone() |
int |
compareTo(SocialCommitment commitment)
Compare the given social commitment to this social commitment.
|
boolean |
designateCanceled()
Attempts to change the state of this commitment to
canceled . |
boolean |
designateFulfilled()
Attempts to change the state of this commitment to
fulfilled . |
boolean |
designateStarted()
Attempts to reset the social commitment by changing the state of this
commitment to
started . |
protected void |
enterTerminalState()
Called whenever the SocialCommitment enters a terminal state (FILFILLED, CANCELED, or VIOLATED).
|
boolean |
equals(Object object)
Determines if the given object is equal to this social commitment.
|
private boolean |
equals(SocialCommitment commitment)
Determines if the given social commitment is equal to this social
commitment.
|
PerformDescriptor |
execute(PolicyAgentInterface agent)
Executes this social commitment by performing its associated action.
|
boolean |
flagSet(SocialCommitmentStatusFlags flagToCheck)
Determines if this social commitment has the given status flag set to
true . |
Act |
getAct()
Retrieves the act of this commitment.
|
Action |
getAction()
Retrieves the action of this commitment.
|
long |
getCreatedTime()
Retrieves the time that this social commitment was created.
|
URLDescriptor |
getCreditor()
Retrieves the creditor of this commitment.
|
URLDescriptor |
getDebtor()
Retrieves the debtor of this commitment.
|
long |
getEndTime()
Returns the time this commitment ended (was fulfilled, canceled or expired).
|
Event |
getEvent()
Retrieves the Event that caused the creation of this social commitment.
|
protected Event |
getEventOfType(String type)
Retrieves the event of the indicated type, if any.
|
Set<SocialCommitmentStatusFlags> |
getFlags()
Retrieves this social commitment's set of status flags.
|
MLMessage |
getMessage()
Retrieves the message in the event that caused the creation of this social commitment, if there is one; else null.
|
String |
getOwnerConversationID() |
String |
getParameter(String key)
Retrieves a parameter of this object.
|
String |
getPerformative()
Retrieves the performative of this commitment.
|
int |
getPriority()
Retrieves the priority of this commitment.
|
long |
getSerialNumber()
Retrieves the unique serial number for this social commitment.
|
SocialCommitment.CommitmentState |
getState() |
protected boolean |
hasEventOfType(String type)
Determines if this social commitment has an event of the indicated type.
|
int |
hashCode()
Returns a hashing of this social commitment.
|
Set<String> |
keySet() |
boolean |
meetsMask(Set<SocialCommitmentStatusFlags> mask)
Determines if this social commitment has all of the status flags given in
the mask set to
true . |
(package private) void |
notifyObservers(PerformDescriptor stat)
TODO Document the notifyObservers method.
|
protected void |
retractTimeoutEvent() |
void |
setDebtor(boolean isDebtor)
Sets the
DEBTOR flag to be the
same as the given value. |
void |
setMarked(boolean marked)
Sets the
MARKED flag to be the
same as the given value. |
void |
setNotDebtor(boolean isNotDebtor)
Sets the
NOTDEBTOR flag to be
the same as the given value. |
void |
setParameter(String parameter,
String value)
Sets a parameter in the object.
|
void |
setPersistent(boolean isPersistent)
Sets the
PERSISTENT flag to be the
same as the given value. |
void |
setPriority(int newPriority)
Sets the priority of this commitment.
|
void |
setShared(boolean isShared)
Sets the
SHARED flag to be the
same as the given value. |
String |
toString()
Returns a string describing this social commitment.
|
String |
toString(boolean prettyPrint)
Returns a string describing this social commitment.
|
void |
update(Observable o,
Object arg)
TODO update this doc
Updates the state of this commitment based on the event that has occurred.
|
private void |
updateStateAtStartup()
Moves forward in the state machine from the state of
created
when the commitment is first created. |
private void |
updateStatePerformingAction()
Moves forward in the state machine from the state of
perform-action when the commitment
is executed. |
private void |
updateStatusWord()
Updates the
status flags based on the current state of
the social commitment. |
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
private PolicyAgentInterface agent
private URLDescriptor debtor
private URLDescriptor creditor
private String performative
private Act act
private Event event
private Action action
private TreeMap<String,String> params
Describable
interfaceprivate final long createdTime
System.currentTimeMillis()
. It cannot change over
the lifetime of a social commitment.private long endTime
System.currentTimeMillis()
. A
value of 0 indicates that this social commitment has not ended.private Map<String,Event> events
private int priority
private final long serialNumber
private static long nextSerialNumber
private SocialCommitment.CommitmentState currentState
private EnumSet<SocialCommitmentStatusFlags> statusFlags
SocialCommitmentStatusFlags
enumeration. For each flag, if
it is contained within this set, it is considered to be set to true
.
If it is not in this set, it is considered to be false
.private String ownerConversationID
static final long DEFAULT_TIMEOUT
private boolean performActionEventOccurred
private boolean stopEventOccurred
public static final Set<SocialCommitmentStatusFlags> MASK_ALL
meetsMask(Set)
, it will always return true
.public static final Set<SocialCommitmentStatusFlags> MASK_EXECUTABLE
public static final Set<SocialCommitmentStatusFlags> MASK_OUTSTANDING
public static final Set<SocialCommitmentStatusFlags> MASK_OBLIGATED
private static Set<SocialCommitmentStatusFlags> STATIC_STATUS_FLAGS
private static final CasaLispOperator SOCIALCOMMITMENT
public SocialCommitment(PolicyAgentInterface agent, URLDescriptor newDebtor, URLDescriptor newCreditor, String newPerformative, Act newAct, Event event, Action newAction, Event... newEvents)
System.currentTimeMillis()
.
created
and then updateStateAtStartup()
is called.
newDebtor
- The debtor of the new social commitment.newCreditor
- The creditor of the new social commitment.newPerformative
- The performative of the new social commitment.newAct
- The act of the new social commitment.msg
- The message which caused the creation of the new social commitment.newAction
- The action which should fulfill the new social commitment.newEvents
- The set of events associated with the new social commitment.public SocialCommitment(PolicyAgentInterface agent, URLDescriptor newDebtor, URLDescriptor newCreditor, String newPerformative, Act newAct, Event event, Action newAction)
#SocialCommitment(URLDescriptor, URLDescriptor, String, Act, MLMessage, Action, Event...)
with a null
final argument.agent
- newDebtor
- The debtor of the new social commitment.newCreditor
- The creditor of the new social commitment.newPerformative
- The performative of the new social commitment.newAct
- The act of the new social commitment.msg
- The message which caused the creation of the new social
commitment.newAction
- The action which should fulfill the new social commitment.public String getOwnerConversationID()
public URLDescriptor getDebtor()
public URLDescriptor getCreditor()
public String getPerformative()
public Act getAct()
public Action getAction()
public Event getEvent()
public MLMessage getMessage()
public long getCreatedTime()
System.currentTimeMillis()
. It cannot change over the lifetime of a social commitment.public long getEndTime()
System.currentTimeMillis()
. MAX_VALUE if it has not ended.public SocialCommitment.CommitmentState getState()
SocialCommitment.CommitmentState
public int getPriority()
public void setPriority(int newPriority)
newPriority
- The new value of priority.public long getSerialNumber()
protected boolean hasEventOfType(String type)
type
- A string describing the type of event that the calling method
is curious about.true
if this commitment has an event of the
specified type; false
otherwise.protected Event getEventOfType(String type)
type
- A string describing the type of event that should be retrieved.null
if this
commitment does not have an event of the specified type.public PerformDescriptor execute(PolicyAgentInterface agent)
updateStatePerformingAction()
is called to move the state
machine forward.
action
.perform(PolicyAgentInterface)
is called to actually perform the action associated with this social
commitment. If there is no associated action, a perform descriptor with a
status of 0 is returned.
TransientAgent.DEFER_ACTION
, then the
social commitment is restarted by calling designateStarted()
.
TransientAgent.DROP_ACTION
, then the
social commitment is fulfilled by calling designateFulfilled()
.
TransientAgent.DEFER_ACTION
or TransientAgent.DROP_ACTION
, then all observers are notified
by calling notifyObservers(PerformDescriptor)
with the status
that will be returned by this method.
SHARED
flag is not
set to true
, then the social commitment is fulfilled by calling
designateFulfilled()
.
agent
- The agent in which will provide the context for the
execution of this social commitment.action
.perform(PolicyAgentInterface)
if it is not null
.private void updateStateAtStartup()
created
when the commitment is first created. This happens if no event of type
start is found, and continues if no event of type perform action are found.private void updateStatePerformingAction()
perform-action
when the commitment
is executed. This is called from execute(PolicyAgentInterface)
.public boolean designateStarted()
started
. This will only
occur if the commitment has not already ended (been fulfilled, canceled or
violated).true
if this commitment has been successfully
restarted (had its state set to
started
); false
otherwise.public boolean designateFulfilled()
fulfilled
. This will only occur if the
commitment has not already ended (been fulfilled, canceled or violated).
This also has the effect of setting the endTime
to
System.currentTimeMillis()
.true
if the state of this commitment has been
successfully set to fulfilled
;
false
otherwise.protected void retractTimeoutEvent()
public boolean designateCanceled()
canceled
. This will only occur if the
commitment has not already ended (been fulfilled, canceled or violated). If
successful, this also has the effect of setting the endTime
to
System.currentTimeMillis()
.true
if the state of this commitment has been
successfully set to canceled
;
false
otherwise.public boolean equals(Object object)
equals(SocialCommitment)
method
returns true
for that commitment. Otherwise, the object is not
considered to be equal to this object.private boolean equals(SocialCommitment commitment)
commitment
- The commitment to compare to this
for equality.true
if the given social commitment is equal to this social
commitment; false
otherwise.public int compareTo(SocialCommitment commitment)
compareTo
in interface Comparable<SocialCommitment>
commitment
- The commitment to compare to this
for equality.0
if the two social commitments are equal; a
value less than 0
if this commitment comes before the given
commitment; and a value greater than 0
if the given
commitment comes before this commitment.public int hashCode()
public String toString()
attributesString()
.public String toString(boolean prettyPrint)
attributesString()
.prettyPrint
- Return a more human-readable string.protected StringBuffer attributesString()
StringBuffer
object and fills it with some attributes of
this social commitment. This method should be overridden in subclasses to
give more information.public void update(Observable o, Object arg)
update
in interface Observer
type
- A string representing the type of event that has occurred.event
- The event that fired
.instanceInfo
- An object that details the event occurrence.EventObserver.notifyEventOccurred(java.lang.String,
casa.event.Event, java.lang.Object)
public void setDebtor(boolean isDebtor)
DEBTOR
flag to be the
same as the given value.isDebtor
- The new value for the
DEBTOR
flag.public void setNotDebtor(boolean isNotDebtor)
NOTDEBTOR
flag to be
the same as the given value.isDebtor
- The new value for the
NOTDEBTOR
flag.public void setShared(boolean isShared)
SHARED
flag to be the
same as the given value.isDebtor
- The new value for the
SHARED
flag.public void setPersistent(boolean isPersistent)
PERSISTENT
flag to be the
same as the given value.isDebtor
- The new value for the
PERSISTENT
flag.public void setMarked(boolean marked)
MARKED
flag to be the
same as the given value.isDebtor
- The new value for the
MARKED
flag.public Set<SocialCommitmentStatusFlags> getFlags()
public boolean flagSet(SocialCommitmentStatusFlags flagToCheck)
true
.flagToCheck
- The status flag which is to be checked in this social
commitment.true
if this social commitment has the given status flag
set to true
; false
otherwise.public boolean meetsMask(Set<SocialCommitmentStatusFlags> mask)
true
.mask
- The set of status flags which are to be checked in this social
commitment.true
if this social commitment has all of the status flags
given in the mask set to true
; false
otherwise.private void updateStatusWord()
status flags
based on the current state of
the social commitment. This is done by copying the current status flags,
retaining only the status flags in STATIC_STATUS_FLAGS
, and then
setting all of the remaining flags conditionally based on the current state
of the commitment.protected void enterTerminalState()
protected void addObserver(SocialCommitment sco)
sco
- void notifyObservers(PerformDescriptor stat)
stat
- public String getParameter(String key)
Describable
getParameter
in interface Describable
key
- String indication which parameter to retrieve.public Set<String> keySet()
keySet
in interface Describable
public void setParameter(String parameter, String value)
Describable
setParameter
in interface Describable
parameter
- name of the parameter to set/addvalue
- string value to associate with the parameterpublic SocialCommitment clone()
clone
in interface Describable
clone
in class Object