Behavior

abstract class Behavior<State : Any, Comm : Any, in Sensors : Any, out Actuators : Any>(executionScheduler: ExecutionScheduler, stateSerializer: KSerializer<StateOps<State>> = serializer(), commSerializer: KSerializer<CommunicationPayload<Comm>> = serializer(), sensorsSerializer: KSerializer<Sensors>, actuatorsSerializer: KSerializer<Actuators>) : AbstractPulverizedComponent

Represents the Behavior component in the pulverization model. The behavior can manage the State of the component, the Communication with the other devices, the Sensors and the Actuators. The behavior is executed according to the ExecutionScheduler.

Constructors

Link copied to clipboard
constructor(executionScheduler: ExecutionScheduler, stateSerializer: KSerializer<StateOps<State>> = serializer(), commSerializer: KSerializer<CommunicationPayload<Comm>> = serializer(), sensorsSerializer: KSerializer<Sensors>, actuatorsSerializer: KSerializer<Actuators>)

Properties

Link copied to clipboard
open lateinit override var di: DI
Link copied to clipboard
open val diContext: DIContext<*>
Link copied to clipboard
open val diTrigger: DITrigger?

Functions

Link copied to clipboard
open suspend override fun execute(): Either<ComponentError, Unit>

Starts the execution of the component logic. The execution may fail with a ComponentError. Before calling this method the setupWiring method MUST be called.

Link copied to clipboard
open suspend override fun finalize(): Either<ComponentError, Unit>

Asynchronously finalizes the entity. Can Either succeed or fail with an Error.

Link copied to clipboard
override fun getRef(): ComponentRef

Returns a symbolic reference to this component. This method is used internally by the runtime and should not be called by the user.

Link copied to clipboard
open suspend override fun initialize(): Either<ComponentError, Unit>

Asynchronously initializes the entity. Can Either succeed or fail with an Error.

Link copied to clipboard
abstract operator fun invoke(state: State?, comm: List<Comm>, sensors: Sensors?): BehaviourOutput<State, Comm, Actuators>

This method implements the logic of the device taking the state, comm and sensors. Returns a BehaviourOutput containing the new State, the Communication to be sent and the Actuators to be performed.

Link copied to clipboard
suspend override fun <P : Any> receive(fromComponent: ComponentRef, serializer: KSerializer<out P>): Either<ComponentError, Flow<P>>

Receives a message of type P by deserializing it with the given serializer. If the message pushed in the flow cannot be serialized with the given serializer the flow will fail with an exception. This method can fail with a ComponentNotRegistered if the fromComponent is not registered as link of this component.

Link copied to clipboard
inline suspend fun <P : Any> Component.receive(fromComponent: ComponentRef): Either<ComponentError, Flow<P>>

Helper method to receive messages fromComponent without specifying the serialization.

Link copied to clipboard
suspend override fun <P : Any> send(toComponent: ComponentRef, message: P, serializer: KSerializer<in P>): Either<ComponentError, Unit>

Sends a message of type P by serializing it with the given serializer. This method can fail with a ComponentNotRegistered if the toComponent is not registered as link of this component.

Link copied to clipboard
inline suspend fun <P : Any> Component.send(toComponent: ComponentRef, message: P): Either<ComponentError, Unit>

Helper method to send a message without specifying the serialization.

Link copied to clipboard
open override fun setupInjector(kodein: DI)

Configures the module of the dependency injection module that the resource will use.

Link copied to clipboard
open override fun setupWiring(vararg components: ComponentRef)

Setup all the other components to which this component will communicate. The components represents the symbolic references to the other components allowing a distributed communication. This method is generally called by the runtime when the pulverization model is adopted. In case of custom Logical Device partitioning this method should be called manually.