Previous Table of Contents Next


7.4 Polling

   There are two types of Polling model invocations that allow a client to proceed before the request finishes: The DII’s send (which supports deferred synchronous invocations) and the typed sendp variants of the interface stubs (which support both deferred synchronous and asynchronous invocations). This section describes a single mechanism that allows a client to query or block on the completion of outstanding requests.

   The mechanism for generalized polling on multiple types of occurrences uses the CORBA::PollableSet interface.

   module CORBA {

   local interface PollableSet;

   abstract valuetype Pollable {boolean is_ready(in unsigned long timeout);

   PollableSet create_pollable_set( );};

   abstract valuetype DIIPollable : Pollable { };

   local interface PollableSet {

   exception NoPossiblePollable { };exception UnknownPollable { };

   DIIPollable create_dii_pollable();

   void add_pollable(in Pollable potential );

   Pollable get_ready_pollable(in unsigned long timeout) raises( NoPossiblePollable );

   void remove(in Pollable potential ) raises( UnknownPollable );

   unsigned short number_left( );

   };};

   7.4.1 Abstract Valuetype Pollable

   A Pollable supports queries to see if it is ready to be used, and can be registered with a pollable set to allow a single client thread to block on multiple potential happenings at the same time.

   7.4.1.1 is_ready

   boolean is_ready(in unsigned long timeout);

   Returns the value TRUE if and only if the specific happening represented by the pollable is ready to be consumed. Returns the value FALSE if the pollable is not yet ready to be consumed. If the timeout argument is the maximum value for unsigned long, the operation will block until it can return the value TRUE indicating that its happening is ready to be consumed. If the timeout argument is the value 0, the operation returns immediately.

   7.4.1.2 create_pollable_set

   PollableSet create_pollable_set( );

   Once there is a Pollable, it is possible to create a set of such pollables, which can be queried or upon which a client can block. The create_pollable_set operation creates a PollableSet object reference for an object with an empty set of pollable entities.

   7.4.2 Abstract Valuetype DIIPollable

   The specific Pollable that indicates interest in DII requests. A DIIPollable can be used in conjunction with a pollable set to allow a client to block or poll for the completion of DII requests, similar to the use of CORBA::ORB::get_next_response. When the DIIPollable is returned from PollableSet::poll, the reply to some DII request must be ready for processing.

   7.4.3 interface PollableSet

   The pollable set contains potential happenings for which a poll can be performed. The client adds potential happenings to the set and later queries the set to see if any have occurred. PollableSet is a locality constrained object.

   Note – There is a factory for PollableSet on the generic Pollable interface. Some implementation of this interface, such as a type-specific poller value, must first be accessible before a client can create a PollableSet.

   7.4.3.1 create_dii_pollable

   DIIPollable create_dii_pollable();

   Returns an instance of DIIPollable that can subsequently be registered to indicate interest in replies to DII requests.

   7.4.3.2 add_pollable

   void add_pollable(in Pollable potential );

   The add_pollable operation adds a potential happening to the PollableSet. The supplied Pollable parameter is some implementation that can be polled for readiness. To register interest in DII requests, an instance of DIIPollable is added to the pollable set.

   7.4.3.3 get_ready_pollable

   Pollable get_ready_pollable(in unsigned long timeout) raises( NoPossiblePollable );

   The get_ready_pollable operation asks the PollableSet if any of its potential happenings have occurred. The timeout parameter indicates how many milliseconds this call should wait until the response becomes available. If this timeout expires before a reply is available, the operation raises the standard system exception TIMEOUT. Any delegated invocations used by the implementation of this polling operation are subject to the single timeout parameter, which supersedes any ORB or thread-level timeout quality of service. Two specific values are of interest:

   If the PollableSet contains no potential happenings, the NoPossiblePollable exception is raised. If an actual happening is returned, the PollableSet removes that happening from the set. For the typed Poller, removing the happening is necessary since its usefulness ends once the Poller completes. In the case of a DII happening, there may still be deferred requests outstanding; if this is the case, the client application must add the DIIPollable again to the PollableSet.

   When the get_ready_pollable operation blocks, the ORB has control of the thread and can process any work it has (such as receiving and dispatching requests through its Object Adapter). The get_ready_pollable operation can be used in an “event-style main loop? using ORB::work_pending and ORB::perform_work.

   If the ORB supports multiple threads, one thread may be blocking on a PollableSet while another is adding and removing potential happenings from the set. It is valid for the PollableSet to change dynamically while a poll is in progress. If another thread’s PollableSet::remove operation leaves the PollableSet empty, any blocked threads raise the NoPossiblePollable exception.

   7.4.3.4 remove

   void remove( in Pollable potential ) raises( UnknownPollable );

   The remove operation deletes the potential happening identified by the potential parameter from the PollableSet. If it was not a member of the set, the UnknownPollable exception is raised.

   7.4.3.5 number_left

   unsigned short number_left( );

   The number_left operation returns the number of potential happenings in the pollable set. A returned value of zero means that there are no potential happenings in the set, in which case a query on the set would raise the NoPossibleHappening exception.