Class GenericGroup<S extends GenericSimulation<S,A,C,D,DM,F,G>,A extends GenericActor<S,A,C,D,DM,F,G>,C extends GenericCondition<S,A,C,D,DM,F,G>,D extends GenericDomain<S,A,C,D,DM,F,G>,DM extends GenericDomainMember<S,A,C,D,DM,F,G>,F extends GenericFactory<S,A,C,D,DM,F,G>,G extends GenericGroup<S,A,C,D,DM,F,G>>
- All Implemented Interfaces:
NamedObjectOps
- Direct Known Subclasses:
Group
A group has methods named getDelay and getMessageFilter for computing a delay and a message filter representing processing performed by the group. The delay is added to the delay computed from domains. The message filter should rarely, and ideally never, cause a message to be deleted. It is intended for annotating a message by, for example, incrementing a hop count used to indicate the number of groups traversed.
The delays computed by both this object and domains give the delays from the time a message was received by a group. If the group sends the message to each recipient at a different time (perhaps due to queuing), the methods getDelay will return different values depending on the recipient, and it is the responsibility of a subclass to compute those values. The processing is similar regardless of whether a group will forward a message to an actor or to another group, either of which can be the next hop for the message (messages may pass through multiple groups before reaching the final destination). When the event delivering a message specifies a domain,
- a CommDomainInfo object cdinfo is looked up by calling the simulation's findCommDomain method.
- A message filter for specific to the group processing the message is obtained by calling this group's getMessageFilter method, and that filter, if it exists, is applied to the message.
- the delay is initialized by calling this group's getDelay method, using the source of the event, the message, and the next hop as its arguments.
- cdinfo is used to look up a source and destination domain and a common ancestor and the delay is incremented by using the ancestor's getDelay method.
- a new event is then scheduled to forward the message to the next recipient. This is done iteratively for each possible next hop..
- the method getMessageFilter is used to look up a message filter for the current group. That message filter, if not null, is applied to the message.
- the delay is determined by calling this group's getDelay method, using the source of the event, the message, and the next hop as its arguments.
- the message, possibly modified, is then forwarded.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
GenericGroup
(S sim, String name, boolean intern) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionactorRecipientIterator
(A source) Get an iterator of actor message recipients for a given message source.boolean
Determine if this named object can be deleted.protected void
checkRegistrationInfo
(GroupInfo info, boolean isGroup) Check registration GroupInfo argument.protected Object
clone()
Creates and returns a copy of this object.final boolean
delete()
Delete an object.final boolean
Determine if an object is being deleted.Get the set of domains that a group has joined.Get the actor members of a group.int
Get the number of actors that are members of a group.getChildDomains
(D ancestor) Get a set of the domains that the current group has joined and that have a common ancestor.long
Get the delay appropriate for delivering a message to an actor.long
Get the delay appropriate for delivering a message to a group.Get the group members of a group.int
Get the number of groups that are members of a group.Get the information object for an actor that is a member of a group.Get the information object for a group that is a member of a group.getMessageFilter
(A source, A dest) Get the message filter when the destination is an Actor.getMessageFilter
(A source, G dest) Get the message filter when the destination is a Group.final String
getName()
Get an object's name.protected Simulation
Get the object namer for a named object.groupRecipientIterator
(A source) Get an integrator of group message recipients for a given message source.boolean
Determine if the current group has joined a domain.final boolean
Determine if an object has been deleted.boolean
Determine if an object is interned in a object namer's tables.boolean
Determine if an actor is a group member.boolean
Determine if a group is a group member.void
joinDomain
(D d) Join a domain.void
leaveDomain
(D d) Leave a domain.protected void
onDelete()
Complete the actions necessary to delete a named object.protected void
onDeregister
(A recipient, GroupInfo info) Complete deregistration of an actor.protected void
onDeregister
(G recipient, GroupInfo info) Complete deregistration of a group.protected void
onRegister
(A recipient, GroupInfo newInfo, GroupInfo oldInfo, boolean newMember) Complete registration of an actor.protected void
onRegister
(G recipient, GroupInfo newInfo, GroupInfo oldInfo, boolean newMember) Complete registration of a group.void
printConfiguration
(String iPrefix, String prefix, boolean printName, PrintWriter out) Print this simulation object's configuration.protected void
reactToMessage
(A source, G intermediateHop, Object message, int recipientCount) React to a message.Methods inherited from class org.bzdev.drama.generic.GenericMsgRecipient
getGroups, inGroup, joinGroup, joinGroup, leaveGroup
Methods inherited from class org.bzdev.drama.generic.GenericTaskObject
cancelDefaultCall, cancelDefaultTask, defaultCall, defaultTask, scheduleDefaultCall, scheduleDefaultTask, scheduleDefaultTask
Methods inherited from class org.bzdev.drama.generic.GenericSimObject
getSimulation, printState
Methods inherited from class org.bzdev.devqsim.SimObject
addSimulationListener, addTraceSet, bindCallable, bindCallable, bindCallable, bindCallable, bindRunnable, bindRunnable, bindRunnable, bindRunnable, callableObject, callableScript, callScriptFunction, callScriptMethod, clearTraceSets, evalScript, getEventListenerList, getScriptObject, getTraceSets, printConfiguration, printConfiguration, printConfiguration, printConfiguration, printConfiguration, printConfiguration, printState, printState, printState, printState, printState, printState, putScriptObject, removeSimulationListener, removeTraceSet, runnableObject, runnableScript, scheduleCall, scheduleCall, scheduleCall, scheduleCall, scheduleCallObject, scheduleScript, scheduleTask, scheduleTask, scheduleTask, scheduleTask, scheduleTaskObject, scheduleTaskScript, startImmediateTask, startImmediateTask, trace, trace, unscheduledTaskThread, unscheduledTaskThread, update, update, usesTraceSet
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.bzdev.obnaming.NamedObjectOps
canDelete, delete, deletePending, getName, isDeleted, isInterned
-
Constructor Details
-
GenericGroup
Constructor.- Parameters:
sim
- the simulationname
- the name of the groupintern
- true if the object can be looked up by using the methods inSimulation
; false otherwise.- Throws:
IllegalArgumentException
- typically means a name is already in use
-
-
Method Details
-
onDelete
protected void onDelete()Complete the actions necessary to delete a named object. A subclass that overrides this method must call super.onDelete() at some point to complete the object deletion. This may not be within the onDelete method of the subclass if the deletion must be delayed for some reason (e.g., until some processing that is in progress has been completed). Once called, the object will be removed from the object-namer's tables and the object will be marked as deleted, so in general cleanup actions by a subclass should occur before it calls super.onDelete().- Overrides:
onDelete
in classGenericMsgRecipient<S extends GenericSimulation<S,
A, C, D, DM, F, G>, A extends GenericActor<S, A, C, D, DM, F, G>, C extends GenericCondition<S, A, C, D, DM, F, G>, D extends GenericDomain<S, A, C, D, DM, F, G>, DM extends GenericDomainMember<S, A, C, D, DM, F, G>, F extends GenericFactory<S, A, C, D, DM, F, G>, G extends GenericGroup<S, A, C, D, DM, F, G>>
-
isMember
Determine if an actor is a group member.- Parameters:
recipient
- the recipient- Returns:
- true if the recipient is a group member; false otherwise
-
isMember
Determine if a group is a group member.- Parameters:
recipient
- the recipient- Returns:
- true if the recipient is a group member; false otherwise
-
getActorMembers
Get the actor members of a group.- Returns:
- a set of the members of this group that are actors
-
getActorMembersSize
public int getActorMembersSize()Get the number of actors that are members of a group.- Returns:
- the number of members
-
getGroupMembers
Get the group members of a group.- Returns:
- a set of the members of this group that are groups
-
getGroupMembersSize
public int getGroupMembersSize()Get the number of groups that are members of a group.- Returns:
- the number of members
-
getInfo
Get the information object for an actor that is a member of a group. Usually the object returned will actually be a subclass of GroupInfo.- Parameters:
member
- the group member- Returns:
- a object providing information for the group member; null if none
- Throws:
IllegalStateException
- info object not cloneable in spite of having implemented the Cloneable interface
-
getInfo
Get the information object for a group that is a member of a group. Usually the object returned will actually be a subclass of GroupInfo.- Parameters:
member
- the group member- Returns:
- a object providing information for the group member; null if none
- Throws:
IllegalStateException
- info object not cloneable in spite of having implemented the Cloneable interface
-
checkRegistrationInfo
protected void checkRegistrationInfo(GroupInfo info, boolean isGroup) throws IllegalArgumentException Check registration GroupInfo argument. This method may be overridden to force a type check of the GroupInfo parameter used during registration, and must throw an IllegalArgumentException if the type check fails.- Parameters:
info
- theinfo
argument passed toregister(GenericMsgRecipient recipient, GroupInfo info)
isGroup
- true if registering a group; false otherwise- Throws:
IllegalArgumentException
- the GroupInfo argument is invalid, most likely because the type is not consistent with the subclass of GenericGroup calling this method
-
onRegister
Complete registration of an actor. This will be called during registration to allow subclasses to manage additional data structures.- Parameters:
recipient
- the message recipient being registerednewInfo
- the new information object; null if noneoldInfo
- the old information object; null if nonenewMember
- true if registering a new member; false if modifying the registration of an existing member
-
onRegister
Complete registration of a group. This will be called during registration to allow subclasses to manage additional data structures.- Parameters:
recipient
- the message recipient being registerednewInfo
- the new information object; null if noneoldInfo
- the old information object; null if nonenewMember
- true if registering a new member; false if modifying the registration of an existing member
-
onDeregister
Complete deregistration of an actor. This will be called during deregistration to allow subclasses to manage additional data structures. It is only called if the message recipient being deregistered is registered- Parameters:
recipient
- the message recipient being registeredinfo
- the information object for the recipient being deregistered; null if none
-
onDeregister
Complete deregistration of a group. This will be called during deregistration to allow subclasses to manage additional data structures. It is only called if the message recipient being deregistered is registered- Parameters:
recipient
- the message recipient being registeredinfo
- the information object for the recipient being deregistered; null if none
-
actorRecipientIterator
Get an iterator of actor message recipients for a given message source.- Parameters:
source
- the actor originating a message- Returns:
- an iterator that enumerates the source actor's immediate recipients (other actors or other groups)
-
groupRecipientIterator
Get an integrator of group message recipients for a given message source.- Parameters:
source
- the actor originating a message- Returns:
- an iterator that enumerates the source actor's immediate recipients (other actors or other groups)
-
getDelay
Get the delay appropriate for delivering a message to an actor. This delay represents the group's contribution to the delay, and is added to any delays provided by domains.- Parameters:
source
- the source of the messagemsg
- the message being sentdest
- the recipient of the message- Returns:
- a non-negative long integer giving the delay in simulation time units
-
getDelay
Get the delay appropriate for delivering a message to a group. This delay represents this group's contribution to the delay, and is added to any delays provided by domains.- Parameters:
source
- the source of the messagemsg
- the message being sentdest
- the recipient of the message- Returns:
- a non-negative long integer giving the delay in simulation time units
-
getMessageFilter
Get the message filter when the destination is an Actor. The current group is the one relaying the message. The default implementation returns null, so if message filters are to be used in a simulation, this method must be overridden. This message filter, if non-null, will be applied before the message filter(s) associated with domains forwarding messages, and is applied in any case.- Parameters:
source
- the source of the messagedest
- a destination- Returns:
- the message filter to use; null if there is none.
-
getMessageFilter
Get the message filter when the destination is a Group. The current group is the one relaying the message. The default implementation returns null, so if message filters are to be used in a simulation, this method must be overridden. This message filter, if non-null, will be applied before the message filter(s) associated with domains forwarding messages, and is applied in any case.- Parameters:
source
- the source of the messagedest
- a destination- Returns:
- the message filter to use; null if there is none.
-
reactToMessage
React to a message. This should be overridden if the group tracks the messages it relays. The default implementation does nothing.- Parameters:
source
- the message sourceintermediateHop
- the last group to relay the message; null if nonemessage
- the messagerecipientCount
- the number of recipients receiving the message.
-
getChildDomains
Get a set of the domains that the current group has joined and that have a common ancestor. The iterator for the returned set will return domains in the order set by domain-specific criteria.- Parameters:
ancestor
- the ancestor domain- Returns:
- a set of domains that the current group has joined and that have the specified ancestor
-
joinDomain
Join a domain.- Parameters:
d
- the domain
-
leaveDomain
Leave a domain.- Parameters:
d
- the domain
-
domainSet
Get the set of domains that a group has joined.- Returns:
- a set of domains
-
inDomain
Determine if the current group has joined a domain.- Parameters:
d
- the domain- Returns:
- true if current group has joined the specified domain; false otherwise
-
printConfiguration
Print this simulation object's configuration. Documentation for the use of this method is provided by the documentation for theSimObject
methodSimObject.printConfiguration(String,String,boolean,PrintWriter)
. When the thirs argument has a value of true, the object name and class name will be printed in a standard format with its indentation provided by the iPrefix argument. In addition, the configuration that is printed includes the following items.Defined in
GenericMsgRecipient
:- the groups this object has joined.
Defined in
GenericGroup
:- the domains this object has joined.
- the actors that are members of this group.F
- Overrides:
printConfiguration
in classGenericMsgRecipient<S extends GenericSimulation<S,
A, C, D, DM, F, G>, A extends GenericActor<S, A, C, D, DM, F, G>, C extends GenericCondition<S, A, C, D, DM, F, G>, D extends GenericDomain<S, A, C, D, DM, F, G>, DM extends GenericDomainMember<S, A, C, D, DM, F, G>, F extends GenericFactory<S, A, C, D, DM, F, G>, G extends GenericGroup<S, A, C, D, DM, F, G>> - Parameters:
iPrefix
- the prefix to use for an initial line when printName is true with null treated as an empty stringprefix
- a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is trueprintName
- requests printing the name of an objectout
- the output print writer
-
clone
Creates and returns a copy of this object. This method will throw the exception CloneNotSupportedException if the object is interned.- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
- a clone could not be created- See Also:
-
isInterned
public boolean isInterned()Determine if an object is interned in a object namer's tables.- Specified by:
isInterned
in interfaceNamedObjectOps
- Returns:
- true if the object is interned; false if not
-
getObjectNamer
Get the object namer for a named object.- Returns:
- the object namer for this named object
-
getName
Get an object's name.- Specified by:
getName
in interfaceNamedObjectOps
- Returns:
- the name of the object
-
canDelete
public boolean canDelete()Determine if this named object can be deleted. A named object can be deleted if the method delete has not been called and if the object is not in a state that prevents the object from being deleted. Subclasses that override this method must call canDelete() for their superclasses and return false if the superclass' canDelete method returns false. The default method returns true if delete() has not been called and returned true.- Specified by:
canDelete
in interfaceNamedObjectOps
- Returns:
- true if this object can be deleted; false otherwise
-
delete
public final boolean delete()Delete an object. An object can only be deleted once. If this method returns true, the object (if interned) will have been removed from the object namer tables.The implementations provided by
DefaultNamedObect
and generated because of a@NamedObject
annotation provide a protected method named onDelete. A subclass that overrides onDelete() must call the onDelete method of its superclass after it's onDelete method has been called and any cleanup actions performed. In some cases, this may happen at a later time (e.g., if a thread is used for some of the cleanup operations or if it is otherwise necessary to wait).- Specified by:
delete
in interfaceNamedObjectOps
- Returns:
- true if the deletion request was accepted; false otherwise
-
isDeleted
public final boolean isDeleted()Determine if an object has been deleted. An object is deleted if the method delete() has been called and returned true.- Specified by:
isDeleted
in interfaceNamedObjectOps
- Returns:
- true if deleted; false otherwise
-
deletePending
public final boolean deletePending()Determine if an object is being deleted. An deletion is pending if the method delete() has been called and returned true but the deletion has not been completed.- Specified by:
deletePending
in interfaceNamedObjectOps
- Returns:
- true if deletion is pending; false otherwise
-