DJ - The delegate-job type.DQ - The queue-type for delegate jobs.J - The job type.Q - The queue type for jobs.public abstract class AbstractSimQueueComposite<DJ extends SimJob,DQ extends SimQueue,J extends SimJob,Q extends AbstractSimQueueComposite> extends AbstractSimQueue<J,Q> implements SimQueueComposite<DJ,DQ,J,Q>, SimEntityListener, SimQueueSelector<J,DQ>
SimQueueComposite.
This abstract base class registers the sub-queues and the queue selector,
and takes care of all administration related to job visits,
creating delegate jobs and maintaining the mapping between real and delegate jobs.
It registers a MultiSimQueueNotificationProcessor
on the sub-queues,
and registers the (abstract) method processSubQueueNotifications(java.util.List<org.javades.jqueues.r5.listener.MultiSimQueueNotificationProcessor.Notification<DJ, DQ>>)
as its processor.
It also registers itself as a SimEntityListener on the sub-queues
in order to capture their updates.
Despite all the work performed in this abstract base class,
many degrees of freedom still exits for concrete implementation,
because only compliance with SimQueueComposite
is targeted.
See AbstractSimQueueComposite_LocalStart
for a more complete (and restricted in flexibility) implementation.
Copyright (C) 2005-2017 Jan de Jongh, TNO
This file is covered by the LICENSE file in the root of this project.
| Modifier and Type | Class and Description |
|---|---|
static interface |
AbstractSimQueueComposite.RealDelegateJobMapper<J extends SimJob,DJ extends SimJob>
A mapper between real and delegate jobs (for use by sub-classes).
|
AbstractSimEntity.Notifier, AbstractSimEntity.PreNotificationHookSimQueue.AutoRevocationPolicySimEntity.Action, SimEntity.UnknownNotificationTypePolicy, SimEntity.UnknownOperationPolicy| Modifier and Type | Field and Description |
|---|---|
protected AbstractSimQueueComposite.RealDelegateJobMapper |
realDelegateJobMapper
A mapper object for mapping real and delegate jobs of this composite queue (for use by sub-classes).
|
eventsScheduled, SANITYUSE_ARRAY_OPTIMIZATION| Modifier | Constructor and Description |
|---|---|
protected |
AbstractSimQueueComposite(org.javades.jsimulation.r5.SimEventList eventList,
Set<DQ> queues,
SimQueueSelector<J,DQ> simQueueSelector,
DelegateSimJobFactory delegateSimJobFactory)
Creates an abstract network of queues.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addRealJobLocal(J realJob)
Adds a real job, creating its delegate job.
|
static Set<SimQueue> |
getCopySimQueues(Set<SimQueue> queues)
Returns a copy of a given set of
SimQueues, each of which is copied in itself. |
protected Set<DQ> |
getCopySubSimQueues()
Returns a copy of the set of sub-queues, each of which is copied in itself.
|
protected DJ |
getDelegateJob(J realJob)
Returns the delegate job for given real job.
|
protected DJ |
getDelegateJobMild(J realJob)
As
getDelegateJob(J), but skips the check for presence in the job queue. |
DelegateSimJobFactory<? extends DJ,DQ,J,Q> |
getDelegateSimJobFactory()
Returns the factory to create delegate
SimJobs, non-null. |
protected int |
getIndex(DQ queue)
Returns the index of given sub-queue.
|
static <DQ extends SimQueue> |
getIndex(Set<DQ> queues,
DQ queue)
Returns the index of a given queue in a set.
|
protected DQ |
getQueue(int q)
Returns a sub-queue by its index.
|
static <DQ extends SimQueue> |
getQueue(Set<DQ> queues,
int q)
Returns a queue in a set by its index.
|
Set<DQ> |
getQueues()
Returns the set of queues embedded by this
SimQueueComposite. |
protected J |
getRealJob(DJ delegateJob)
Returns the real job for given delegate job.
|
protected J |
getRealJob(DJ delegateJob,
DQ queue)
Returns the real job for given delegate job, and asserts its presence on the given (sub-)queue, or on no (sub-)queue at all.
|
SimQueueSelector<J,DQ> |
getSimQueueSelector()
Returns the (user-supplied)
SimQueueSelector for selecting the sub-queue to visit. |
protected boolean |
isDelegateJob(DJ delegateJob)
Checks for the presence of a delegate job (in the administration of this composite queue).
|
protected boolean |
isRealJob(J realJob)
Checks for the presence of a real job (in the administration of this composite queue).
|
void |
notifyResetEntity(SimEntity entity)
Does nothing.
|
void |
notifyStateChanged(double time,
SimEntity entity,
List<Map<SimEntitySimpleEventType.Member,SimEntityEvent>> notifications)
Does nothing.
|
void |
notifyUpdate(double time,
SimEntity entity)
Calls
AbstractSimEntity.update(double) in order to update our own time in response to an increase in time on one of the sub-queues. |
protected abstract void |
processSubQueueNotifications(List<MultiSimQueueNotificationProcessor.Notification<DJ,DQ>> notifications)
Processes the pending atomic notification from the sub-queues.
|
protected void |
removeJobsFromQueueLocal(J realJob,
DJ delegateJob)
Removes a real job and a delegate job from the internal data structures.
|
protected void |
resetEntitySubClass()
Resets this
AbstractSimQueueComposite. |
void |
resetSimQueueSelector()
Does nothing.
|
DQ |
selectFirstQueue(double time,
J job)
Selects the first sub-queue to visit from the user-supplied
SimQueueSelector,
or none if no such object was supplied. |
DQ |
selectNextQueue(double time,
J job,
DQ previousQueue)
Selects the next sub-queue to visit from the user-supplied
SimQueueSelector,
or none if no such object was supplied. |
void |
setDelegateSimJobFactory(DelegateSimJobFactory<? extends DJ,DQ,J,Q> delegateSimJobFactory)
Sets the factory to create delegate
SimJobs, non-null. |
arrive, autoRevoke, cancelDepartureEvent, cancelDepartureEvent, depart, departureFromEventList, drop, getAutoRevocationPolicy, getDepartureEvents, getDepartureEvents, getFirstJob, getFirstJobInServiceArea, getFirstJobInWaitingArea, getJobs, getJobsInServiceArea, getJobsInWaitingArea, getNumberOfJobs, getNumberOfJobsInServiceArea, getNumberOfJobsInWaitingArea, getServerAccessCredits, getServiceTimeForJob, hasJobs, hasJobsInServiceArea, hasJobsInWaitingArea, hasServerAcccessCredits, insertJobInQueueUponArrival, insertJobInQueueUponStart, isJob, isJobInServiceArea, isJobInWaitingArea, isQueueAccessVacation, queueAccessVacationDropSubClass, registerStdOutSimQueueListener, removeJobFromQueueUponDeparture, removeJobFromQueueUponDrop, removeJobFromQueueUponRevokation, rescheduleAfterArrival, rescheduleAfterDeparture, rescheduleAfterDrop, rescheduleAfterRevokation, rescheduleAfterStart, rescheduleForNewServerAccessCredits, revoke, revoke, scheduleDepartureEvent, scheduleJobArrival, setAutoRevocationPolicy, setQueueAccessVacation, setServerAccessCredits, setServerAccessCreditsSubClass, start, takeServerAccessCredit, toStringDefault, triggerPotentialNewStartArmed, unregisterStdOutSimQueueListeneraddPendingNotification, addPendingNotification, clearAndUnlockPendingNotificationsIfLocked, delegateOperation, doAfterNotifications, doOperation, fireAndLockPendingNotifications, getEventList, getLastUpdateTime, getRegisteredDelegatedOperations, getRegisteredNotificationTypes, getRegisteredOperations, getSimEntityListeners, getUnknownNotificationTypePolicy, getUnknownOperationPolicy, isIgnoreEventListReset, notifyEventListReset, registerDelegatedOperation, registerNotificationType, registerOperation, registerPreEventHook, registerPreNotificationHook, registerPreUpdateHook, registerSimEntityListener, registerStdOutSimEntityListener, removeDelegationForOperation, resetEntity, setIgnoreEventListReset, setName, setUnknownNotificationTypePolicy, setUnknownOperationPolicy, toString, unregisterSimEntityListener, unregisterStdOutSimEntityListener, updateclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitarrive, getAutoRevocationPolicy, getCopySimQueue, getJobs, getJobsInServiceArea, getJobsInWaitingArea, getNumberOfJobs, getNumberOfJobsInServiceArea, getNumberOfJobsInWaitingArea, getServerAccessCredits, isJob, isJobInServiceArea, isJobInWaitingArea, isQueueAccessVacation, isStartArmed, revoke, revoke, setAutoRevocationPolicy, setQueueAccessVacation, setServerAccessCreditsdoAfterNotifications, doOperation, getEventList, getLastUpdateTime, getRegisteredNotificationTypes, getRegisteredOperations, getSimEntityListeners, getUnknownNotificationTypePolicy, getUnknownOperationPolicy, isIgnoreEventListReset, registerSimEntityListener, resetEntity, setIgnoreEventListReset, setName, setUnknownNotificationTypePolicy, setUnknownOperationPolicy, toStringDefault, unregisterSimEntityListener, updatenotifyEventListResetgetQoS, getQoSClassprotected final AbstractSimQueueComposite.RealDelegateJobMapper realDelegateJobMapper
protected AbstractSimQueueComposite(org.javades.jsimulation.r5.SimEventList eventList,
Set<DQ> queues,
SimQueueSelector<J,DQ> simQueueSelector,
DelegateSimJobFactory delegateSimJobFactory)
After calling the super constructor,
this methods sets the delegate job factory,
and inhibits future automatic resets from the event list on all sub-queues through SimEntity.setIgnoreEventListReset(boolean),
since this object will take care of that (and depends on the absence of "independent" resets
of the sub-queues).
In addition, it registers as a SimEntityListener on each sub-queue
(only required for UPDATE notifications).
It then creates a single MultiSimQueueNotificationProcessor for all sub-queues,
and registers method processSubQueueNotifications(java.util.List<org.javades.jqueues.r5.listener.MultiSimQueueNotificationProcessor.Notification<DJ, DQ>>) as its processor.
Finally, it resets the local part of the object through a (private) variant of resetEntitySubClass()
that does not invoke its super method.
This, among others, will reset the sub-queues.
eventList - The event list to be shared between this queue and the embedded queues.queues - A set holding the "embedded" queues.simQueueSelector - The object for routing jobs through the network of embedded queues;
if null, no sub-queues will be visited.delegateSimJobFactory - An optional factory for the delegate SimJobs.IllegalArgumentException - If the event list is null,
the queue argument is null, has null members,
or contains this composite queue.SimQueueSelector,
DelegateSimJobFactory,
DefaultDelegateSimJobFactory,
SimEntity.setIgnoreEventListReset(boolean),
SimEntity.registerSimEntityListener(org.javades.jqueues.r5.entity.SimEntityListener),
MultiSimQueueNotificationProcessor,
MultiSimQueueNotificationProcessor.setProcessor(org.javades.jqueues.r5.listener.MultiSimQueueNotificationProcessor.Processor),
processSubQueueNotifications(java.util.List<org.javades.jqueues.r5.listener.MultiSimQueueNotificationProcessor.Notification<DJ, DQ>>),
resetEntitySubClass()public final Set<DQ> getQueues()
SimQueueCompositeSimQueueComposite.
The set should not be manipulated. Typically, implementations return an unmodifiable set.
Implementations must maintain deterministic ordering of the queues in the set!
getQueues in interface SimQueueComposite<DJ extends SimJob,DQ extends SimQueue,J extends SimJob,Q extends AbstractSimQueueComposite>null set of queues, each non-null.public static <DQ extends SimQueue> int getIndex(Set<DQ> queues, DQ queue)
Note that elements in a Set are unordered,
unless the specific implementation (like LinkedHashSet) takes care of that.
Be careful with this method!
DQ - The queue-type.queues - The set, must be non-null.queue - The queue; must be present in the set and non-null.IllegalArgumentException - If the set or the queue is null,
or if the queue is not present in the set.protected final int getIndex(DQ queue)
queue - The sub-queue; must be present in getQueues().getQueues().IllegalArgumentException - If the queue is null or not present in getQueues().public static <DQ extends SimQueue> DQ getQueue(Set<DQ> queues, int q)
Note that elements in a Set are unordered,
unless the specific implementation (like LinkedHashSet) takes care of that.
Be careful with this method!
DQ - The queue-type.queues - The queues.q - The index.IllegalArgumentException - If the set is null
or the index is (strictly) negative or larger or equal than the size of the set.protected final DQ getQueue(int q)
q - The index.getQueues() with given index.IllegalArgumentException - If the index is (strictly) negative or larger or equal than the size of getQueues().public static Set<SimQueue> getCopySimQueues(Set<SimQueue> queues) throws UnsupportedOperationException
SimQueues, each of which is copied in itself.queues - The set of SimQueues.SimQueues, each of which is copied in itself.IllegalArgumentException - If queues == null or contains a null element.UnsupportedOperationException - If copying any of the sub-queues is unsupported; this should be considered as a
software error.SimQueue.getCopySimQueue()protected final Set<DQ> getCopySubSimQueues() throws UnsupportedOperationException
UnsupportedOperationException - If copying any of the sub-queues is unsupported; this should be considered as a
software error.getQueues(),
SimQueue.getCopySimQueue()public final SimQueueSelector<J,DQ> getSimQueueSelector()
SimQueueSelector for selecting the sub-queue to visit.getSimQueueSelector in interface SimQueueComposite<DJ extends SimJob,DQ extends SimQueue,J extends SimJob,Q extends AbstractSimQueueComposite>SimQueueSelector for selecting the sub-queue to visit.public final void resetSimQueueSelector()
resetSimQueueSelector in interface SimQueueSelector<J extends SimJob,DQ extends SimQueue>public final DQ selectFirstQueue(double time, J job)
SimQueueSelector,
or none if no such object was supplied.selectFirstQueue in interface SimQueueSelector<J extends SimJob,DQ extends SimQueue>time - The time of arrival of the job.job - The job, non-null.null, the job is to depart immediately.
If no selector is supplied upon construction, this method returns null.getSimQueueSelector()public final DQ selectNextQueue(double time, J job, DQ previousQueue)
SimQueueSelector,
or none if no such object was supplied.selectNextQueue in interface SimQueueSelector<J extends SimJob,DQ extends SimQueue>time - The current time, i.e., the departure time of the job at its previous queue.job - The job, non-null.previousQueue - The previous queue the job visited, and just departed from.null, the job is to depart immediately.
If no selector is supplied upon construction, this method returns null.getSimQueueSelector()public final DelegateSimJobFactory<? extends DJ,DQ,J,Q> getDelegateSimJobFactory()
SimQueueCompositeSimJobs, non-null.getDelegateSimJobFactory in interface SimQueueComposite<DJ extends SimJob,DQ extends SimQueue,J extends SimJob,Q extends AbstractSimQueueComposite>SimJobs, non-null.public final void setDelegateSimJobFactory(DelegateSimJobFactory<? extends DJ,DQ,J,Q> delegateSimJobFactory)
SimQueueCompositeSimJobs, non-null.setDelegateSimJobFactory in interface SimQueueComposite<DJ extends SimJob,DQ extends SimQueue,J extends SimJob,Q extends AbstractSimQueueComposite>delegateSimJobFactory - The new factory to create delegate SimJobs, non-null.protected final boolean isRealJob(J realJob)
The result of this method is equivalent to this.isJob (realJob),
with additional sanity checks on the internal administration,
in particular on the mapping between real and delegate jobs.
This method does not check the presence of the delegate job on a sub-queue.
realJob - The real SimJob; if null, false is returned.True if and only if the argument is a real job currently visiting this composite queue.IllegalStateException - If sanity checks on the internal job administrations fail.AbstractSimQueue.isJob(org.javades.jqueues.r5.entity.jq.job.SimJob)protected final boolean isDelegateJob(DJ delegateJob)
This method performs sanity checks on the internal administration, in particular on the mapping between real and delegate jobs.
delegateJob - The delegate SimJob; if null, false is returned.True if and only if the argument is a delegate job of a real job currently visiting this composite queue.IllegalStateException - If sanity checks on the internal job administrations fail.getDelegateJob(J)protected final DJ getDelegateJob(J realJob)
realJob - The real job.IllegalStateException - If sanity checks fail.isRealJob(J),
isDelegateJob(DJ),
getDelegateJobMild(J)protected final DJ getDelegateJobMild(J realJob)
getDelegateJob(J), but skips the check for presence in the job queue.
Specifically meant to access a delegate job in AbstractSimQueue.insertJobInQueueUponArrival(J, double),
in which the real job has not been inserted into the job queue yet.
realJob - The real job.IllegalStateException - If (remaining) sanity checks fail.getDelegateJob(J),
isRealJob(J),
isDelegateJob(DJ)protected final J getRealJob(DJ delegateJob, DQ queue)
By using this method, you assume that the delegate job is present on the given sub-queue,
or, if passing a null argument for the queue,
on no sub-queue at all.
This method will rigorously check your assumption and happily throw an IllegalStateException
if your assumption proves wrong.
Clearly, this method is primarily intended for internal consistency checking.
Performs various additional sanity checks on the arguments and the internal administration consistency.
delegateJob - The delegate job.queue - The queue at which the delegate job currently resides,
null if it is supposed to reside on none of the (sub-)queues..IllegalStateException - If sanity checks fail, including the case where a corresponding real job could not be found,
or where assumption on the delegate-job whereabout proves to be wrong.getRealJob(SimJob)protected final J getRealJob(DJ delegateJob)
Performs various sanity checks on the arguments and the internal administration consistency.
This method does not check the presence (nor absence) of the delegate job on a (or any) sub-queue.
delegateJob - The delegate job.IllegalStateException - If sanity checks fail, including the case where a corresponding real job could not be found.getRealJob(SimJob, SimQueue)protected final void addRealJobLocal(J realJob)
realJob - The real job, non-null.IllegalArgumentException - If the real job is already present,
or if no delegate job for it could be created.IllegalStateException - If the internal administration is found inconsistent.protected final void removeJobsFromQueueLocal(J realJob, DJ delegateJob)
The jobs do not have to be present; if not, this method has (with respect to that job) no effect.
This method does not remove the delegate job from a sub-queue it might currently be visiting.
realJob - The real job (may be null meaning no real job is to be removed).delegateJob - The delegate job (may be null meaning no delegate job is to be removed).protected void resetEntitySubClass()
AbstractSimQueueComposite.
Calls super method (not if called from constructor, for which a private variant for local resets is used),
resets the sub-queue selector,
clears the internal mapping between real and delegate SimJobs (removing all real and delegate jobs),
and resets all sub-queues in the order in which they appear in getQueues().
(Note: some sub-classes rely on this order!)
resetEntitySubClass in class AbstractSimQueue<J extends SimJob,Q extends AbstractSimQueueComposite>AbstractSimQueue.removeJobFromQueueUponRevokation(J, double, boolean),
AbstractSimQueue.rescheduleAfterRevokation(J, double, boolean),
SimEntity.resetEntity(),
SimQueueSelector.resetSimQueueSelector(),
SimQueue.setServerAccessCredits(double, int),
SimQueue.isStartArmed()protected abstract void processSubQueueNotifications(List<MultiSimQueueNotificationProcessor.Notification<DJ,DQ>> notifications)
Core method for reacting to 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>>) notifications from all sub-queues.
This method is registered as the processor for an anonymous MultiSimQueueNotificationProcessor
(for all sub-queues) created upon construction,
see MultiSimQueueNotificationProcessor.Processor
and MultiSimQueueNotificationProcessor.setProcessor(org.javades.jqueues.r5.listener.MultiSimQueueNotificationProcessor.Processor).
notifications - The sub-queue notifications, will be modified; empty upon return.IllegalArgumentException - If the list is null or empty, or contains a notification from another queue
than the a sub-queue,
or if other sanity checks fail.MultiSimQueueNotificationProcessor,
MultiSimQueueNotificationProcessor.Processor,
MultiSimQueueNotificationProcessor.setProcessor(org.javades.jqueues.r5.listener.MultiSimQueueNotificationProcessor.Processor)public final void notifyUpdate(double time,
SimEntity entity)
AbstractSimEntity.update(double) in order to update our own time in response to an increase in time on one of the sub-queues.notifyUpdate in interface SimEntityListenertime - The time of the update.entity - The entity that is about to be updated.IllegalArgumentException - If the entity is null or not one of our sub-queues.IllegalStateException - If time is in the past.getQueues(),
AbstractSimEntity.update(double),
AbstractSimEntity.getLastUpdateTime()public final void notifyResetEntity(SimEntity entity)
notifyResetEntity in interface SimEntityListenerentity - The entity that has been reset.processSubQueueNotifications(java.util.List<org.javades.jqueues.r5.listener.MultiSimQueueNotificationProcessor.Notification<DJ, DQ>>)public final void notifyStateChanged(double time,
SimEntity entity,
List<Map<SimEntitySimpleEventType.Member,SimEntityEvent>> notifications)
notifyStateChanged in interface SimEntityListenertime - The current time (the time of the state change).entity - The entity at which the state changed.notifications - The sequence of notifications of state-changes the combination of which led to the new state.processSubQueueNotifications(java.util.List<org.javades.jqueues.r5.listener.MultiSimQueueNotificationProcessor.Notification<DJ, DQ>>)Copyright © 2018. All rights reserved.