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, Identifiable, EventProducer

public class Resource<T extends Number & Comparable<T>> extends LocalEventProducer implements 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:
  • Field Details

    • UTILIZATION_EVENT

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

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

      public static final 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 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