ProtocolController class

A controller to run protocols. It helps you to handle a sequence of messages that are part of a protocol.

Register the controller to the actor builder to process incoming message on a protocol. Use the runProtocol method to create a new instance of a protocol and run it.

In the init step it is important to pass the correlationId to the message so that the response can be correlated to.

Example:

final controller = ProtocolController();

controller.runProtocol(ctx, (builder) {
  // hold some protocol state here
  return builder //
    .init((ctx, correlationId) {
      // first step of the protocol (e.g. send a request to another actor)
    })
    .onMessage<String>((ctx, msg) {
      // handle incoming messages for the protocol (e.g. response from another actor)
    })
    .build();
});

final actor = ActorBuilder().withProtocolController(controller).orSkip();

Constructors

ProtocolController()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

actor(ActorContext ctx, Object? msg) Future<void>
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
predicate(ActorContext ctx, Object? msg) bool
runProtocol(ActorContext ctx, Protocol protocolBuilder(ProtocolBuilderInit builder)) → void
Create a new instance of a protocol and run it.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited