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:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Resource.Request<T extends Number & Comparable<T>>
A Request.static class
Resource.RequestComparator<T extends Number & Comparable<T>>
the RequestComparator. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
the default average priority.static final int
the maximum priority.static final int
the minimum priority.static final EventType
QUEUE_LENGTH_EVENT fired on changes in queue length.static final 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.protected DevsSimulatorInterface<T>
simulator defines the simulator on which is scheduled.static final 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
ConstructorDescriptionResource
(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 TypeMethodDescriptiondouble
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.getId()
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.toString()
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
-
Field Details
-
UTILIZATION_EVENT
UTILIZATION_EVENT is fired on activity that decreases or increases the utilization. -
QUEUE_LENGTH_EVENT
QUEUE_LENGTH_EVENT fired on changes in queue length. -
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_PRIORITYthe minimum priority.- See Also:
-
MAX_REQUEST_PRIORITY
public static final int MAX_REQUEST_PRIORITYthe maximum priority.- See Also:
-
DEFAULT_REQUEST_PRIORITY
public static final int DEFAULT_REQUEST_PRIORITYthe default average priority.- See Also:
-
requests
request defines the list of requestors for this resource. -
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 resourcesimulator
- DevsSimulatorInterface<T>; the simulatorcapacity
- double; the capacity of the resourcerequestComparator
- Comparator<Request<T>>; the comparator to use
-
Resource
Create a new Resource with a capacity and a default FIFO request comparator.- Parameters:
resourceId
- String; the id of this resourcesimulator
- DevsSimulatorInterface<T>; the simulatorcapacity
- double; the capacity of the resource
-
-
Method Details
-
getId
- Specified by:
getId
in interfaceIdentifiable
-
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 asreturn 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 amountrequestor
- ResourceRequestorInterface<T>; the RequestorInterface requesting the amount- Throws:
RemoteException
- on network failureSimRuntimeException
- 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 amountrequestor
- ResourceRequestorInterface<T>; the RequestorInterface requesting the amountpriority
- int; the priority of the request- Throws:
RemoteException
- on network failureSimRuntimeException
- on other failures
-
releaseCapacity
releases an amount of capacity from the resource.- Parameters:
amount
- double; the amount to release- Throws:
RemoteException
- on network failure
-
toString
-