Package jadex.future

Class CallMultiplexer

java.lang.Object
jadex.future.CallMultiplexer

public class CallMultiplexer extends Object
The CallMultiplexer unifies multiple executions of "similar" commands to a single execution. Multiple threads can attempt to call the command. When a "similar" call is already in progress, the thread will wait for the results of the call in progress instead of executing the command itself. Calls are considered "similar" depending on the chosen doCall() method. Similarity can depend simply on the command class itself, a set of key command parameters or both.
  • Field Details

    • futuremap

      protected Map<Object,IFuture<?>> futuremap
      Map of futures of calls that are in progress.
  • Constructor Details

    • CallMultiplexer

      public CallMultiplexer()
      Instantiates a call multiplexer. The same multiplexer must be shared by all "similar" calls to a command.
  • Method Details

    • doCall

      public IFuture<?> doCall(jadex.common.IResultCommand<Object,Object> call)
      Calls the command. If a "similar" call is in progress, wait for that call's results instead. All commands of the same class are considered "similar".
      Parameters:
      call - The command.
      Returns:
      The results, either from executing the call or "hitchhiking" on a "similar" call.
    • doCall

      public IFuture<?> doCall(Object keyargs, jadex.common.IResultCommand<Object,Object> call)
      Calls the command. If a "similar" call is in progress, wait for that call's results instead. All commands of the same class with the same key arguments are considered "similar".
      Parameters:
      keyargs - Key argument to differentiate whether calls are similar in addition to the command class, may be an array.
      call - The command.
      Returns:
      The results, either from executing the call or "hitchhiking" on a "similar" call.
    • doCall

      public IFuture<?> doCall(Object keyargs, jadex.common.IResultCommand<Object,Object> call, boolean commandaskey)
      Calls the command. If a "similar" call is in progress, wait for that call's results instead. All commands with the same key arguments and/or command class are considered "similar".
      Parameters:
      keyargs - Key argument to differentiate whether calls are similar in addition to the command class, may be an array.
      call - The command.
      commandaskey - Flag whether to consider the command class as part of the key differentiating calls.
      Returns:
      The results, either from executing the call or "hitchhiking" on a "similar" call.