Provides various kinds of Component classes.
Components are coroutines with context. That is, they are classes that implement ICoroutine, but can also store and access instance attributes.
Bases: object
Base class for components.
Components act like coroutines but can store and retrieve context via instance attributes. This corresponds in concept to Kamaelia's Component class.
Components have an internal coroutine defined in the _main() method, which sub-classes should implement.
Parameters: | kwargs (collections.Mapping) -- Any keyword arguments given at instantiation are automatically set as instance attributes for convenience. |
---|---|
Implements : | m4us.core.interfaces.ICoroutine |
Provides : | m4us.core.interfaces.ICoroutineFactory |
Sub-classes are expected to override this method. It should be a coroutine which will automatically be activated upon instantiation.
This coroutine should work just like regular coroutines, but has access to self and any context that the instance contains.
Terminate the component.
This method just calls close() on the component's internal coroutine defined in _main().
See also
The ICoroutine interface for details about this method.
Bases: m4us.core.components.Component
Component that passes all messages through.
This component is meant to provide a canonical example of what a component used with this project looks like.
Like sample_coroutine(), any messages sent to it on any inbox will be sent back out on it's outbox outbox. It is also well behaved in that it will shutdown on any IShutdown message, forwarding it on before quitting.
The full code for this component is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | @provider(ICoroutineFactory)
class SampleComponent(Component):
"""Component that passes all messages through."""
def _main(self):
"""Pass all messages through."""
inbox, message = (yield)
while True:
if is_shutdown(inbox, message):
yield 'signal', message
break
## Your code goes here.
inbox, message = (yield 'outbox', message)
|
Implements : | m4us.core.interfaces.ICoroutine |
---|---|
Provides : | m4us.core.interfaces.ICoroutineFactory |
See also
The sample_coroutine() coroutine for details on why the _main() method is written the way it is.