Interface Scheduler

All Superinterfaces:
Lifecycle

public interface Scheduler
extends Lifecycle
A Scheduler manages resources used by vehicles, preventing both collisions and deadlocks.
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Interface Description
    static interface  Scheduler.Client
    Defines callback methods for clients of the resource scheduler.
    static interface  Scheduler.Module
    A scheduler module.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.lang.String PROPKEY_BLOCK_ENTRY_DIRECTION
    The key of a path property defining the direction in which a vehicle is entering a block when it's taking the path.
  • Method Summary

    Modifier and Type Method Description
    void allocate​(Scheduler.Client client, java.util.Set<TCSResource<?>> resources)
    Requests allocation of the given resources.
    void allocateNow​(Scheduler.Client client, java.util.Set<TCSResource<?>> resources)
    Informs the scheduler that a set of resources are to be allocated for the given client immediately, i.e. without blocking.
    void claim​(Scheduler.Client client, java.util.List<java.util.Set<TCSResource<?>>> resourceSequence)
    Claims a set of resources for a vehicle.
    void free​(Scheduler.Client client, java.util.Set<TCSResource<?>> resources)
    Releases a set of resources allocated by a client.
    void freeAll​(Scheduler.Client client)
    Releases all resources allocation by the given client.
    java.util.Map<java.lang.String,​java.util.Set<TCSResource<?>>> getAllocations()
    Returns all resource allocations as a map of client IDs to resources.
    void preparationSuccessful​(Scheduler.Module module, Scheduler.Client client, java.util.Set<TCSResource<?>> resources)
    Informs the scheduler that a set of resources was successfully prepared in order of allocating them to a client.
    void unclaim​(Scheduler.Client client)
    Unclaims a set of resources claimed by a vehicle.
    void updateProgressIndex​(Scheduler.Client client, int index)
    Notifies the scheduler that the given client has now reached the given index in its claimed resource sequence, and that the client does not need the resources preceding the index in the sequence, any more.

    Methods inherited from interface org.opentcs.components.Lifecycle

    initialize, isInitialized, terminate
  • Field Details

  • Method Details

    • claim

      void claim​(@Nonnull Scheduler.Client client, @Nonnull java.util.List<java.util.Set<TCSResource<?>>> resourceSequence) throws java.lang.IllegalArgumentException
      Claims a set of resources for a vehicle.
      Parameters:
      client - The client claiming the resources.
      resourceSequence - The sequence of resources claimed.
      Throws:
      java.lang.IllegalArgumentException - If the given list of resources is empty, or if the client already holds a claim.
    • updateProgressIndex

      void updateProgressIndex​(@Nonnull Scheduler.Client client, int index) throws java.lang.IllegalArgumentException
      Notifies the scheduler that the given client has now reached the given index in its claimed resource sequence, and that the client does not need the resources preceding the index in the sequence, any more.
      Parameters:
      client - The client.
      index - The new index in the client's claimed resource sequence.
      Throws:
      java.lang.IllegalArgumentException - If the client does not hold a claim, or if the new index is larger than a valid index in its claim's resource sequence, or if the new index is not larger than the current index.
    • unclaim

      void unclaim​(@Nonnull Scheduler.Client client) throws java.lang.IllegalArgumentException
      Unclaims a set of resources claimed by a vehicle.
      Parameters:
      client - The client unclaiming the resources.
      Throws:
      java.lang.IllegalArgumentException - If the given client does not hold a claim.
    • allocate

      void allocate​(@Nonnull Scheduler.Client client, @Nonnull java.util.Set<TCSResource<?>> resources) throws java.lang.IllegalArgumentException
      Requests allocation of the given resources. The client will be notified via callback if the allocation was successful or not.
      Parameters:
      client - The client requesting the resources.
      resources - The resources requested.
      Throws:
      java.lang.IllegalArgumentException - If the given client did not claim any resources, or if the resources to be allocated are not in the set of currently claimed resources, or if the client has already requested resources that have not yet been granted.
    • allocateNow

      void allocateNow​(@Nonnull Scheduler.Client client, @Nonnull java.util.Set<TCSResource<?>> resources) throws ResourceAllocationException
      Informs the scheduler that a set of resources are to be allocated for the given client immediately, i.e. without blocking.

      This method should only be called in urgent/emergency cases, for instance if a vehicle has been moved to a different point manually, which has to be reflected by resource allocation in the scheduler.

      This method does not block, which means that it's safe to call it synchronously.
      Parameters:
      client - The client requesting the resources.
      resources - The resources requested.
      Throws:
      ResourceAllocationException - If it's impossible to allocate the given set of resources for the given client.
    • free

      void free​(@Nonnull Scheduler.Client client, @Nonnull java.util.Set<TCSResource<?>> resources)
      Releases a set of resources allocated by a client.
      Parameters:
      client - The client releasing the resources.
      resources - The resources released. Any resources in the given set not allocated by the given client are ignored.
    • freeAll

      void freeAll​(@Nonnull Scheduler.Client client)
      Releases all resources allocation by the given client.
      Parameters:
      client - The client.
    • getAllocations

      @Nonnull java.util.Map<java.lang.String,​java.util.Set<TCSResource<?>>> getAllocations()
      Returns all resource allocations as a map of client IDs to resources.
      Returns:
      All resource allocations as a map of client IDs to resources.
    • preparationSuccessful

      void preparationSuccessful​(@Nonnull Scheduler.Module module, @Nonnull Scheduler.Client client, @Nonnull java.util.Set<TCSResource<?>> resources)
      Informs the scheduler that a set of resources was successfully prepared in order of allocating them to a client.
      Parameters:
      module - The module a preparation was necessary for.
      client - The client that requested the preparation/allocation.
      resources - The resources that are now prepared for the client.