Class IntResource<T extends Number & Comparable<T>>
- java.lang.Object
-
- org.djutils.event.LocalEventProducer
-
- nl.tudelft.simulation.examples.dsol.terminal.IntResource<T>
-
- Type Parameters:
T- the simulation time type to use.
- All Implemented Interfaces:
Serializable,Remote,EventProducer
public class IntResource<T extends Number & Comparable<T>> extends LocalEventProducer
A resource defines a shared and limited amount..Copyright (c) 2002-2023 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.
- Since:
- 1.5
- Author:
- Alexander Verbraeck
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classIntResource.Request<T extends Number & Comparable<T>>A Request.protected classIntResource.RequestComparatorthe RequestComparator.
-
Field Summary
Fields Modifier and Type Field Description protected longclaimedCapacityclaimedCapacity defines the currently claimed capacity.(package private) static AtomicLongcounterthe counter counting the requests.static intDEFAULT_REQUEST_PRIORITYthe default average priority.protected Stringdescriptionthe description of the resource.static intMAX_REQUEST_PRIORITYthe maximum priority.static intMIN_REQUEST_PRIORITYthe minimum priority.protected SortedSet<IntResource.Request<T>>requestsrequest defines the list of requestors for this resource.static EventTypeRESOURCE_REQUESTED_QUEUE_LENGTHRESOURCE_REQUESTED_QUEUE_LENGTH fired on changes in queue length.protected DevsSimulatorInterface<T>simulatorsimulator defines the simulator on which is scheduled.static EventTypeUTILIZATION_EVENTUTILIZATION_EVENT is fired on activity.-
Fields inherited from interface org.djutils.event.EventProducer
FIRST_POSITION, LAST_POSITION
-
-
Constructor Summary
Constructors Constructor Description IntResource(DevsSimulatorInterface<T> simulator, long capacity)Method Resource.IntResource(DevsSimulatorInterface<T> simulator, String description, long capacity)Method Resource.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetAvailableCapacity()returns the currently available capacity on this resource.longgetCapacity()returns the maximum, and thus original capacity of the resource.longgetClaimedCapacity()returns the amount of currently claimed capacity.intgetQueueLength()returns the number of instances currently waiting for this resource.voidreleaseCapacity(long amount)releases an amount of capacity from the resource.voidrequestCapacity(long amount, IntResourceRequestorInterface<T> requestor)requests an amount of capacity from the resource.voidrequestCapacity(long amount, IntResourceRequestorInterface<T> requestor, int priority)requests an amount of capacity from the resource.voidsetCapacity(long capacity)sets the capacity of the resource.StringtoString()-
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 Detail
-
counter
static AtomicLong counter
the counter counting the requests. package visibility, so Request can access it.
-
UTILIZATION_EVENT
public static final EventType UTILIZATION_EVENT
UTILIZATION_EVENT is fired on activity.
-
RESOURCE_REQUESTED_QUEUE_LENGTH
public static final EventType RESOURCE_REQUESTED_QUEUE_LENGTH
RESOURCE_REQUESTED_QUEUE_LENGTH fired on changes in queue length.
-
MIN_REQUEST_PRIORITY
public static final int MIN_REQUEST_PRIORITY
the minimum priority.- See Also:
- Constant Field Values
-
MAX_REQUEST_PRIORITY
public static final int MAX_REQUEST_PRIORITY
the maximum priority.- See Also:
- Constant Field Values
-
DEFAULT_REQUEST_PRIORITY
public static final int DEFAULT_REQUEST_PRIORITY
the default average priority.- See Also:
- Constant Field Values
-
claimedCapacity
protected long claimedCapacity
claimedCapacity defines the currently claimed capacity.
-
requests
protected SortedSet<IntResource.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.
-
description
protected String description
the description of the resource.
-
-
Constructor Detail
-
IntResource
public IntResource(DevsSimulatorInterface<T> simulator, String description, long capacity)
Method Resource.- Parameters:
simulator- DEVSSimulatorInterface<T>; on which is scheduleddescription- String; the description of this resourcecapacity- long; of the resource
-
IntResource
public IntResource(DevsSimulatorInterface<T> simulator, long capacity)
Method Resource.- Parameters:
simulator- DEVSSimulatorInterface<T>; on which is scheduledcapacity- long; of the resource
-
-
Method Detail
-
getCapacity
public long getCapacity()
returns the maximum, and thus original capacity of the resource.- Returns:
- capacity the maximum, and thus original capacity of the resource.
-
getClaimedCapacity
public long getClaimedCapacity()
returns the amount of currently claimed capacity.- Returns:
- the amount of currently claimed capacity.
-
getAvailableCapacity
public long 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(long capacity)
sets the capacity of the resource.- Parameters:
capacity- long; the new maximal capacity
-
requestCapacity
public void requestCapacity(long amount, IntResourceRequestorInterface<T> requestor) throws RemoteException, SimRuntimeExceptionrequests an amount of capacity from the resource.- Parameters:
amount- long; the requested amountrequestor- IntResourceRequestorInterface<T>; the RequestorInterface requesting the amount- Throws:
RemoteException- on network failureSimRuntimeException- on other failures
-
requestCapacity
public void requestCapacity(long amount, IntResourceRequestorInterface<T> requestor, int priority) throws RemoteException, SimRuntimeExceptionrequests an amount of capacity from the resource.- Parameters:
amount- long; the requested amountrequestor- IntResourceRequestorInterface<T>; the RequestorInterface requesting the amountpriority- int; the priority of the request- Throws:
RemoteException- on network failureSimRuntimeException- on other failures
-
releaseCapacity
public void releaseCapacity(long amount) throws RemoteExceptionreleases an amount of capacity from the resource.- Parameters:
amount- long; the amount to release- Throws:
RemoteException- on network failure
-
-