Package nl.tudelft.simulation.examples.dsol.terminal

# Class IntResource<A extends Comparable<A> & Serializable,​R extends Number & Comparable<R>,​T extends SimTime<A,​R,​T>>

java.lang.Object
org.djutils.event.EventProducer
nl.tudelft.simulation.examples.dsol.terminal.IntResource<A,​R,​T>

Type Parameters:
  `A` - the absolute time type to use in timed events
  `R` - the relative time type
  `T` - the simulation time type to use.

All Implemented Interfaces:
  `Serializable`, `org.djutils.event.EventProducerInterface`

Direct Known Subclasses:
  `AGV`, `QC`

    public class IntResource<A extends Comparable<A> & Serializable,​R extends Number & Comparable<R>,​T extends SimTime<A,​R,​T>>
    extends org.djutils.event.EventProducer

A resource defines a shared and limited amount..

Copyright (c) 2002-2020 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://simulation.tudelft.nl/dsol/3.0/license.html.

Since:
  1.5
Author:
  Alexander Verbraeck
See Also:
  Serialized Form

## Nested Class Summary

Nested Classes
Modifier and Type | Class | Description
--- | --- | ---
`static class` | `IntResource.Request<A extends Comparable<A> & Serializable,​R extends Number & Comparable<R>,​T extends SimTime<A,​R,​T>>` | A Request.
`protected class` | `IntResource.RequestComparator` | the RequestComparator.

## Field Summary

Fields
Modifier and Type | Field | Description
--- | --- | ---
`protected long` | `claimedCapacity` | claimedCapacity defines the currently claimed capacity.
`(package private) static AtomicLong` | `counter` | the counter counting the requests.
`static int` | `DEFAULT_REQUEST_PRIORITY` | the default average priority.
`protected String` | `description` | the description of the resource.
`static int` | `MAX_REQUEST_PRIORITY` | the maximum priority.
`static int` | `MIN_REQUEST_PRIORITY` | the minimum priority.
`protected SortedSet<IntResource.Request<A,​R,​T>>` | `requests` | request defines the list of requestors for this resource.
`static org.djutils.event.EventType` | `RESOURCE_REQUESTED_QUEUE_LENGTH` | RESOURCE_REQUESTED_QUEUE_LENGTH fired on changes in queue length.
`protected DEVSSimulatorInterface<A,​R,​T>` | `simulator` | simulator defines the simulator on which is scheduled.
`static org.djutils.event.EventType` | `UTILIZATION_EVENT` | UTILIZATION_EVENT is fired on activity.

### Fields inherited from class org.djutils.event.EventProducer

`eventProducerImpl`

### Fields inherited from interface org.djutils.event.EventProducerInterface

`FIRST_POSITION, LAST_POSITION`

## Constructor Summary

Constructors
Constructor | Description
--- | ---
`IntResource​(DEVSSimulatorInterface<A,​R,​T> simulator, long capacity)` | Method Resource.
`IntResource​(DEVSSimulatorInterface<A,​R,​T> simulator, String description, long capacity)` | Method Resource.

## Method Summary

Modifier and Type | Method | Description
--- | --- | ---
`long` | `getAvailableCapacity()` | returns the currently available capacity on this resource.
`long` | `getCapacity()` | returns the maximum, and thus original capacity of the resource.
`long` | `getClaimedCapacity()` | returns the amount of currently claimed capacity.
`int` | `getQueueLength()` | returns the number of instances currently waiting for this resource.
`Serializable` | `getSourceId()`
`void` | `releaseCapacity​(long amount)` | releases an amount of capacity from the resource.
`void` | `requestCapacity​(long amount, IntResourceRequestorInterface<A,​R,​T> requestor)` | requests an amount of capacity from the resource.
`void` | `requestCapacity​(long amount, IntResourceRequestorInterface<A,​R,​T> requestor, int priority)` | requests an amount of capacity from the resource.
`void` | `setCapacity​(long capacity)` | sets the capacity of the resource.
`String` | `toString()`

### Methods inherited from class org.djutils.event.EventProducer

`addListener, addListener, addListener, addListener, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, fireTimedEvent, 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

### counter

static AtomicLong counter
the counter counting the requests. package visibility, so Request can access it.

### UTILIZATION_EVENT

public static final org.djutils.event.EventType UTILIZATION_EVENT
UTILIZATION_EVENT is fired on activity.

### RESOURCE_REQUESTED_QUEUE_LENGTH

public static final org.djutils.event.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<A extends Comparable<A> & Serializable,​R extends Number & Comparable<R>,​T extends SimTime<A,​R,​T>>> requests
request defines the list of requestors for this resource.

### simulator

protected DEVSSimulatorInterface<A extends Comparable<A> & Serializable,​R extends Number & Comparable<R>,​T extends SimTime<A,​R,​T>> simulator
simulator defines the simulator on which is scheduled.

### description

protected String description
the description of the resource.

## Constructor Details

### IntResource

public IntResource​(DEVSSimulatorInterface<A,​R,​T> simulator, String description, long capacity)
Method Resource.

Parameters:
  `simulator` - DEVSSimulatorInterface<A,R,T>; on which is scheduled
  `description` - String; the description of this resource
  `capacity` - long; of the resource

### IntResource

public IntResource​(DEVSSimulatorInterface<A,​R,​T> simulator, long capacity)
Method Resource.

Parameters:
  `simulator` - DEVSSimulatorInterface<A,R,T>; on which is scheduled
  `capacity` - long; of the resource

## Method Details

### getCapacity

public final 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 final long getClaimedCapacity()
returns the amount of currently claimed capacity.

Returns:
  the amount of currently claimed capacity.

### getAvailableCapacity

public final long 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 final int getQueueLength()
returns the number of instances currently waiting for this resource.

Returns:
  the number of instances currently waiting for this resource

### setCapacity

public final void setCapacity​(long capacity)
sets the capacity of the resource.

Parameters:
  `capacity` - long; the new maximal capacity

### requestCapacity

public final void requestCapacity​(long amount, IntResourceRequestorInterface<A,​R,​T> requestor) throws RemoteException, SimRuntimeException
requests an amount of capacity from the resource.

Parameters:
  `amount` - long; the requested amount
  `requestor` - IntResourceRequestorInterface<A,R,T>; the RequestorInterface requesting the amount
Throws:
  `RemoteException` - on network failure
  `SimRuntimeException` - on other failures

### requestCapacity

public final void requestCapacity​(long amount, IntResourceRequestorInterface<A,​R,​T> requestor, int priority) throws RemoteException, SimRuntimeException
requests an amount of capacity from the resource.

Parameters:
  `amount` - long; the requested amount
  `requestor` - IntResourceRequestorInterface<A,R,T>; the RequestorInterface requesting the amount
  `priority` - int; the priority of the request
Throws:
  `RemoteException` - on network failure
  `SimRuntimeException` - on other failures

### releaseCapacity

public final void releaseCapacity​(long amount) throws RemoteException
releases an amount of capacity from the resource.

Parameters:
  `amount` - long; the amount to release
Throws:
  `RemoteException` - on network failure

### getSourceId

public Serializable getSourceId()

Specified by:
  `getSourceId` in interface `org.djutils.event.EventProducerInterface`
Specified by:
  `getSourceId` in class `org.djutils.event.EventProducer`

### toString

public String toString()

Overrides:
  `toString` in class `Object`