Skip to content

hololinked.core.eventloop.operations.Operation dataclass

The eventloop's operation model - One operation to perform on one interaction affordance of one Thing.

The transport-neutral unit of work.

Source code in repo/hololinked/hololinked/core/eventloop/operations.py
@dataclass
class Operation:
    """
    The eventloop's operation model - One operation to perform on one interaction affordance of one `Thing`.

    The transport-neutral unit of work.
    """

    thing_id: str
    """`id` of the `Thing` the operation is for."""
    objekt: str
    """name of the property, action or event."""
    operation: str
    """what to do with it - an `Operations` member such as `readproperty` or `invokeaction`."""

    payload: SerializableData = field(default_factory=lambda: SerializableData(None))
    """the operation's argument, still encoded until the executing `Thing` deserializes it."""
    preserialized_payload: PreserializedData = field(default_factory=lambda: PreserializedData(b""))
    """binary argument that bypasses serialization entirely."""

    scheduler_execution_context: SchedulerExecutionContext = field(
        default_factory=lambda: SchedulerExecutionContext(
            invokation_timeout=None,
            execution_timeout=None,
            oneway=False,
        )
    )
    """the timeouts, and whether a reply is wanted at all."""
    thing_execution_context: ThingExecutionContext = field(
        default_factory=lambda: ThingExecutionContext(fetch_execution_logs=False)
    )
    """what the `Thing` should do beside running the operation."""

    id: str = ""
    """identifier of the originating request. Correlation and logging only - never routed on."""
    sender_id: str = ""
    """identifier of whoever asked. Logging only."""

    @classmethod
    def create(
        cls,
        thing_id: str,
        objekt: str,
        operation: str,
        payload: SerializableData | None = None,
        preserialized_payload: PreserializedData | None = None,
        invokation_timeout: float | None = None,
        execution_timeout: float | None = None,
        oneway: bool = False,
        fetch_execution_logs: bool = False,
        id: str = "",
        sender_id: str = "",
    ) -> Operation:
        """
        Initialize an operation.

        Parameters
        ----------
        thing_id: str
            `id` of the `Thing` the operation is for
        objekt: str
            name of the property, action or event
        operation: str
            what to do with it, an `Operations` member
        payload: SerializableData, optional
            the operation's argument, still encoded
        preserialized_payload: PreserializedData, optional
            binary argument that bypasses serialization
        invokation_timeout: float, optional
            seconds to wait for the operation to start, `None` to wait indefinitely
        execution_timeout: float, optional
            seconds to wait for the operation to finish, `None` to wait indefinitely
        oneway: bool
            whether to discard the reply
        fetch_execution_logs: bool
            whether to return the `Thing`'s log records with the reply
        id: str
            identifier of the originating request
        sender_id: str
            identifier of whoever asked

        Returns
        -------
        Operation
            the operation, with the parameters grouped into their contexts
        """
        return cls(
            thing_id=thing_id,
            objekt=objekt,
            operation=operation,
            payload=SerializableData(None) if payload is None else payload,
            preserialized_payload=PreserializedData(b"") if preserialized_payload is None else preserialized_payload,
            scheduler_execution_context=SchedulerExecutionContext(
                invokation_timeout=invokation_timeout,
                execution_timeout=execution_timeout,
                oneway=oneway,
            ),
            thing_execution_context=ThingExecutionContext(fetch_execution_logs=fetch_execution_logs),
            id=id,
            sender_id=sender_id,
        )

    @property
    def qualified_name(self) -> str:
        """A key identifying this operation on this affordance of this `Thing`."""
        return qualified_operation_key(self.thing_id, self.objekt, self.operation)

Attributes

thing_id instance-attribute

thing_id: str

id of the Thing the operation is for.

objekt instance-attribute

objekt: str

name of the property, action or event.

operation instance-attribute

operation: str

what to do with it - an Operations member such as readproperty or invokeaction.

payload class-attribute instance-attribute

payload: SerializableData = field(default_factory=lambda: SerializableData(None))

the operation's argument, still encoded until the executing Thing deserializes it.

preserialized_payload class-attribute instance-attribute

preserialized_payload: PreserializedData = field(default_factory=lambda: PreserializedData(b''))

binary argument that bypasses serialization entirely.

scheduler_execution_context class-attribute instance-attribute

scheduler_execution_context: SchedulerExecutionContext = field(default_factory=lambda: SchedulerExecutionContext(invokation_timeout=None, execution_timeout=None, oneway=False))

the timeouts, and whether a reply is wanted at all.

thing_execution_context class-attribute instance-attribute

thing_execution_context: ThingExecutionContext = field(default_factory=lambda: ThingExecutionContext(fetch_execution_logs=False))

what the Thing should do beside running the operation.

sender_id class-attribute instance-attribute

sender_id: str = ''

identifier of whoever asked. Logging only.

id class-attribute instance-attribute

id: str = ''

identifier of the originating request. Correlation and logging only - never routed on.

Functions

__init__

__init__(thing_id: str, objekt: str, operation: str, payload: SerializableData = lambda: SerializableData(None)(), preserialized_payload: PreserializedData = lambda: PreserializedData(b'')(), scheduler_execution_context: SchedulerExecutionContext = lambda: SchedulerExecutionContext(invokation_timeout=None, execution_timeout=None, oneway=False)(), thing_execution_context: ThingExecutionContext = lambda: ThingExecutionContext(fetch_execution_logs=False)(), id: str = '', sender_id: str = '') -> None

qualified_name

qualified_name() -> str

A key identifying this operation on this affordance of this Thing.

Source code in repo/hololinked/hololinked/core/eventloop/operations.py
@property
def qualified_name(self) -> str:
    """A key identifying this operation on this affordance of this `Thing`."""
    return qualified_operation_key(self.thing_id, self.objekt, self.operation)

create classmethod

create(thing_id: str, objekt: str, operation: str, payload: SerializableData | None = None, preserialized_payload: PreserializedData | None = None, invokation_timeout: float | None = None, execution_timeout: float | None = None, oneway: bool = False, fetch_execution_logs: bool = False, id: str = '', sender_id: str = '') -> Operation

Initialize an operation.

Parameters:

Name Type Description Default

thing_id

str

id of the Thing the operation is for

required

objekt

str

name of the property, action or event

required

operation

str

what to do with it, an Operations member

required

payload

SerializableData | None

the operation's argument, still encoded

None

preserialized_payload

PreserializedData | None

binary argument that bypasses serialization

None

invokation_timeout

float | None

seconds to wait for the operation to start, None to wait indefinitely

None

execution_timeout

float | None

seconds to wait for the operation to finish, None to wait indefinitely

None

oneway

bool

whether to discard the reply

False

fetch_execution_logs

bool

whether to return the Thing's log records with the reply

False

id

str

identifier of the originating request

''

sender_id

str

identifier of whoever asked

''

Returns:

Type Description
Operation

the operation, with the parameters grouped into their contexts

Source code in repo/hololinked/hololinked/core/eventloop/operations.py
@classmethod
def create(
    cls,
    thing_id: str,
    objekt: str,
    operation: str,
    payload: SerializableData | None = None,
    preserialized_payload: PreserializedData | None = None,
    invokation_timeout: float | None = None,
    execution_timeout: float | None = None,
    oneway: bool = False,
    fetch_execution_logs: bool = False,
    id: str = "",
    sender_id: str = "",
) -> Operation:
    """
    Initialize an operation.

    Parameters
    ----------
    thing_id: str
        `id` of the `Thing` the operation is for
    objekt: str
        name of the property, action or event
    operation: str
        what to do with it, an `Operations` member
    payload: SerializableData, optional
        the operation's argument, still encoded
    preserialized_payload: PreserializedData, optional
        binary argument that bypasses serialization
    invokation_timeout: float, optional
        seconds to wait for the operation to start, `None` to wait indefinitely
    execution_timeout: float, optional
        seconds to wait for the operation to finish, `None` to wait indefinitely
    oneway: bool
        whether to discard the reply
    fetch_execution_logs: bool
        whether to return the `Thing`'s log records with the reply
    id: str
        identifier of the originating request
    sender_id: str
        identifier of whoever asked

    Returns
    -------
    Operation
        the operation, with the parameters grouped into their contexts
    """
    return cls(
        thing_id=thing_id,
        objekt=objekt,
        operation=operation,
        payload=SerializableData(None) if payload is None else payload,
        preserialized_payload=PreserializedData(b"") if preserialized_payload is None else preserialized_payload,
        scheduler_execution_context=SchedulerExecutionContext(
            invokation_timeout=invokation_timeout,
            execution_timeout=execution_timeout,
            oneway=oneway,
        ),
        thing_execution_context=ThingExecutionContext(fetch_execution_logs=fetch_execution_logs),
        id=id,
        sender_id=sender_id,
    )