Class Command<T>

java.lang.Object
eu.mihosoft.devcom.Command<T>
Type Parameters:
T - the data type, e.g. String or Packet.

public final class Command<T> extends Object
A command for sending and receiving data to/from a device.
  • Constructor Details

    • Command

      public Command(T data, Consumer<T> onSent, Boolean replyExpected, Consumer<T> onReceived, BiConsumer<T,​Exception> onError, Consumer<String> onCancellationRequested)
      Creates a new command.
      Parameters:
      data - data to send
      onSent - consumer to call if a data has been sent
      replyExpected - predicate that indicates whether a reply is expected
      onReceived - consumer to call if a response has been received
      onError - consumer to call if an error occurs
      onCancellationRequested - consumer called if cancellation has been requested
  • Method Details

    • reset

      @Deprecated public void reset()
      Deprecated.
      Resets this command for being reused for sending and receiving data.
    • newBuilder

      public static <T> Command.Builder<T> newBuilder()
      Returns a new Command builder.
      Type Parameters:
      T -
      Returns:
      a new Command builder
    • isReplyExpected

      public boolean isReplyExpected()
      Indicates whether a reply is expected by this command.
      Returns:
      true if a reply is expected; false otherwise
    • getReply

      public CompletableFuture<T> getReply()
      Returns the future reply.
      Returns:
      reply
    • getData

      public T getData()
      Returns the data to send.
      Returns:
      the data to send
    • isConsumed

      public boolean isConsumed()
      Indicates whether this command has been consumed.
      Returns:
      if this command has been consumed; false otherwise
    • requestCancellation

      public void requestCancellation()
      Requests command cancellation.
    • isCancellationRequested

      public boolean isCancellationRequested()
      Indicates whether cancellation has been requested.
      Returns:
      if cancellation has been requested; false otherwise
    • toString

      public String toString()
      Overrides:
      toString in class Object