Skip to content

input_devices

messageflux.iodevices.base.input_devices

AggregatedInputDevice

AggregatedInputDevice(manager, inner_devices)

Bases: InputDevice[TManagerType]

this class is a round-robin input device, that reads from several underlying input devices in order

Parameters:

Name Type Description Default
manager TManagerType

the input device manager that created this device

required
inner_devices List[InputDevice]

the list of input devices to read from

required

last_read_device property

last_read_device

Returns:

Type Description

the last device that was read (in case it returned data/raised exception)

close

close()

tries to close underlying devices

InputDevice

InputDevice(manager, name)

Bases: Generic[TManagerType]

this is the base class for input devices

Parameters:

Name Type Description Default
manager TManagerType

the input device manager that created this device

required
name str

the name of this device

required

manager property

manager

Returns:

Type Description

the input device manager that created this device

name property

name

Returns:

Type Description

the name of this device

close

close()

and optional method that cleans device resources if necessary

read_message

read_message(
    cancellation_token, timeout=None, with_transaction=True
)

this method returns a message from the device. and makes sure that the input device name header is present

Parameters:

Name Type Description Default
cancellation_token Event

the cancellation token for this service. this can be used to know if cancellation was requested

required
timeout Optional[float]

an optional timeout (in seconds) to wait for the device to return a message. after 'timeout' seconds, if the device doesn't have a message to return, it will return None

None
with_transaction bool

'True' if the device should read message within transaction, or 'False' if the message is automatically committed

True

Returns:

Type Description
Optional[ReadResult]

a ReadResult object or None if no message was available. the device headers can contain extra information about the device that returned the message

InputDeviceException

InputDeviceException(
    *args, inner_exceptions=None, **kwargs
)

Bases: AggregatedException

a base exception class for all input device related exceptions

InputDeviceManager

InputDeviceManager(**kwargs)

Bases: Generic[TInputDeviceType]

this is the base class for input device managers. this class is used to create input devices.

connect

connect()

connects to the device manager

delete_input_device_from_cache

delete_input_device_from_cache(name)

deletes a cached input device from cache.

Parameters:

Name Type Description Default
name str

the device to delete from cache

required

Returns:

Type Description
bool

True if the device existed and deleted, False otherwise

disconnect

disconnect()

disconnects from the device manager

get_aggregate_device

get_aggregate_device(names)

creates an aggregated input device on all the devices with given names

Parameters:

Name Type Description Default
names List[str]

the names of the devices to create and aggregate

required

Returns:

Type Description
AggregatedInputDevice

the AggregatedInputDevice

get_input_device

get_input_device(name)

checks the cache for a device with 'name' and returns it. creates it if it's not in cache

Parameters:

Name Type Description Default
name str

the name of the input device to return

required

Returns:

Type Description
TInputDeviceType

the input device

ReadResult

ReadResult(
    message,
    device_headers=None,
    transaction=NULL_TRANSACTION,
)

Bases: MessageBundle

this class holds the result for "read_message". adds the transaction to the message bundle

Parameters:

Name Type Description Default
message Message

The Message.

required
device_headers Optional[DeviceHeaders]

Additional Headers that may return data from device, or affect its operation.

None
transaction InputTransaction

the transaction returned by the reading device

NULL_TRANSACTION

transaction property

transaction

the transaction returned by the reading device

commit

commit()

commits this read result

rollback

rollback()

rolls back this read result