public class DefaultSimQueueState<J extends SimJob,Q extends SimQueue> extends Object implements SimQueueState<J,Q>
SimQueueState.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 |
DefaultSimQueueState.PostStartHook<J extends SimJob>
A functional interface for a hook to be called right before exiting
doStarts(double, java.util.Set<J>). |
| Constructor and Description |
|---|
DefaultSimQueueState(Q queue)
Creates a new state object for give queue.
|
| Modifier and Type | Method and Description |
|---|---|
void |
doArrivals(double time,
Set<J> arrivals,
Set<JobQueueVisitLog<J,Q>> visitLogs)
Adds jobs as arrivals to the queue.
|
void |
doExits(double time,
Set<J> drops,
Set<J> revocations,
Set<J> departures,
Set<J> stickers,
Set<JobQueueVisitLog<J,Q>> visitLogs)
Removes jobs from the queue.
|
void |
doStarts(double time,
Set<J> starters)
Starts jobs at the queue.
|
Map<J,Double> |
getArrivalTimesMap()
Gets a map from jobs present in the queue onto their arrival times.
|
SimQueueStateHandler |
getHandler(String name)
Gets a handler by name.
|
NavigableMap<Double,List<J>> |
getJobArrivalsMap()
Returns a map of time onto jobs that arrived at that time, and are still present in the queue.
|
Map<J,Double> |
getJobRemainingServiceTimeMap()
Gets a map from all jobs in the service area onto their remaining service times.
|
Set<J> |
getJobs()
Get the set of all jobs currently residing at the queue, either in the waiting area or in the service area.
|
Set<J> |
getJobsInServiceArea()
Get the set of jobs currently in the service area of the queue (i.e., not waiting).
|
NavigableMap<Double,Set<J>> |
getJobsInServiceAreaMap()
Returns a map of time onto jobs that started at that time, and are still present (and thus in the service area) in the queue.
|
Set<J> |
getJobsInWaitingArea()
Gets a set holding all the jobs waiting at the queue (in no particular order).
|
Set<J> |
getJobsInWaitingAreaOrdered()
Gets a set holding all the jobs in the waiting area of the queue, in order of arrival.
|
Q |
getQueue()
Gets the queue, non-
null. |
NavigableMap<Double,List<J>> |
getRemainingServiceMap()
Returns a map of remaining service time onto jobs that started, have exactly that remaining service time,
and are still present (and thus in the service area) in the queue.
|
int |
getServerAccessCredits()
Gets the server-access credits.
|
double |
getServiceTime(Q queue,
J job)
Gets the service time of a job at a queue (central entry point).
|
Map<J,Double> |
getStartTimesMap()
Gets a map from all jobs in the service area of this queue onto their start times.
|
double |
getTime()
Gets the current time at the queue.
|
boolean |
isQueueAccessVacation()
Returns whether or not the queue is on queue-access vacation.
|
void |
registerHandler(SimQueueStateHandler handler)
Registers a handler.
|
void |
registerPostStartHook(DefaultSimQueueState.PostStartHook<J> postStartHook,
Object userData)
Registers a post-start hook.
|
void |
reset()
Resets the state, after which it reflects the "real" queue state after a reset.
|
void |
setQueueAccessVacation(double time,
boolean start)
Starts or ends a queue-access vacation.
|
void |
setServerAccessCredits(double time,
int credits)
Sets the server-access credits.
|
void |
setServiceTimeProvider(ToDoubleBiFunction<Q,J> serviceTimeProvider)
Sets a service-time provider, overruling job-settings for obtaining the required service time for a job visit.
|
void |
setTime(double time)
Sets the current time at the queue.
|
public DefaultSimQueueState(Q queue)
queue - The queue, non-null.IllegalArgumentException - If the queue is null.public final void registerHandler(SimQueueStateHandler handler)
A (extension) handler allow for extending the queue-state representation with
additional state variables without creating a subclass of DefaultSimQueueState for that
(which would lead to problems in case we have multiple such extensions).
handler - The handler.IllegalArgumentException - If the handler or its name are null,
or if a handler with the same name has been registered already.SimQueueStateHandlerpublic final SimQueueStateHandler getHandler(String name)
name - The name to look for.null if not found.public final Q getQueue()
SimQueueStatenull.
The queue to which this SimQueueState refers; cannot be changed.
public void reset()
SimQueueState
Mimics SimEventList.reset(double).
Note that the corresponding SimQueue method is SimEntity.resetEntity().
Implementations must set the time to Double.NaN, effectively meaning
"left of" Double.NEGATIVE_INFINITY.
reset in interface SimQueueState<J extends SimJob,Q extends SimQueue>SimEntity.resetEntity()public final double getTime()
SimQueueStatepublic final void setTime(double time)
SimQueueState
You cannot set back the time (only through SimQueueState.reset()).
setTime in interface SimQueueState<J extends SimJob,Q extends SimQueue>time - The new time.SimQueueState.reset()public final boolean isQueueAccessVacation()
SimQueueState
Mimics SimQueue.isQueueAccessVacation().
isQueueAccessVacation in interface SimQueueState<J extends SimJob,Q extends SimQueue>public final void setQueueAccessVacation(double time,
boolean start)
SimQueueStateThe time cannot be in the past.
setQueueAccessVacation in interface SimQueueState<J extends SimJob,Q extends SimQueue>time - The time the vacation starts or ends.start - Whether to start (true) or end (false) the vacation.
public final NavigableMap<Double,List<J>> getJobArrivalsMap()
SimQueueStateWithin the list, the jobs are in arrival order. Any job can only be in one of the value lists. The value lists only holds jobs present in the system, and, vice versa, any job present in the system must be in exactly one of the value lists. Null keys or values are not allowed.
getJobArrivalsMap in interface SimQueueState<J extends SimJob,Q extends SimQueue>public final Map<J,Double> getArrivalTimesMap()
SimQueueStateThe key set of this map must be in arrival order.
Every job present in the queue must have an entry, and, vice versa, every entry refers to a job actually present in the queue. Null keys or values are not allowed.
getArrivalTimesMap in interface SimQueueState<J extends SimJob,Q extends SimQueue>public final Set<J> getJobs()
SimQueueStateJobs are returned in arrival order.
Mimics SimQueue.getJobs().
The default implementation returns the key-set of SimQueueState.getArrivalTimesMap().
public final Set<J> getJobsInWaitingArea()
SimQueueState
Mimics SimQueue.getJobsInWaitingArea().
The default implementation returns the set difference of
SimQueueState.getJobs() and SimQueueState.getJobsInServiceArea().
getJobsInWaitingArea in interface SimQueueState<J extends SimJob,Q extends SimQueue>public final Set<J> getJobsInWaitingAreaOrdered()
SimQueueState
The default implementation returns a LinkedHashSet.
getJobsInWaitingAreaOrdered in interface SimQueueState<J extends SimJob,Q extends SimQueue>public int getServerAccessCredits()
SimQueueStategetServerAccessCredits in interface SimQueueState<J extends SimJob,Q extends SimQueue>public void setServerAccessCredits(double time,
int credits)
SimQueueState
Mimics SimQueue.setServerAccessCredits(double, int).
The time cannot be in the past.
setServerAccessCredits in interface SimQueueState<J extends SimJob,Q extends SimQueue>time - The time to set the credits.credits - The new remaining server-access credits, non-negative, with Integer.MAX_VALUE treated as infinity.public final Map<J,Double> getStartTimesMap()
SimQueueStategetStartTimesMap in interface SimQueueState<J extends SimJob,Q extends SimQueue>public final NavigableMap<Double,Set<J>> getJobsInServiceAreaMap()
SimQueueStateWithin the list, the jobs are in start order. Any job can only be in one of the value lists. The value lists only holds jobs currently in the service area of the system, and, vice versa, any job in the service area in the system must be in exactly one of the value lists. Null keys or values are not allowed.
getJobsInServiceAreaMap in interface SimQueueState<J extends SimJob,Q extends SimQueue>public final Set<J> getJobsInServiceArea()
SimQueueState
Mimics SimQueue.getJobsInServiceArea().
getJobsInServiceArea in interface SimQueueState<J extends SimJob,Q extends SimQueue>public final NavigableMap<Double,List<J>> getRemainingServiceMap()
SimQueueState
This map has no equivalence in the bare SimQueue, but the concept is used in,
for instance, processor-sharing queues.
Implementations must maintain the aggregate value set of the map returned to the set of jobs currently in the service area,
and must set the initial key for each job to the result returned from
SimJob.getServiceTime(Q).
Within the list, the jobs are in start order. Any job can only be in one of the value lists. The value lists only holds jobs currently in the service area of the system, and, vice versa, any job in the service area must be in exactly one of the value lists. Null keys or values are not allowed.
getRemainingServiceMap in interface SimQueueState<J extends SimJob,Q extends SimQueue>public final Map<J,Double> getJobRemainingServiceTimeMap()
SimQueueState
This map has no equivalence in the bare SimQueue, but the concept is used in,
for instance, processor-sharing queues.
Implementations must maintain the key set of the map returned to the set of jobs currently in the service area,
and must set the initial value for each job to the result returned from
SimJob.getServiceTime(Q).
Values must be non-negative (but do not have to be decreasing in time!).
getJobRemainingServiceTimeMap in interface SimQueueState<J extends SimJob,Q extends SimQueue>public final double getServiceTime(Q queue, J job)
queue - The queue.job - The job.SimJob.getServiceTime(Q) or
from the service-time provider (if installed).public void setServiceTimeProvider(ToDoubleBiFunction<Q,J> serviceTimeProvider)
serviceTimeProvider - The service-time provider; its two arguments are the queue and job, respectively.public void doArrivals(double time,
Set<J> arrivals,
Set<JobQueueVisitLog<J,Q>> visitLogs)
SimQueueStateThe arrival time cannot be in the past.
If the queue is on queue-access vacation, the jobs are dropped (i.e., not added to this state object).
doArrivals in interface SimQueueState<J extends SimJob,Q extends SimQueue>time - The arrival time.arrivals - The jobs that arrive.visitLogs - An optional set of visit log to which entries for dropped jobs (due to queue-access vacations)
are added (if the set is non-null).SimQueueState.isQueueAccessVacation()public void doStarts(double time,
Set<J> starters)
SimQueueStateThe start time cannot be in the past.
This method updates the server-access credits, and throws an exception if there are not sufficient server-access credits to start all jobs offered.
doStarts in interface SimQueueState<J extends SimJob,Q extends SimQueue>time - The start time.starters - The jobs that start.SimQueueState.getServerAccessCredits()public void doExits(double time,
Set<J> drops,
Set<J> revocations,
Set<J> departures,
Set<J> stickers,
Set<JobQueueVisitLog<J,Q>> visitLogs)
SimQueueStateThe removal time cannot be in the past.
doExits in interface SimQueueState<J extends SimJob,Q extends SimQueue>time - The removal time.drops - The jobs that drop, may be null.revocations - The jobs that are revoked, may be null.departures - The jobs that depart, may be null.stickers - The jobs that stick (never leave), may be null.visitLogs - An optional set of visit log to which entries for the leaving jobs
are added (if the set is non-null).public final void registerPostStartHook(DefaultSimQueueState.PostStartHook<J> postStartHook, Object userData)
postStartHook - The hook, non-null.userData - Optional user-data associated with the hook.IllegalArgumentException - If the hook is null or already registered.SimQueue.AutoRevocationPolicy.UPON_STARTCopyright © 2018. All rights reserved.