Package eu.mihosoft.devcom
Class Command<T>
java.lang.Object
eu.mihosoft.devcom.Command<T>
- Type Parameters:
T- the data type, e.g. String or Packet.
A command for sending and receiving data to/from a device.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetData()Returns the data to send.getReply()Returns the future reply.booleanIndicates whether cancellation has been requested.booleanIndicates whether this command has been consumed.booleanIndicates whether a reply is expected by this command.static <T> Command.Builder<T>Returns a new Command builder.voidRequests command cancellation.voidreset()Deprecated.toString()
-
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 sendonSent- consumer to call if a data has been sentreplyExpected- predicate that indicates whether a reply is expectedonReceived- consumer to call if a response has been receivedonError- consumer to call if an error occursonCancellationRequested- consumer called if cancellation has been requested
-
-
Method Details
-
reset
Deprecated.Resets this command for being reused for sending and receiving data. -
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:
trueif a reply is expected;falseotherwise
-
getReply
Returns the future reply.- Returns:
- reply
-
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;falseotherwise
-
requestCancellation
public void requestCancellation()Requests command cancellation. -
isCancellationRequested
public boolean isCancellationRequested()Indicates whether cancellation has been requested.- Returns:
if cancellation has been requested;falseotherwise
-
toString
-