public interface SimEntity
extends org.javades.jsimulation.r5.SimEventListResetListener
SimJob or SimQueue.
A SimEntity is an entity relevant to event-list scheduling in a queueing system simulation.
Usually, it is either a queue (SimQueue) or a job (SimJob).
However, the interface does not a priori assume this.
What SimEntitys have in common is the event list they are attached to,
the fact that they have a name, that they support operations,
and their obligation to propagate state changes
(notifications) to (registered) listeners.
Objects implementing this interface take care of (at the very least)
SimEventList), which may be null,
SimEventListResetListener to a non-null SimEventList,
obeying resets on the SimEventList,
and propagating reset events on the SimEventList to SimEntityListeners through resetEntity()
(which, effectively, describes the RESET operation),
setName(java.lang.String) and toStringDefault(),
SimEntityOperations, and supporting them through doOperation(double, Req)
with flexible error handling for unknown operations,
SimEntitySimpleEventType.Member,
SimEntityListener) to notifications,
SimEntityListener.notifyUpdate(double, org.javades.jqueues.r5.entity.SimEntity) and SimEntityListener.notifyStateChanged(double, org.javades.jqueues.r5.entity.SimEntity, java.util.List<java.util.Map<org.javades.jqueues.r5.entity.SimEntitySimpleEventType.Member, org.javades.jqueues.r5.entity.SimEntityEvent>>), respectively,
SimEntity and SimEntityListener,
listeners are not allowed to initiate state-changing operations on the entity),
getLastUpdateTime()
(effectively, the UPDATE notification).
Note that the contracts of
SimEntityOperation,
SimEntitySimpleEventType,
SimEntityEvent
and SimEntityListener are part of the formal interface of a SimEntity.
For an implementation starting point, see AbstractSimEntity.
Copyright (C) 2005-2017 Jan de Jongh, TNO
This file is covered by the LICENSE file in the root of this project.
SimEntityOperation,
SimEntitySimpleEventType,
SimEntityEvent,
SimEntityListener,
SimJob,
SimQueue,
AbstractSimEntity| Modifier and Type | Interface and Description |
|---|---|
static interface |
SimEntity.Action
An action for use in
doAfterNotifications(org.javades.jqueues.r5.entity.SimEntity.Action). |
static class |
SimEntity.UnknownNotificationTypePolicy
Possible courses of action when an unknown notification is to be published.
|
static class |
SimEntity.UnknownOperationPolicy
Possible courses of action when an unknown operation is offered to
doOperation(double, Req). |
| Modifier and Type | Method and Description |
|---|---|
void |
doAfterNotifications(SimEntity.Action action)
Registers an
SimEntity.Action to be taken once this entity has finished issuing notifications,
or takes the action immediately if this entity is not notifying listeners. |
<O extends SimEntityOperation,Req extends SimEntityOperation.Request,Rep extends SimEntityOperation.Reply> |
doOperation(double time,
Req request)
Performs the given operation, identified by an operation request, at this entity at given time.
|
org.javades.jsimulation.r5.SimEventList |
getEventList()
Gets the underlying event list of this
SimEntity. |
double |
getLastUpdateTime()
Gets the time of the last update of this entity.
|
Set<SimEntitySimpleEventType.Member> |
getRegisteredNotificationTypes()
Gets the registered notification types of this entity.
|
Set<SimEntityOperation> |
getRegisteredOperations()
Gets the registered operations of this entity.
|
Set<SimEntityListener> |
getSimEntityListeners()
Gets the listeners to this entity.
|
SimEntity.UnknownNotificationTypePolicy |
getUnknownNotificationTypePolicy()
Returns the policy for unknown notifications types.
|
SimEntity.UnknownOperationPolicy |
getUnknownOperationPolicy()
Returns the policy for unknown operations.
|
boolean |
isIgnoreEventListReset()
Returns whether this entity ignores event-list resets.
|
void |
registerSimEntityListener(SimEntityListener listener)
Registers a listener to event notifications related to this entity.
|
void |
resetEntity()
Puts the entity into its "known" initial state.
|
void |
setIgnoreEventListReset(boolean ignoreEventListReset)
Sets whether this entity ignores future event-list resets.
|
void |
setName(String name)
Sets the name of this
SimEntity, to be returned by subsequent calls to Object.toString (). |
void |
setUnknownNotificationTypePolicy(SimEntity.UnknownNotificationTypePolicy unknownNotificationTypePolicy)
Sets the policy for unknown notifications types.
|
void |
setUnknownOperationPolicy(SimEntity.UnknownOperationPolicy unknownOperationPolicy)
Sets the policy for unknown operations.
|
String |
toStringDefault()
Returns a default name for this
SimEntity. |
void |
unregisterSimEntityListener(SimEntityListener listener)
Unregisters a listener to event notifications related to this entity.
|
void |
update(double time)
Updates this entity.
|
org.javades.jsimulation.r5.SimEventList getEventList()
SimEntity.
The event list is passed upon construction of the object, and cannot be changed afterwards.
It may be null.
If the event list is non-null, implementations must register at it as a SimEventListResetListener,
and propagate any reset of the event list through resetEntity().
SimEntity.String toStringDefault()
SimEntity.
The naming framework of an entity is as follows:
Object.toString () implementations final;
users should always have the option to give useful (to them) names to entities
by using the conventional approach of overriding Object.toString ().
Object.toString () for String representations of an entity
(following Java conventions).
AbstractSimEntity.toString())
of Object.toString return
setName(java.lang.String), or, if not set,
toStringDefault() as set (and often made final
by the implementation class(es), or, if not set,
Object.toString().
setName(java.lang.String) or by overriding (if still possible) Object.toString().
At the same time, if a user chooses to not care about naming, a type-specific (typically "short") meaningful
description String of the entity is used.
In other words, the string is to be returned by (concrete) implementations of toStringDefault() acts
as a fallback return value for Object.toString ()
in case the user did not set an instance-specific name
through setName(java.lang.String).
Implementations are recommended to not make this method final
unless the class itself is final.
The recommendation same holds for Object.toString ().
SimEntity.setName(java.lang.String),
Object.toString()void setName(String name)
SimEntity, to be returned by subsequent calls to Object.toString ().name - The new name of this job or queue; if non-null, the string will be returned by subsequent calls
to Object.toString () (recommended implementation!);
otherwise, the type-specific default toStringDefault() will be used for that.toStringDefault()Set<SimEntityOperation> getRegisteredOperations()
SimEntityOperationSimEntity.UnknownOperationPolicy getUnknownOperationPolicy()
null.SimEntityOperation,
doOperation(double, Req)void setUnknownOperationPolicy(SimEntity.UnknownOperationPolicy unknownOperationPolicy)
unknownOperationPolicy - The new policy for unknown operations, non-null.IllegalArgumentException - If the argument is null.SimEntityOperation,
doOperation(double, Req)<O extends SimEntityOperation,Req extends SimEntityOperation.Request,Rep extends SimEntityOperation.Reply> Rep doOperation(double time, Req request)
If the operation is unknown, the course of action is as determined by getUnknownOperationPolicy().
O - The operation type.Req - The request type (corresponding to the operation type).Rep - The reply type (corresponding to the operation type).time - The time at which to perform the operation.request - The operation request (holds operation type as well).null unless the request was unknown and ignored.IllegalArgumentException - If time is in the past,
if the request is null, illegally structured, or contains illegal arguments,
or if the corresponding operation is not registered and the policy is not to accept that.getRegisteredOperations(),
SimEntity.UnknownOperationPolicy,
getUnknownOperationPolicy()Set<SimEntitySimpleEventType.Member> getRegisteredNotificationTypes()
void doAfterNotifications(SimEntity.Action action)
SimEntity.Action to be taken once this entity has finished issuing notifications,
or takes the action immediately if this entity is not notifying listeners.action - The action to take, non-null.IllegalArgumentException - If the action is null.SimEntity.UnknownNotificationTypePolicy getUnknownNotificationTypePolicy()
null.void setUnknownNotificationTypePolicy(SimEntity.UnknownNotificationTypePolicy unknownNotificationTypePolicy)
unknownNotificationTypePolicy - The new policy for unknown notification types, non-null.IllegalArgumentException - If the argument is null.void registerSimEntityListener(SimEntityListener listener)
Implementations are encouraged to consider the use of weak/soft references to registered listeners.
listener - The listener; ignored if already registered or null.SimEntityListener,
unregisterSimEntityListener(org.javades.jqueues.r5.entity.SimEntityListener),
getSimEntityListeners()void unregisterSimEntityListener(SimEntityListener listener)
listener - The listener; ignored if not registered or null.SimEntityListener,
registerSimEntityListener(org.javades.jqueues.r5.entity.SimEntityListener),
getSimEntityListeners()Set<SimEntityListener> getSimEntityListeners()
Callers must not attempt to change the returned set.
Implementations are encouraged to return read-only views.
SimEntityListener,
registerSimEntityListener(org.javades.jqueues.r5.entity.SimEntityListener),
unregisterSimEntityListener(org.javades.jqueues.r5.entity.SimEntityListener),
getSimEntityListeners()boolean isIgnoreEventListReset()
setIgnoreEventListReset(boolean)void setIgnoreEventListReset(boolean ignoreEventListReset)
By contract, a SimEntity must reset with resetEntity()
whenever the underlying event list (if present) is reset.
The normal procedure to achieve this is to register as a SimEventListResetListener,
and invoke resetEntity() upon SimEventListResetListener.notifyEventListReset(org.javades.jsimulation.r5.SimEventList).
There are cases, however, in which resetting this entity has to be delegated to another entity (or other type of object listening to the event list), for instance because the order in which entities are reset is important. Through this method, the automatic resetting of this entity upon an event-list reset can be disabled. Note, however, that the contract remains that the entity has to follow event-list resets.
ignoreEventListReset - Whether this entity ignores future event-list resets.isIgnoreEventListReset(),
SimEventListResetListener.notifyEventListReset(org.javades.jsimulation.r5.SimEventList)void resetEntity()
This method is used in order to restart a simulation.
By contract, a SimEntity must reset if its underlying SimEventList resets.
However, a SimEntity can also be reset independently from the event list.
In the latter case, it takes its current time from the event list, if available,
or to Double.NEGATIVE_INFINITY otherwise.
Implementations must ensure that only a single SimEntityListener.notifyResetEntity(org.javades.jqueues.r5.entity.SimEntity) is invoked after
the entity is in the new (valid) state.
SimEventListResetListener.notifyEventListReset(org.javades.jsimulation.r5.SimEventList)double getLastUpdateTime()
Upon construction, the last-update time must be set to minus infinity, mimicking the behavior of SimEventList.
Upon an explicit reset of this entity, the last-update time is to be copied from the event list, if available
(or reset to Double.NEGATIVE_INFINITY otherwise).
In all other cases, the time returned corresponds to the time argument of the last update of the entity,
see SimEntityListener.notifyUpdate(double, org.javades.jqueues.r5.entity.SimEntity) for more details.
AbstractSimEntity.update(double),
SimEntityListener.notifyUpdate(double, org.javades.jqueues.r5.entity.SimEntity)void update(double time)
For a precise definition of an update of an entity, refer to SimEntityListener.notifyUpdate(double, org.javades.jqueues.r5.entity.SimEntity).
time - The time of the update (the new time on the entity).IllegalStateException - If time is in the past.getLastUpdateTime(),
SimEntityListener.notifyUpdate(double, org.javades.jqueues.r5.entity.SimEntity)Copyright © 2018. All rights reserved.