Class 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.
    • 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 positive
        reactor - 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 positive
        reactor - the RequestReactorIfc used to react to request changes, must not be null
        duration - 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 positive
        reactor - the RequestReactorIfc used to react to request changes, must not be null
        duration - the time duration for the request, determines the time of the request, must not be null
        entity - 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 positive
        resourceUnit - the resource unit, may be null
        reactor - the RequestReactorIfc used to react to request changes, must not be null
        duration - the time duration for the request, determines the time of the request, must not be null
        entity - 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 positive
        name - the name, may be null
        resourceUnit - the resource unit, may be null
        reactor - the RequestReactorIfc used to react to request changes, must not be null
        duration - the time duration for the request, determines the time of the request, must not be null
        entity - 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 positive
        name - the name, may be null
        resourceUnit - the resource unit, may be null
        reactor - the RequestReactorIfc used to react to request changes, must not be null
        duration - the time duration for the request, determines the time of the request, must not be null
        entity - the object (entity) attached to the request, can be null
        rule - 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 positive
        name - the name, may be null
        resourceUnit - the resource unit, may be null
        reactor - the RequestReactorIfc used to react to request changes, must not be null
        duration - the time duration for the request, determines the time of the request, must not be null
        entity - the object (entity) attached to the request, can be null
        rule - the request preemption rule, if null it is RESUME
        priority - 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 positive
        name - the name, may be null
        resourceUnit - the resource unit, may be null
        reactor - the RequestReactorIfc used to react to request changes, must not be null
        duration - the time duration for the request, determines the time of the request, if null it is set to Constant.POSITIVE_INFINITY
        entity - the object (entity) attached to the request, can be null
        rule - the request preemption rule, if null it is RESUME
        priority - the priority of the request within the queues that holds requests to be allocated for usage
        timeUnits - 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
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class QObject
      • 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 state
        time - the time of the state change