Hub

The Hub is the equivalent of the ORB - a central context for everything in the distributed object system.

The Hub has a registry which can be as simple as a dictionary or as sophisticated as a CORBA NamingContext. It must provide the getitem and setitem methods to dereference and assign keys to objects.

Methods

__clearContext(self)

   def __clearContext(self):

__connectionClosed(self, protoId, protoInfo)

   def __connectionClosed(self, protoId, protoInfo):

Called when a connection is closed.

__execInputLine(self)

   def __execInputLine(self):

__getAllProtocols(self)

   def __getAllProtocols(self):

Internal method to return all Protocol objects as a list.

__getObject(self, node, splitKey)

   def __getObject(self, node, splitKey):

Private version of getObject(), in which splitKey is a list.

__getSelectors(self, servers, rd, wr, er)

   def __getSelectors(self, servers, rd, wr, er):

Creates lists of objects for the select lists.

parms:

servers

[list<ProtocolServer>] list of servers

__init__(self, registry, threadMode)

   def __init__(self, registry, 
                threadMode = _haveThreads and THRD_FUNC or THRD_NONE
                ):

__needSelectThread(self)

   def __needSelectThread(self):

__processRequest(self, request, protocol)

   def __processRequest(self, request, protocol):

__selectLoop(self, msgId)

   def __selectLoop(self, msgId = None):

__serviceClient(self, clientConnection)

   def __serviceClient(self, clientConnection):

__serviceConnections(self, server)

   def __serviceConnections(self, server):

This is executed in a thread to begin servicing client connections for a particular server.

__serviceFunction(self, clientConnection, request)

   def __serviceFunction(self, clientConnection, request):

__setContext(self, context)

   def __setContext(self, context):

_getResponse(self, responseId)

   def _getResponse(self, responseId):

This function reenters the message processing loop and waits for a particular response.

If any response other that response should be received, a BadResponse exception will be raised.

addObject(self, key, object)

   def addObject(self, key, object):

Registers the object as a remote object under the name key (a string). Any kind of object can be registered.

Note that a key consisting of name parts seperated by forward slashes can be used, but it does not produce the results that one might expect after reading the documentation on getObject() - i.e. the object is not stored in a nested context.

addProtocol(self, proto)

   def addProtocol(self, proto):

This function should generally be called by the protocol constructor to register itself with the hub.

addReactor(self, reactor)

   def addReactor(self, reactor):

Adds a new reactor object to the hub's internal list. This will cause the reactor to be included in the select loop.

parms:

reactor

[ Reactor]

addServer(self, server)

   def addServer(self, server):

Registers server (an instance of ProtocolServer). In threaded communication mode, the hub will begin handling connections on the server in another thread.

getContext(self)

   def getContext(self):

Returns the current context object. This is only available from within a remote method call. If it is called from somewhere other than a remotely invoked method, None is returned.

getObject(self, fullKey)

   def getObject(self, fullKey):

Returns the object (the object that was added using addObject(), not necessarily a RemoteObject) associated with fullKey.

fullKey can resemble a UNIX path - that is, it can consist of name components seperated by forward slashes. If it is, and there is nothing matching the key in the registry, a recursive retrieval is performed.

getProtocol(self, protoId)

   def getProtocol(self, protoId):

This is used to get or create a protocol from its id. Returns the protocol if it already exists, creates it if it doesn't.

getRemoteObject(self, key, remoteFactory)

   def getRemoteObject(self, key, remoteFactory = None):

Returns a remote object for an object that has been added to the current hub identified by key.

parms:

key

[string] object key

remoteFactory

[ RemoteObjectFactory or None] if present, this is the remote object factory used to create the remote object. If not, DynamicRemoteObjectFactory is used.

getThreadMode(self)

   def getThreadMode(self):

Returns the hub's thread mode. Thread modes are:

THRD_NONE (0)

no threading

THRD_SELECT (1)

run "select()" loop in a background thread

THRD_FUNC (2)

Like THRD_SELECT but also create new threads for method invocations

THRD_COM (3)

Create a listening thread for each Protocol and ServerProtocol and each method invocation.

isThreaded(self)

   def isThreaded(self):

Returns true if the hub is threaded, false if not. The hub is threaded in all threads modes except THRD_NONE

mainloop(self)

   def mainloop(self):

makeAnonObject(self, object, remoteFactory)

   def makeAnonObject(self, object, remoteFactory = None):

Makes object into an anonymous remote object. Returns an instance of a RemoteObject derivative for the object.

Anonymous remote objects are remote objects that are registered without any particular key - presumably for temporary use. Actually, the key is the object's id - the address of the object.

If remoteFactory is supplied, it should be an instance of a class derived from RemoteObjectFactory. If it is not supplied, DynamicRemoteObjectFactory is used to create and return a DynamicRemoteObject.

makeRemoteObject(self, objectId, remoteFactory)

   def makeRemoteObject(self, objectId, remoteFactory = None):

Returns a remote object for the given object id. An object id consists of a protocol id followed by a colon and the object key.

If remoteFactory is supplied, it should be an instance of a class derived from RemoteObjectFactory. If it is not supplied, DynamicRemoteObjectFactory is used to create and return a DynamicRemoteObject.

processRequest(self, request)

   def processRequest(self, request):

Processes a request (an instance of Request) and returns the response (a Response).

removeObject(self, key)

   def removeObject(self, key):

Deregisters the object listed under the given key.

parms:

key

[string] object key.