NOTIFICATION OF SOCKET AND FILE EVENTS
The Selector component listens for events on sockets and sends out notifications. It is effectively a wrapper around the unix 'select' statement. Components request that the Selector component notify them when a supplied socket or file object is ready.
The selectorComponent is a service that registers with the Coordinating Assistant Tracker (CAT).
NOTE: The behaviour and API of this component changed in Kamaelia 0.4 and is likely to change again in the near future.
See the source code for TCPClient for an example of how the Selector component can be used.
Selector is a service. Obtain it by calling the static method Selector.getSelectorService(...). Any existing instance will be returned, otherwise a new one is automatically created.
This component ignores anything sent to its "inbox" and "control" inboxes. This component does not terminate.
Register socket or file objects with the selector, to receive a one-shot notification when that file descriptor is ready. The file descriptor can be a python file object or socket object. The notification is one-shot - meaning you must resubmit your request every time you wish to receive a notification.
Ensure you deregister the file object when closing the file/socket. You may do this even if you have already received the notification. The Selector component will be unable to handle notifications for any other descriptors if it still has a registered descriptor that has closed.
Register for a notification by sending an one of the following messages to the "notify" inbox, as returned by Selector.getSelectorService():
Choose which as appropriate:
Selector will notify the taret component by sending the file/socket descriptor object to the target inbox the component provided. It then automatically deregisters the descriptor, unlinking from the target component's inbox.
For a given descriptor for a given type of event (read/write/exceptional) only one notification will be sent when the event occurs. If multiple notification requests have been received, only the first is listened to; all others are ignored.
Of course, once the notification as happened, or someone has requested that descriptor be deregistered, then someone can register for it once again.
Deregister by sending on of the following messages to the "notify" inbox of Selector:
It is advisable to send a deregister message when the corresponding file descriptor closes, in case you registered for a notification, but it has not occurred.
Selector() -> new Selector component
Use Selector.getSelectorService(...) in preference as it returns an existing instance, or automatically creates a new one.
Methods defined here
Adds a file descriptor (selectable).
Creates a corresponding outbox, with name based on boxBase; links it to the component that wants to be notified; adds the file descriptor to the set of selectables; and records the box and linkage info in meta.
Process requests to add and remove file descriptors (selectables) that arrive at the "notify" inbox.
Removes a file descriptor (selectable).
Removes the corresponding entry from meta and selectables; unlinks from the component to be notified; and deletes the corresponding outbox.
Got a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording!
Please leave you feedback here in reply to the documentation thread in the Kamaelia blog.
-- Automatic documentation generator, 05 Jun 2009 at 03:01:38 UTC/GMT
This is an ongoing community based development site. As a result the contents of this page is the opinions of the contributors of the pages involved not the organisations involved. Specificially, this page may contain personal views which are not the views of the BBC. (the site is powered by a wiki engine)
(C) Copyright 2008 Kamaelia Contributors, including the British Broadcasting Corporation, All Rights Reserved.