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

public abstract 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>> extends GenericMsgRecipient<S,A,C,D,DM,F,G>
Class to represent groups of message recipients. While only actors can originate messages, groups can distribute those messages to multiple recipients. Actors may join one or more groups. A member of a group may be another group (there is a circularity check to avoid infinite loops).

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..
If a domain was not specified by the event, the following sequence of operations is used:
  • 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 Details

    • GenericGroup

      protected GenericGroup(S sim, String name, boolean intern) throws IllegalArgumentException
      Constructor.
      Parameters:
      sim - the simulation
      name - the name of the group
      intern - true if the object can be looked up by using the methods in Simulation; 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 class GenericMsgRecipient<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

      public boolean isMember(A recipient)
      Determine if an actor is a group member.
      Parameters:
      recipient - the recipient
      Returns:
      true if the recipient is a group member; false otherwise
    • isMember

      public boolean isMember(G recipient)
      Determine if a group is a group member.
      Parameters:
      recipient - the recipient
      Returns:
      true if the recipient is a group member; false otherwise
    • getActorMembers

      public Set<A> 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

      public Set<G> 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

      public GroupInfo getInfo(A member) throws IllegalStateException
      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

      public GroupInfo getInfo(G member) throws IllegalStateException
      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 - the info argument passed to register(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

      protected void onRegister(A recipient, GroupInfo newInfo, GroupInfo oldInfo, boolean newMember)
      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 registered
      newInfo - the new information object; null if none
      oldInfo - the old information object; null if none
      newMember - true if registering a new member; false if modifying the registration of an existing member
    • onRegister

      protected void onRegister(G recipient, GroupInfo newInfo, GroupInfo oldInfo, boolean newMember)
      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 registered
      newInfo - the new information object; null if none
      oldInfo - the old information object; null if none
      newMember - true if registering a new member; false if modifying the registration of an existing member
    • onDeregister

      protected void onDeregister(A recipient, GroupInfo info)
      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 registered
      info - the information object for the recipient being deregistered; null if none
    • onDeregister

      protected void onDeregister(G recipient, GroupInfo info)
      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 registered
      info - the information object for the recipient being deregistered; null if none
    • actorRecipientIterator

      public abstract Iterator<A> actorRecipientIterator(A source)
      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

      public abstract Iterator<G> groupRecipientIterator(A source)
      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

      public long getDelay(A source, Object msg, A dest)
      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 message
      msg - the message being sent
      dest - the recipient of the message
      Returns:
      a non-negative long integer giving the delay in simulation time units
    • getDelay

      public long getDelay(A source, Object msg, G dest)
      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 message
      msg - the message being sent
      dest - the recipient of the message
      Returns:
      a non-negative long integer giving the delay in simulation time units
    • getMessageFilter

      public MessageFilter getMessageFilter(A source, A dest)
      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 message
      dest - a destination
      Returns:
      the message filter to use; null if there is none.
    • getMessageFilter

      public MessageFilter getMessageFilter(A source, G dest)
      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 message
      dest - a destination
      Returns:
      the message filter to use; null if there is none.
    • reactToMessage

      protected void reactToMessage(A source, G intermediateHop, Object message, int recipientCount)
      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 source
      intermediateHop - the last group to relay the message; null if none
      message - the message
      recipientCount - the number of recipients receiving the message.
    • getChildDomains

      public Set<D> getChildDomains(D ancestor)
      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

      public void joinDomain(D d)
      Join a domain.
      Parameters:
      d - the domain
    • leaveDomain

      public void leaveDomain(D d)
      Leave a domain.
      Parameters:
      d - the domain
    • domainSet

      public Set<D> domainSet()
      Get the set of domains that a group has joined.
      Returns:
      a set of domains
    • inDomain

      public boolean inDomain(D d)
      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

      public void printConfiguration(String iPrefix, String prefix, boolean printName, PrintWriter out)
      Print this simulation object's configuration. Documentation for the use of this method is provided by the documentation for the SimObject method SimObject.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 class GenericMsgRecipient<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 string
      prefix - a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is true
      printName - requests printing the name of an object
      out - the output print writer
    • clone

      protected Object clone() throws CloneNotSupportedException
      Creates and returns a copy of this object. This method will throw the exception CloneNotSupportedException if the object is interned.
      Overrides:
      clone in class Object
      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 interface NamedObjectOps
      Returns:
      true if the object is interned; false if not
    • getObjectNamer

      protected Simulation getObjectNamer()
      Get the object namer for a named object.
      Returns:
      the object namer for this named object
    • getName

      public final String getName()
      Get an object's name.
      Specified by:
      getName in interface NamedObjectOps
      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 interface NamedObjectOps
      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 interface NamedObjectOps
      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 interface NamedObjectOps
      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 interface NamedObjectOps
      Returns:
      true if deletion is pending; false otherwise