Previous Up Next

Chapter 9  Interceptors

omniORBpy has limited interceptor support. Interceptors permit the application to insert processing at various points along the call chain, as requests are processed. The Portable Interceptors API is not supported.

9.1  Request interceptors

Interceptors for incoming and outgoing requests are registered using functions in the omniORB.interceptors module:

addClientSendRequest() addClientReceiveReply() addServerReceiveRequest() addServerSendReply() addServerSendException()

To register an interceptor function, call the relevant registration function with a callable argument. The callable will be called with two or three arguments. The first argument is a string containing the name of the operation being invoked; the second is the collection of service contexts to be retrieved or filled in. ServerSendException has a third argument, the repository id of the exception being thrown.

When receiving service contexts (in the ClientReceiveReply and ServerReceiveRequest interceptors), the second argument is a tuple of 2-tuples. In each 2-tuple, the first item is the service context id and the second item is the CDR encapsulation of the service context. The encapsulation can be decoded with omniORB.cdrUnmarshal() (but only if you know the type to decode it to).

When sending service contexts (ClientSendRequest, ServerSendReply, and ServerSendException), the second argument is an empty list. The interceptor function can choose to add one or more service context tuples, with the same form described above, by appending to the list. Encapsulations are created with omniORB.cdrMarshal().

Interceptor registration functions may only be called before the ORB is initialised. Attempting to call them later results in a BAD_INV_ORDER exception.

9.2  Thread interceptors

Thread interceptors are registered using functions in the omniORB.interceptors module:

addAssignUpcallThread addAssignAMIThread

To register thread interceptors, call the relevant registration function with a callable argument. The callable can be a simple function that returns None, or a generator that yields once. When a thread is assigned to perform server upcalls or AMI calls, the corresponding function is called. If it is a simple function, the function is called when the thread is assigned. If it is a generator, it is called when the thread is assigned, yields to permit the thread to execute, and then resumes when the thread is unassigned. For example:

def upcallInterceptor(): print("This thread is about to be used to call into server code") yield print("The thread has finished") omniORB.interceptors.addAssignUpcallThread(upcallInterceptor)

Previous Up Next