Class Resource<T extends Number & Comparable<T>>

java.lang.Object
org.djutils.event.LocalEventProducer
nl.tudelft.simulation.dsol.formalisms.Resource<T>
Type Parameters:
T - the simulation time type
All Implemented Interfaces:
Serializable, Remote, org.djutils.base.Identifiable, org.djutils.event.EventProducer

public class Resource<T extends Number & Comparable<T>> extends org.djutils.event.LocalEventProducer implements org.djutils.base.Identifiable
A resource defines a shared and limited amount.

Copyright (c) 2002-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://simulation.tudelft.nl. The DSOL project is distributed under a three-clause BSD-style license, which can be found at https://https://simulation.tudelft.nl/dsol/docs/latest/license.html.

Author:
Peter Jacobs , Alexander Verbraeck
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A Request.
    static class 
    the RequestComparator.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    the default average priority.
    static final int
    the maximum priority.
    static final int
    the minimum priority.
    static final org.djutils.event.EventType
    QUEUE_LENGTH_EVENT fired on changes in queue length.
    static final org.djutils.event.EventType
    QUEUE_TIME_EVENT is fired wwhen a request is granted and provides the waiting time (which can be 0).
    protected final SortedSet<Resource.Request<T>>
    request defines the list of requestors for this resource.
    simulator defines the simulator on which is scheduled.
    static final org.djutils.event.EventType
    UTILIZATION_EVENT is fired on activity that decreases or increases the utilization.

    Fields inherited from interface org.djutils.event.EventProducer

    FIRST_POSITION, LAST_POSITION
  • Constructor Summary

    Constructors
    Constructor
    Description
    Resource(String resourceId, DevsSimulatorInterface<T> simulator, double capacity)
    Create a new Resource with a capacity and a default FIFO request comparator.
    Resource(String resourceId, DevsSimulatorInterface<T> simulator, double capacity, Comparator<Resource.Request<T>> requestComparator)
    Create a new Resource with a capacity and a specific request comparator, e.g., LIFO or sorted on an attribute.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    returns the currently available capacity on this resource.
    double
    returns the maximum, and thus original capacity of the resource.
    double
    returns the amount of currently claimed capacity.
    int
    returns the number of instances currently waiting for this resource.
    void
    releaseCapacity(double amount)
    releases an amount of capacity from the resource.
    void
    requestCapacity(double amount, ResourceRequestorInterface<T> requestor)
    requests an amount of capacity from the resource.
    void
    requestCapacity(double amount, ResourceRequestorInterface<T> requestor, int priority)
    requests an amount of capacity from the resource.
    void
    setCapacity(double capacity)
    sets the capacity of the resource.

    Methods inherited from class org.djutils.event.LocalEventProducer

    addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireUnverifiedEvent, fireUnverifiedEvent, fireUnverifiedTimedEvent, fireUnverifiedTimedEvent, getEventListenerMap, getEventTypesWithListeners, getListenerReferences, hasListeners, numberOfListeners, removeAllListeners, removeAllListeners, removeListener

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • UTILIZATION_EVENT

      public static final org.djutils.event.EventType UTILIZATION_EVENT
      UTILIZATION_EVENT is fired on activity that decreases or increases the utilization.
    • QUEUE_LENGTH_EVENT

      public static final org.djutils.event.EventType QUEUE_LENGTH_EVENT
      QUEUE_LENGTH_EVENT fired on changes in queue length.
    • QUEUE_WAITING_TIME_EVENT

      public static final org.djutils.event.EventType QUEUE_WAITING_TIME_EVENT
      QUEUE_TIME_EVENT is fired wwhen a request is granted and provides the waiting time (which can be 0).
    • MIN_REQUEST_PRIORITY

      public static final int MIN_REQUEST_PRIORITY
      the minimum priority.
      See Also:
    • MAX_REQUEST_PRIORITY

      public static final int MAX_REQUEST_PRIORITY
      the maximum priority.
      See Also:
    • DEFAULT_REQUEST_PRIORITY

      public static final int DEFAULT_REQUEST_PRIORITY
      the default average priority.
      See Also:
    • requests

      protected final SortedSet<Resource.Request<T extends Number & Comparable<T>>> requests
      request defines the list of requestors for this resource.
    • simulator

      protected DevsSimulatorInterface<T extends Number & Comparable<T>> simulator
      simulator defines the simulator on which is scheduled.
  • Constructor Details

    • Resource

      public Resource(String resourceId, DevsSimulatorInterface<T> simulator, double capacity, Comparator<Resource.Request<T>> requestComparator)
      Create a new Resource with a capacity and a specific request comparator, e.g., LIFO or sorted on an attribute.
      Parameters:
      resourceId - String; the id of this resource
      simulator - DevsSimulatorInterface<T>; the simulator
      capacity - double; the capacity of the resource
      requestComparator - Comparator<Request<T>>; the comparator to use
    • Resource

      public Resource(String resourceId, DevsSimulatorInterface<T> simulator, double capacity)
      Create a new Resource with a capacity and a default FIFO request comparator.
      Parameters:
      resourceId - String; the id of this resource
      simulator - DevsSimulatorInterface<T>; the simulator
      capacity - double; the capacity of the resource
  • Method Details

    • getId

      public String getId()
      Specified by:
      getId in interface org.djutils.base.Identifiable
    • getCapacity

      public double getCapacity()
      returns the maximum, and thus original capacity of the resource.
      Returns:
      capacity the maximum, and thus original capacity of the resource.
    • getClaimedCapacity

      public double getClaimedCapacity()
      returns the amount of currently claimed capacity.
      Returns:
      the amount of currently claimed capacity.
    • getAvailableCapacity

      public double getAvailableCapacity()
      returns the currently available capacity on this resource. This method is implemented as return this.getCapacity()-this.getClaimedCapacity()
      Returns:
      the currently available capacity on this resource.
    • getQueueLength

      public int getQueueLength()
      returns the number of instances currently waiting for this resource.
      Returns:
      the number of instances currently waiting for this resource
    • setCapacity

      public void setCapacity(double capacity)
      sets the capacity of the resource.
      Parameters:
      capacity - double; the new maximal capacity
    • requestCapacity

      public void requestCapacity(double amount, ResourceRequestorInterface<T> requestor) throws RemoteException, SimRuntimeException
      requests an amount of capacity from the resource.
      Parameters:
      amount - double; the requested amount
      requestor - ResourceRequestorInterface<T>; the RequestorInterface requesting the amount
      Throws:
      RemoteException - on network failure
      SimRuntimeException - on other failures
    • requestCapacity

      public void requestCapacity(double amount, ResourceRequestorInterface<T> requestor, int priority) throws RemoteException, SimRuntimeException
      requests an amount of capacity from the resource.
      Parameters:
      amount - double; the requested amount
      requestor - ResourceRequestorInterface<T>; the RequestorInterface requesting the amount
      priority - int; the priority of the request
      Throws:
      RemoteException - on network failure
      SimRuntimeException - on other failures
    • releaseCapacity

      public void releaseCapacity(double amount) throws RemoteException
      releases an amount of capacity from the resource.
      Parameters:
      amount - double; the amount to release
      Throws:
      RemoteException - on network failure
    • toString

      public String toString()
      Overrides:
      toString in class Object