Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(2)  |  Call(0)  |  Derive(0)  |  Import(2)
=====================================================================
"Adaptive Comms Components" - can add and remove inboxes and outboxes
=====================================================================

An AdaptiveCommsComponent is just like an ordinary component but with the
ability to create and destroy extra inboxes and outboxes whilst it is running.

* An AdaptiveCommsComponent is based on an Axon.Component.component

There are other variants on the basic component:
    
* Axon.ThreadedComponent.threadedcomponent
* Axon.ThreadedComponent.threadedadaptivecommscomponent

If your component needs to block - eg. wait on a system call; then make it a
'threaded' component. If it needs to change what inboxes or outboxes it has at
runtime, then make it an 'adaptive' component. Otherwise, simply make it an
ordinary component!



Adding and removing inboxes and outboxes
----------------------------------------

To add a new inbox or outbox call self.addInbox() or self.addOutbox() specifying
a base name for the inbox/outbox. The created inbox or outbox is immediately
ready to be used.::

    actualInboxName = self.addInbox("inputData")
    actualOutboxName = self.addOutbox("outputData")

You specify a name you would ideally like the inbox or outbox to be given. If
that name is already taken then a variant of it will be generated. Calls to
addInbox() and addOutbox() therefore return the actual name the inbox or outbox
was given. You should always use this returned name. It is unwise to assume your
ideal choice of name has been allocated!

To remove a box, call self.deleteInbox() or self.deleteOutbox() specifying the
name of the box to be deleted::

    self.deleteInbox(actualInboxName)
    self.deleteOutbox(actualOutboxName)

When deleting an inbox or outbox, try to make sure that any linkages involving
that inbox/outbox have been destroyed. This includes not only linkages created
by your component, but any created by other components too.



Tracking resources
------------------

adaptivecommscomponent also includes an ability to track associations between
resources and inboxes, outboxes and other information.

For example, you might want to associate another component (that your component
is interacting with) with the set of inboxes, outboxes and any other info that
are being used to communicate with it.

You can also associate particular inboxes or outboxes with those resources. This
therefore allows you to map both ways: "which resource relates to this inbox?"
and "which inboxes relate to this resource?"

For example, suppose a request leads to your component creating an inbox and
outbox to deal with another component. You might store these as a tracked
resource, along with other information, such as the 'other' component and any
state or linkages that were created; and associate this resource with the inbox
from which data might arrive::

    def wireUpToOtherComponent(self, theComponent):
        newIn  = self.addInbox("commsIn")
        newOut = self.addOutbox("commsOut")
    
        newState = "WAITING"
        inLinkage  = self.link((theComponent,itsOutbox),(self,newIn))
        outLinkage = self.link((theComponent,itsInbox), (self,newOut))
    
        resource = theComponent

        inboxes = [newIn]
        outboxes = [newOut]
        info = (newState, inLinkage, outLinkage)
        self.trackResourceInformation(resource, inboxes, outboxes, info)

        self.trackResource(resource, newIn)

If a message then arrives at that inbox, we can easily look up all the
information we might need know where it came from and how to handle it::

    def handleMessageArrived(self, inboxName):
        msg = self.recv(inboxName)

        resource = self.retrieveResource(inboxName)
        inboxes, outboxes, info = self.retrieveResourceInformation(resource)
        theComponent=resource

        ...

When you are finished with a resource and its associated information you can
clean it up with the ceaseTrackingResource() method which removes the
association between the resource and information. For example when you get rid
of a set of linkages and inboxes or outboxes associated with another component
you might want to clean up the resource you were using to track this too::

    def doneWithComponent(self, theComponent):
        resource=theComponent
        inboxes, outboxes, info = self.retrieveResourceInformation(resource)

        for name in inboxes:
            self.deleteInbox(name)
        for name in outboxes:
            self.deleteOutbox(name)

        state,linkages = info[0], info[1:]
        for linkage in linkages:
            self.unlink(thelinkage=linkage)
        
        self.ceaseTrackingResource(resource)


        
Implementation
--------------

AdaptiveCommsComponent's functionality above and beyond the ordinary
Axon.Component.component is implemented in a separate mixin class
_AdaptiveCommsable. This enables it to be reused for other variants on the
basic component that need to inherit this functionality - such as the
threadedadaptivecommscomponent.

When adding new inboxes or outboxes, name clashes are resolved by permuting the
box name with a suffixed unique ID number until there is no longer any clash.

src/k/a/kamaelia-HEAD/Sketches/MH/exceptions/Axon/__init__.py   kamaelia(Download)
import debug
import util
import AdaptiveCommsComponent
import AxonExceptions
import CoordinatingAssistantTracker

src/k/a/Kamaelia-0.6.0/Axon/__init__.py   Kamaelia(Download)
import debug
import util
import AdaptiveCommsComponent
import AxonExceptions
import CoordinatingAssistantTracker