Package jsl.modeling.resource
Class Request
- java.lang.Object
-
- jsl.modeling.queue.QObject
-
- jsl.modeling.resource.Request
-
- All Implemented Interfaces:
java.lang.Comparable<QObject>
,GetNameIfc
public class Request extends QObject
A Request represents a notification that the ResourceUnit is needed for allocation for a period of time. A builder pattern is available to facilitate construction of requests. The request of the resourceUnit may be preempted or not. The preemption rule determines how the request is handled if the resourceUnit attempts a preemption because of a failure or inactive period. The rules are: NONE = do not allow preemption, the request cannot be preempted RESUMABLE = request resumes with the time remaining after preemption RESTART = the request restarts using its original time after preemption CANCEL = the request should be canceled upon preemption A request can be in 1 of 7 states: CreatedState = newly made, can only transition to ReadyState or RejectedState ReadyState = ready to do something, can only transition to WaitingState, CanceledState, or AllocatedState WaitingState = waiting for resourceUnit, can only transition to ReadyState RejectedState = rejected after creation, no further transitions permitted CanceledState = can cancel from ReadyState or AllocatedState, no further transitions AllocatedState = using the resourceUnit, may preempted, canceled, or completed Preempted = preempted from using the resourceUnit, can resumed or cancel Completed = finished its life-cycle, no further transitions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
Request.AllocatedState
protected static class
Request.Builder
static interface
Request.BuildStep
protected class
Request.CanceledState
protected class
Request.Completed
protected class
Request.CreatedState
Represents a freshly made Request.static interface
Request.CreateTimeStep
protected class
Request.Preempted
static class
Request.PreemptionRule
protected class
Request.PreparedState
A Request that is prepared can wait, be canceled, or transition to being in allocate.static interface
Request.ReactorStep
protected class
Request.RejectedState
protected class
Request.RequestState
protected class
Request.WaitingState
-
Field Summary
-
Fields inherited from class jsl.modeling.queue.QObject
myTimeStamp, myValue
-
-
Constructor Summary
Constructors Constructor Description Request(double creationTime, java.lang.String name, ResourceUnit resourceUnit, RequestReactorIfc reactor, GetValueIfc duration, java.lang.Object entity)
The builder provides a more semantically meaningful way of constructing a request.Request(double creationTime, java.lang.String name, ResourceUnit resourceUnit, RequestReactorIfc reactor, GetValueIfc duration, java.lang.Object entity, Request.PreemptionRule rule)
The builder provides a more semantically meaningful way of constructing a request.Request(double creationTime, java.lang.String name, ResourceUnit resourceUnit, RequestReactorIfc reactor, GetValueIfc duration, java.lang.Object entity, Request.PreemptionRule rule, int priority)
The builder provides a more semantically meaningful way of constructing a request.Request(double creationTime, java.lang.String name, ResourceUnit resourceUnit, RequestReactorIfc reactor, GetValueIfc duration, java.lang.Object entity, Request.PreemptionRule rule, int priority, double timeUnits)
The builder provides a more semantically meaningful way of constructing a requestRequest(double creationTime, RequestReactorIfc reactor)
The builder provides a more semantically meaningful way of constructing a request.Request(double creationTime, RequestReactorIfc reactor, GetValueIfc duration)
The builder provides a more semantically meaningful way of constructing a request.Request(double creationTime, RequestReactorIfc reactor, GetValueIfc duration, java.lang.Object entity)
The builder provides a more semantically meaningful way of constructing a request.Request(double creationTime, ResourceUnit resourceUnit, RequestReactorIfc reactor, GetValueIfc duration, java.lang.Object entity)
The builder provides a more semantically meaningful way of constructing a request.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Request.CreateTimeStep
builder()
Creates a Builder that can be used to step through the construction of a Request.void
cancel()
Causes the request to be canceled by the resourceboolean
doesNotAllowPreemption()
double
getInitialRequestTime()
The initial time associated with the requestdouble
getNumPreemptions()
Request.PreemptionRule
getPreemptionRule()
If the request can be preempted during its allocate of the resourceUnitjava.util.Optional<ResourceUnit>
getResourceUnit()
If the request has not be allocate to a resource unit yet, then the resource unit will be null.protected double
getTime()
The request must be allocate to a resource unit.double
getTimeCompleted()
double
getTimeEnteredCurrentState()
May return Double.NaN if state was never entereddouble
getTimeEnteredPreviousState()
May return Double.NaN if state was never entereddouble
getTimeExitedCurrentState()
May return Double.NaN if state was never exiteddouble
getTimeExitedPreviousState()
May return Double.NaN if state was never exiteddouble
getTimeFirstEnteredUsingState()
double
getTimeFirstEnteredWaitingState()
double
getTimeRemaining()
GetValueIfc
getTimeSetter()
double
getTimeUnits()
double
getTimeUntilCompletion()
double
getTotalPreemptionTime()
double
getWaitingTime()
boolean
isAllocated()
boolean
isCanceled()
boolean
isCreated()
boolean
isFinished()
Indicates that the request has been finished.boolean
isPreempted()
boolean
isPreviousStateAllocated()
boolean
isPreviousStateCreated()
boolean
isPreviousStatePreempted()
boolean
isPreviousStateReady()
boolean
isPreviousStateWaiting()
boolean
isReady()
boolean
isRejected()
boolean
isWaiting()
void
release()
Causes the request to be released by the resource.protected void
setState(Request.RequestState state, double time)
Sets the state.java.lang.String
toString()
-
Methods inherited from class jsl.modeling.queue.QObject
compareTo, enterQueue, exitQueue, getAttachedObject, getCreateTime, getId, getName, getPriority, getQueue, getQueuedState, getTimeEnteredQueue, getTimeExitedQueue, getTimeInQueue, getTimeStamp, getValueObject, initialize, isQueued, nullify, setAttachedObject, setName, setNulls, setPriority, setPriority_, setQueue, setTimeStamp, setValueObject
-
-
-
-
Constructor Detail
-
Request
public Request(double creationTime, RequestReactorIfc reactor)
The builder provides a more semantically meaningful way of constructing a request. Time timeUnits is 1.0, priority = JSLEvent.DEFAULT_PRIORITY, PreemptionRule.RESUME, name = null, ResourceUnit = null, attached object = null, request time = Constant.POSITIVE_INFINITY- Parameters:
creationTime
- the time the request was created, must be positivereactor
- the RequestReactorIfc used to react to request changes, must not be null
-
Request
public Request(double creationTime, RequestReactorIfc reactor, GetValueIfc duration)
The builder provides a more semantically meaningful way of constructing a request. Time timeUnits is 1.0, priority = JSLEvent.DEFAULT_PRIORITY, PreemptionRule.RESUME, name = null, ResourceUnit = null, attached object = null- Parameters:
creationTime
- the time the request was created, must be positivereactor
- the RequestReactorIfc used to react to request changes, must not be nullduration
- the time duration for the request, determines the time of the request, must not be null
-
Request
public Request(double creationTime, RequestReactorIfc reactor, GetValueIfc duration, java.lang.Object entity)
The builder provides a more semantically meaningful way of constructing a request. Time timeUnits is 1.0, priority = JSLEvent.DEFAULT_PRIORITY, PreemptionRule.RESUME, name = null, ResourceUnit = null- Parameters:
creationTime
- the time the request was created, must be positivereactor
- the RequestReactorIfc used to react to request changes, must not be nullduration
- the time duration for the request, determines the time of the request, must not be nullentity
- the object (entity) attached to the request, can be null
-
Request
public Request(double creationTime, ResourceUnit resourceUnit, RequestReactorIfc reactor, GetValueIfc duration, java.lang.Object entity)
The builder provides a more semantically meaningful way of constructing a request. Time timeUnits is 1.0, priority = JSLEvent.DEFAULT_PRIORITY, PreemptionRule.RESUME, name = null- Parameters:
creationTime
- the time the request was created, must be positiveresourceUnit
- the resource unit, may be nullreactor
- the RequestReactorIfc used to react to request changes, must not be nullduration
- the time duration for the request, determines the time of the request, must not be nullentity
- the object (entity) attached to the request, can be null
-
Request
public Request(double creationTime, java.lang.String name, ResourceUnit resourceUnit, RequestReactorIfc reactor, GetValueIfc duration, java.lang.Object entity)
The builder provides a more semantically meaningful way of constructing a request. Time timeUnits is 1.0, priority = JSLEvent.DEFAULT_PRIORITY, PreemptionRule.RESUME- Parameters:
creationTime
- the time the request was created, must be positivename
- the name, may be nullresourceUnit
- the resource unit, may be nullreactor
- the RequestReactorIfc used to react to request changes, must not be nullduration
- the time duration for the request, determines the time of the request, must not be nullentity
- the object (entity) attached to the request, can be null
-
Request
public Request(double creationTime, java.lang.String name, ResourceUnit resourceUnit, RequestReactorIfc reactor, GetValueIfc duration, java.lang.Object entity, Request.PreemptionRule rule)
The builder provides a more semantically meaningful way of constructing a request. Time timeUnits is 1.0, priority = JSLEvent.DEFAULT_PRIORITY- Parameters:
creationTime
- the time the request was created, must be positivename
- the name, may be nullresourceUnit
- the resource unit, may be nullreactor
- the RequestReactorIfc used to react to request changes, must not be nullduration
- the time duration for the request, determines the time of the request, must not be nullentity
- the object (entity) attached to the request, can be nullrule
- the request preemption rule, if null it is RESUME
-
Request
public Request(double creationTime, java.lang.String name, ResourceUnit resourceUnit, RequestReactorIfc reactor, GetValueIfc duration, java.lang.Object entity, Request.PreemptionRule rule, int priority)
The builder provides a more semantically meaningful way of constructing a request. Time timeUnits is 1.0- Parameters:
creationTime
- the time the request was created, must be positivename
- the name, may be nullresourceUnit
- the resource unit, may be nullreactor
- the RequestReactorIfc used to react to request changes, must not be nullduration
- the time duration for the request, determines the time of the request, must not be nullentity
- the object (entity) attached to the request, can be nullrule
- the request preemption rule, if null it is RESUMEpriority
- the priority of the request within the queues that allocate priority
-
Request
public Request(double creationTime, java.lang.String name, ResourceUnit resourceUnit, RequestReactorIfc reactor, GetValueIfc duration, java.lang.Object entity, Request.PreemptionRule rule, int priority, double timeUnits)
The builder provides a more semantically meaningful way of constructing a request- Parameters:
creationTime
- the time the request was created, must be positivename
- the name, may be nullresourceUnit
- the resource unit, may be nullreactor
- the RequestReactorIfc used to react to request changes, must not be nullduration
- the time duration for the request, determines the time of the request, if null it is set to Constant.POSITIVE_INFINITYentity
- the object (entity) attached to the request, can be nullrule
- the request preemption rule, if null it is RESUMEpriority
- the priority of the request within the queues that holds requests to be allocated for usagetimeUnits
- how the request time will be interpreted, see ModelElement, the default is 1
-
-
Method Detail
-
builder
public static Request.CreateTimeStep builder()
Creates a Builder that can be used to step through the construction of a Request. The request must have a creation time and a RequestReactorIfc associated with it.- Returns:
- the builder
-
getTimeUnits
public final double getTimeUnits()
- Returns:
- The addFactor representing the time timeUnits of the request
-
getNumPreemptions
public final double getNumPreemptions()
- Returns:
- number of times that the request was preempted
-
getTotalPreemptionTime
public final double getTotalPreemptionTime()
- Returns:
- the amount of time that the request spent preempted
-
getResourceUnit
public final java.util.Optional<ResourceUnit> getResourceUnit()
If the request has not be allocate to a resource unit yet, then the resource unit will be null.- Returns:
- the resourceUnit associated with the request
-
isCreated
public final boolean isCreated()
- Returns:
- true if in the created state
-
isReady
public final boolean isReady()
- Returns:
- true if in the ready state
-
isRejected
public final boolean isRejected()
- Returns:
- true if in the rejected state
-
isCanceled
public final boolean isCanceled()
- Returns:
- rue if in the canceled state
-
isFinished
public final boolean isFinished()
Indicates that the request has been finished. That is, whether or not the request is finished using the allocated resource unit- Returns:
- true if finished
-
isWaiting
public final boolean isWaiting()
- Returns:
- true if in the waiting state
-
isAllocated
public final boolean isAllocated()
- Returns:
- true if in the using state
-
isPreempted
public final boolean isPreempted()
- Returns:
- true if in the preempted state
-
isPreviousStateReady
public final boolean isPreviousStateReady()
- Returns:
- true if previous state was created
-
isPreviousStateCreated
public final boolean isPreviousStateCreated()
- Returns:
- true if previous state was created
-
isPreviousStateWaiting
public final boolean isPreviousStateWaiting()
- Returns:
- true if previous state was waiting
-
isPreviousStateAllocated
public final boolean isPreviousStateAllocated()
- Returns:
- true if previous state was using
-
isPreviousStatePreempted
public final boolean isPreviousStatePreempted()
- Returns:
- true if previous state was preempted
-
getTimeEnteredCurrentState
public final double getTimeEnteredCurrentState()
May return Double.NaN if state was never entered- Returns:
- the time the current state was entered
-
getTimeExitedCurrentState
public final double getTimeExitedCurrentState()
May return Double.NaN if state was never exited- Returns:
- the time that the current state was exited
-
getTimeEnteredPreviousState
public final double getTimeEnteredPreviousState()
May return Double.NaN if state was never entered- Returns:
- the time that the previous state was entered
-
getTimeExitedPreviousState
public final double getTimeExitedPreviousState()
May return Double.NaN if state was never exited- Returns:
- the time that the previous state was exited
-
getWaitingTime
public final double getWaitingTime()
- Returns:
- the time from when the request tried to allocate the ResourceUnit until it actually started using the unit
-
getTimeFirstEnteredUsingState
public final double getTimeFirstEnteredUsingState()
- Returns:
- the time that the request started using the resourceUnit
-
getTimeRemaining
public final double getTimeRemaining()
- Returns:
- the time remaining on the request
-
getTimeFirstEnteredWaitingState
public final double getTimeFirstEnteredWaitingState()
- Returns:
- the time that the request first entered the wait state
-
getTime
protected final double getTime()
The request must be allocate to a resource unit.- Returns:
- the current simulation time
-
getTimeUntilCompletion
public final double getTimeUntilCompletion()
- Returns:
- the time from when the request tried to allocate the ResourceUnit until it finally finished its allocate of the unit.
-
getTimeCompleted
public final double getTimeCompleted()
- Returns:
- the time that the request was finished or Double.NaN if not yet finished
-
getInitialRequestTime
public final double getInitialRequestTime()
The initial time associated with the request- Returns:
- time associated with the request
-
getPreemptionRule
public final Request.PreemptionRule getPreemptionRule()
If the request can be preempted during its allocate of the resourceUnit- Returns:
- the rule
-
doesNotAllowPreemption
public final boolean doesNotAllowPreemption()
- Returns:
- true if the request does not allow preemption, i.e. the PreemptionRule is NONE
-
getTimeSetter
public final GetValueIfc getTimeSetter()
- Returns:
- the thing that determines the time of the request
-
cancel
public final void cancel()
Causes the request to be canceled by the resource
-
release
public final void release()
Causes the request to be released by the resource. This is immediate. The resource must be busy with this request. If a usage time has been scheduled (internally) to the resource, it is canceled. The request must be in the isAllocated() state.
-
setState
protected void setState(Request.RequestState state, double time)
Sets the state. Notification of state change is embedded within inner RequestState sub-classes.- Parameters:
state
- the new statetime
- the time of the state change
-
-