TAO_CEC_ProxyPullConsumer Class Reference

ProxyPullConsumer. More...

#include <CEC_ProxyPullConsumer.h>

Collaboration diagram for TAO_CEC_ProxyPullConsumer:

Collaboration graph
[legend]
List of all members.

Public Types

typedef CosEventChannelAdmin::ProxyPullConsumer_ptr _ptr_type
typedef CosEventChannelAdmin::ProxyPullConsumer_var _var_type

Public Member Functions

 TAO_CEC_ProxyPullConsumer (TAO_CEC_EventChannel *event_channel, const ACE_Time_Value &timeout)
 constructor...
virtual ~TAO_CEC_ProxyPullConsumer (void)
 destructor...
virtual void activate (CosEventChannelAdmin::ProxyPullConsumer_ptr &activated_proxy)
 Activate in the POA.
virtual void deactivate (void)
 Deactivate from the POA.
CORBA::Boolean is_connected (void) const
 Return 0 if no supplier is connected...
CosEventComm::PullSupplier_ptr supplier (void) const
CORBA::Any * try_pull_from_supplier (CORBA::Boolean_out has_event)
 Pulls from the supplier, verifies that it is connected.
CORBA::Any * pull_from_supplier (void)
CORBA::Boolean supplier_non_existent (CORBA::Boolean_out disconnected)
virtual void shutdown (void)
 The event channel is shutting down.
CORBA::ULong _incr_refcnt (void)
 Increment and decrement the reference count.
CORBA::ULong _decr_refcnt (void)
virtual void connect_pull_supplier (CosEventComm::PullSupplier_ptr pull_supplier)
virtual void disconnect_pull_consumer (void)
virtual PortableServer::POA_ptr _default_POA (void)
virtual void _add_ref (void)
virtual void _remove_ref (void)

Protected Member Functions

void supplier (CosEventComm::PullSupplier_ptr supplier)
void supplier_i (CosEventComm::PullSupplier_ptr supplier)
CORBA::Boolean is_connected_i (void) const
 The private version (without locking) of is_connected().
void cleanup_i (void)
 Release the supplier.
CosEventComm::PullSupplier_ptr apply_policy (CosEventComm::PullSupplier_ptr s)

Private Attributes

TAO_CEC_EventChannelevent_channel_
 The supplier admin, used for activation and memory managment.
ACE_Time_Value timeout_
ACE_Locklock_
 The locking strategy.
CORBA::ULong refcount_
 The reference count.
CosEventComm::PullSupplier_var supplier_
CosEventComm::PullSupplier_var nopolicy_supplier_
 The supplier without any policies applied.
PortableServer::POA_var default_POA_
 Store the default POA.

Detailed Description

ProxyPullConsumer.

Implement the CosEventChannelAdmin::ProxyPullConsumer interface, remember that this class is used to communicate with a PullSupplier, so, in effect, this is the ambassador for a supplier inside the event channel. = MEMORY MANAGMENT The object commits suicide when disconnect_pull_consumer() is called.

Definition at line 46 of file CEC_ProxyPullConsumer.h.


Member Typedef Documentation

typedef CosEventChannelAdmin::ProxyPullConsumer_ptr TAO_CEC_ProxyPullConsumer::_ptr_type

Definition at line 49 of file CEC_ProxyPullConsumer.h.

typedef CosEventChannelAdmin::ProxyPullConsumer_var TAO_CEC_ProxyPullConsumer::_var_type

Definition at line 50 of file CEC_ProxyPullConsumer.h.


Constructor & Destructor Documentation

TAO_CEC_ProxyPullConsumer::TAO_CEC_ProxyPullConsumer ( TAO_CEC_EventChannel event_channel,
const ACE_Time_Value timeout 
)

constructor...

Definition at line 24 of file CEC_ProxyPullConsumer.cpp.

00026   : event_channel_ (ec),
00027     timeout_ (timeout),
00028     refcount_ (1)
00029 {
00030   this->lock_ =
00031     this->event_channel_->create_consumer_lock ();
00032 
00033   this->default_POA_ =
00034     this->event_channel_->consumer_poa ();
00035 
00036   this->event_channel_->get_servant_retry_map ().bind (this, 0);
00037 }

TAO_CEC_ProxyPullConsumer::~TAO_CEC_ProxyPullConsumer ( void   )  [virtual]

destructor...

Definition at line 39 of file CEC_ProxyPullConsumer.cpp.

References TAO_CEC_EventChannel::destroy_consumer_lock(), event_channel_, and TAO_CEC_EventChannel::get_servant_retry_map().

00040 {
00041   this->event_channel_->get_servant_retry_map ().unbind (this);
00042   this->event_channel_->destroy_consumer_lock (this->lock_);
00043 }


Member Function Documentation

void TAO_CEC_ProxyPullConsumer::_add_ref ( void   )  [virtual]

Definition at line 373 of file CEC_ProxyPullConsumer.cpp.

References _incr_refcnt().

00374 {
00375   this->_incr_refcnt ();
00376 }

CORBA::ULong TAO_CEC_ProxyPullConsumer::_decr_refcnt ( void   ) 

Definition at line 242 of file CEC_ProxyPullConsumer.cpp.

References ACE_GUARD_RETURN, TAO_CEC_EventChannel::destroy_proxy(), event_channel_, and refcount_.

Referenced by _remove_ref().

00243 {
00244   {
00245     ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->lock_, 0);
00246     this->refcount_--;
00247     if (this->refcount_ != 0)
00248       return this->refcount_;
00249   }
00250 
00251   // Notify the event channel
00252   this->event_channel_->destroy_proxy (this);
00253   return 0;
00254 }

PortableServer::POA_ptr TAO_CEC_ProxyPullConsumer::_default_POA ( void   )  [virtual]

Definition at line 367 of file CEC_ProxyPullConsumer.cpp.

Referenced by deactivate().

00368 {
00369   return PortableServer::POA::_duplicate (this->default_POA_.in ());
00370 }

CORBA::ULong TAO_CEC_ProxyPullConsumer::_incr_refcnt ( void   ) 

Increment and decrement the reference count.

Definition at line 235 of file CEC_ProxyPullConsumer.cpp.

References ACE_GUARD_RETURN, and refcount_.

Referenced by _add_ref().

00236 {
00237   ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->lock_, 0);
00238   return this->refcount_++;
00239 }

void TAO_CEC_ProxyPullConsumer::_remove_ref ( void   )  [virtual]

Definition at line 379 of file CEC_ProxyPullConsumer.cpp.

References _decr_refcnt().

00380 {
00381   this->_decr_refcnt ();
00382 }

void TAO_CEC_ProxyPullConsumer::activate ( CosEventChannelAdmin::ProxyPullConsumer_ptr &  activated_proxy  )  [virtual]

Activate in the POA.

Definition at line 46 of file CEC_ProxyPullConsumer.cpp.

00048 {
00049   CosEventChannelAdmin::ProxyPullConsumer_var result;
00050   try
00051     {
00052       result = this->_this ();
00053     }
00054   catch (const CORBA::Exception&)
00055     {
00056       result = CosEventChannelAdmin::ProxyPullConsumer::_nil ();
00057     }
00058   activated_proxy = result._retn ();
00059 }

CosEventComm::PullSupplier_ptr TAO_CEC_ProxyPullConsumer::apply_policy ( CosEventComm::PullSupplier_ptr  s  )  [protected]

Assigns the parameter to both supplier_ and nopolicy_supplier_, and applies policies (when appropriate) to supplier_.

Definition at line 304 of file CEC_ProxyPullConsumer.cpp.

References event_channel_, TAO_Pseudo_Var_T< T >::in(), nopolicy_supplier_, and ACE_Time_Value::zero.

Referenced by connect_pull_supplier().

00305 {
00306   this->nopolicy_supplier_ = CosEventComm::PullSupplier::_duplicate (pre);
00307 #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0
00308   CosEventComm::PullSupplier_var post =
00309     CosEventComm::PullSupplier::_duplicate (pre);
00310   if (this->timeout_ > ACE_Time_Value::zero)
00311     {
00312       CORBA::PolicyList policy_list;
00313       policy_list.length (1);
00314       policy_list[0] = this->event_channel_->
00315         create_roundtrip_timeout_policy (this->timeout_);
00316 
00317       CORBA::Object_var post_obj = pre->_set_policy_overrides
00318         (policy_list, CORBA::ADD_OVERRIDE);
00319       post = CosEventComm::PullSupplier::_narrow (post_obj.in ());
00320 
00321       policy_list[0]->destroy ();
00322       policy_list.length (0);
00323     }
00324   return post._retn ();
00325 #else
00326   return CosEventComm::PullSupplier::_duplicate (pre);
00327 #endif /* TAO_HAS_CORBA_MESSAGING */
00328 }

void TAO_CEC_ProxyPullConsumer::cleanup_i ( void   )  [protected]

Release the supplier.

Definition at line 228 of file CEC_ProxyPullConsumer.cpp.

References supplier_.

Referenced by connect_pull_supplier(), and disconnect_pull_consumer().

00229 {
00230   this->supplier_ =
00231     CosEventComm::PullSupplier::_nil ();
00232 }

void TAO_CEC_ProxyPullConsumer::connect_pull_supplier ( CosEventComm::PullSupplier_ptr  pull_supplier  )  [virtual]

Definition at line 257 of file CEC_ProxyPullConsumer.cpp.

References ACE_GUARD_THROW_EX, apply_policy(), cleanup_i(), TAO_CEC_EventChannel::connected(), TAO_CEC_EventChannel::disconnected(), event_channel_, CORBA::is_nil(), supplier_, and TAO_CEC_Unlock.

00259 {
00260   // Nil PullSuppliers are illegal
00261   if (CORBA::is_nil (pull_supplier))
00262     throw CORBA::BAD_PARAM ();
00263 
00264   {
00265     ACE_GUARD_THROW_EX (
00266         ACE_Lock, ace_mon, *this->lock_,
00267         CORBA::INTERNAL ());
00268     // @@ CosEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR ());
00269 
00270     if (this->is_connected_i ())
00271       {
00272         if (this->event_channel_->supplier_reconnect () == 0)
00273           throw CosEventChannelAdmin::AlreadyConnected ();
00274 
00275         // Re-connections are allowed, go ahead and disconnect the
00276         // consumer...
00277         this->cleanup_i ();
00278 
00279         // @@ Please read the comments in CEC_ProxyPullSupplier about
00280         //     possible race conditions in this area...
00281         TAO_CEC_Unlock reverse_lock (*this->lock_);
00282 
00283         {
00284           ACE_GUARD_THROW_EX (
00285               TAO_CEC_Unlock, ace_mon, reverse_lock,
00286               CORBA::INTERNAL ());
00287           // @@ CosEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR ());
00288 
00289           this->event_channel_->disconnected (this);
00290         }
00291 
00292         // What if a second thread connected us after this?
00293         if (this->is_connected_i ())
00294           return;
00295       }
00296     this->supplier_ = apply_policy (pull_supplier);
00297   }
00298 
00299   // Notify the event channel...
00300   this->event_channel_->connected (this);
00301 }

void TAO_CEC_ProxyPullConsumer::deactivate ( void   )  [virtual]

Deactivate from the POA.

Definition at line 62 of file CEC_ProxyPullConsumer.cpp.

References _default_POA().

Referenced by shutdown().

00063 {
00064   try
00065     {
00066       PortableServer::POA_var poa =
00067         this->_default_POA ();
00068       PortableServer::ObjectId_var id =
00069         poa->servant_to_id (this);
00070       poa->deactivate_object (id.in ());
00071     }
00072   catch (const CORBA::Exception&)
00073     {
00074       // Exceptions here should not be propagated.  They usually
00075       // indicate that an object is beign disconnected twice, or some
00076       // race condition, but not a fault that the user needs to know
00077       // about.
00078     }
00079 }

void TAO_CEC_ProxyPullConsumer::disconnect_pull_consumer ( void   )  [virtual]

Definition at line 331 of file CEC_ProxyPullConsumer.cpp.

References ACE_GUARD_THROW_EX, cleanup_i(), TAO_CEC_EventChannel::disconnected(), event_channel_, supplier(), and supplier_.

Referenced by TAO_CEC_Reactive_SupplierControl::supplier_not_exist(), and TAO_CEC_Reactive_SupplierControl::system_exception().

00332 {
00333   CosEventComm::PullSupplier_var supplier;
00334 
00335   {
00336     ACE_GUARD_THROW_EX (
00337         ACE_Lock, ace_mon, *this->lock_,
00338         CORBA::INTERNAL ());
00339     // @@ CosEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR ());
00340 
00341     if (this->is_connected_i () == 0)
00342       throw CORBA::BAD_INV_ORDER (); // @@ add user exception?
00343 
00344     supplier = this->supplier_._retn ();
00345 
00346     this->cleanup_i ();
00347   }
00348 
00349   // Notify the event channel...
00350   this->event_channel_->disconnected (this);
00351 
00352   if (this->event_channel_->disconnect_callbacks ())
00353     {
00354       try
00355         {
00356           supplier->disconnect_pull_supplier ();
00357         }
00358       catch (const CORBA::Exception&)
00359         {
00360           // Ignore exceptions, we must isolate other clients from
00361           // failures on this one.
00362         }
00363     }
00364 }

ACE_INLINE CORBA::Boolean TAO_CEC_ProxyPullConsumer::is_connected ( void   )  const

Return 0 if no supplier is connected...

Definition at line 14 of file CEC_ProxyPullConsumer.inl.

References ACE_GUARD_RETURN, and is_connected_i().

00015 {
00016   ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->lock_, 0);
00017 
00018   return this->is_connected_i ();
00019 }

TAO_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE CORBA::Boolean TAO_CEC_ProxyPullConsumer::is_connected_i ( void   )  const [protected]

The private version (without locking) of is_connected().

Definition at line 8 of file CEC_ProxyPullConsumer.inl.

References CORBA::is_nil().

Referenced by is_connected().

00009 {
00010   return !CORBA::is_nil (this->supplier_.in ());
00011 }

CORBA::Any * TAO_CEC_ProxyPullConsumer::pull_from_supplier ( void   ) 

Definition at line 135 of file CEC_ProxyPullConsumer.cpp.

References ACE_GUARD_THROW_EX, and supplier().

00136 {
00137   CosEventComm::PullSupplier_var supplier;
00138   {
00139     ACE_GUARD_THROW_EX (
00140             ACE_Lock, ace_mon, *this->lock_,
00141             CORBA::INTERNAL ());
00142     // @@ CosEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR ());
00143 
00144     if (this->is_connected_i () == 0)
00145       return 0; // ACE_THROW (CosEventComm::Disconnected ());????
00146 
00147     supplier =
00148       CosEventComm::PullSupplier::_duplicate (this->supplier_.in ());
00149 
00150     // The refcount cannot be zero, because we have at least two
00151     // references,
00152   }
00153 
00154   CORBA::Any_var any;
00155   try
00156     {
00157       any = supplier->pull ();
00158     }
00159   catch (const CORBA::Exception&)
00160     {
00161       // @@ This is where the policies for misbehaving suppliers
00162       //    should kick in.... for the moment just ignore them.
00163     }
00164   return any._retn ();
00165 }

void TAO_CEC_ProxyPullConsumer::shutdown ( void   )  [virtual]

The event channel is shutting down.

Definition at line 198 of file CEC_ProxyPullConsumer.cpp.

References ACE_GUARD_THROW_EX, deactivate(), CORBA::is_nil(), supplier(), and supplier_.

00199 {
00200   CosEventComm::PullSupplier_var supplier;
00201 
00202   {
00203     ACE_GUARD_THROW_EX (
00204         ACE_Lock, ace_mon, *this->lock_,
00205         CORBA::INTERNAL ());
00206     // @@ CosEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR ());
00207 
00208     supplier = this->supplier_._retn ();
00209   }
00210 
00211   this->deactivate ();
00212 
00213   if (CORBA::is_nil (supplier.in ()))
00214     return;
00215 
00216   try
00217     {
00218       supplier->disconnect_pull_supplier ();
00219     }
00220   catch (const CORBA::Exception&)
00221     {
00222       // Ignore exceptions, we must isolate other clients from
00223       // failures on this one.
00224     }
00225 }

ACE_INLINE void TAO_CEC_ProxyPullConsumer::supplier ( CosEventComm::PullSupplier_ptr  supplier  )  [protected]

Set the supplier, used by some implementations to change the policies used when invoking operations on the supplier.

Definition at line 35 of file CEC_ProxyPullConsumer.inl.

References ACE_GUARD, and supplier_i().

00036 {
00037   ACE_GUARD (ACE_Lock, ace_mon, *this->lock_);
00038 
00039   this->supplier_i (supplier);
00040 }

ACE_INLINE CosEventComm::PullSupplier_ptr TAO_CEC_ProxyPullConsumer::supplier ( void   )  const

Return the consumer object reference. It returns nil() if it has not connected yet.

Definition at line 22 of file CEC_ProxyPullConsumer.inl.

References ACE_GUARD_RETURN.

Referenced by disconnect_pull_consumer(), pull_from_supplier(), shutdown(), supplier_non_existent(), and try_pull_from_supplier().

00023 {
00024   ACE_GUARD_RETURN (ACE_Lock, ace_mon, *this->lock_, 0);
00025   return CosEventComm::PullSupplier::_duplicate (this->supplier_.in ());
00026 }

ACE_INLINE void TAO_CEC_ProxyPullConsumer::supplier_i ( CosEventComm::PullSupplier_ptr  supplier  )  [protected]

Definition at line 29 of file CEC_ProxyPullConsumer.inl.

References supplier_.

Referenced by supplier().

00030 {
00031   this->supplier_ = supplier;
00032 }

CORBA::Boolean TAO_CEC_ProxyPullConsumer::supplier_non_existent ( CORBA::Boolean_out  disconnected  ) 

Invoke the _non_existent() pseudo-operation on the supplier. If it is disconnected then it returns true and sets the <disconnected> flag.

Definition at line 168 of file CEC_ProxyPullConsumer.cpp.

References CORBA::Object::_duplicate(), ACE_GUARD_THROW_EX, CORBA::is_nil(), and supplier().

Referenced by TAO_CEC_Ping_Pull_Supplier::work().

00170 {
00171   CORBA::Object_var supplier;
00172   {
00173     ACE_GUARD_THROW_EX (
00174         ACE_Lock, ace_mon, *this->lock_,
00175         CORBA::INTERNAL ());
00176 
00177     disconnected = 0;
00178     if (this->is_connected_i () == 0)
00179       {
00180         disconnected = 1;
00181         return 0;
00182       }
00183     if (CORBA::is_nil (this->nopolicy_supplier_.in ()))
00184       {
00185         return 0;
00186       }
00187     supplier = CORBA::Object::_duplicate (this->nopolicy_supplier_.in ());
00188   }
00189 
00190 #if (TAO_HAS_MINIMUM_CORBA == 0)
00191   return supplier->_non_existent ();
00192 #else
00193   return 0;
00194 #endif /* TAO_HAS_MINIMUM_CORBA */
00195 }

CORBA::Any * TAO_CEC_ProxyPullConsumer::try_pull_from_supplier ( CORBA::Boolean_out  has_event  ) 

Pulls from the supplier, verifies that it is connected.

Definition at line 87 of file CEC_ProxyPullConsumer.cpp.

References ACE_GUARD_THROW_EX, event_channel_, TAO_CEC_SupplierControl::successful_transmission(), supplier(), TAO_CEC_EventChannel::supplier_control(), TAO_CEC_SupplierControl::supplier_not_exist(), and TAO_CEC_SupplierControl::system_exception().

Referenced by TAO_CEC_Pull_Event::work().

00089 {
00090   has_event = 0;
00091   CosEventComm::PullSupplier_var supplier;
00092   {
00093     ACE_GUARD_THROW_EX (
00094             ACE_Lock, ace_mon, *this->lock_,
00095             CORBA::INTERNAL ());
00096     // @@ CosEventChannelAdmin::EventChannel::SYNCHRONIZATION_ERROR ());
00097 
00098     if (this->is_connected_i () == 0)
00099       return 0; // ACE_THROW (CosEventComm::Disconnected ());????
00100 
00101     supplier =
00102       CosEventComm::PullSupplier::_duplicate (this->supplier_.in ());
00103 
00104     // The refcount cannot be zero, because we have at least two
00105     // references,
00106   }
00107 
00108   CORBA::Any_var any;
00109   TAO_CEC_SupplierControl *control =
00110                  this->event_channel_->supplier_control ();
00111 
00112   try
00113     {
00114       any = supplier->try_pull (has_event);
00115 
00116       // Inform the control that we got something from the supplier
00117       control->successful_transmission(this);
00118     }
00119   catch (const CORBA::OBJECT_NOT_EXIST&)
00120     {
00121       control->supplier_not_exist (this);
00122     }
00123   catch (CORBA::SystemException& sysex)
00124     {
00125       control->system_exception (this, sysex);
00126     }
00127   catch (const CORBA::Exception&)
00128     {
00129       // @@ Should not happen
00130     }
00131   return any._retn ();
00132 }


Member Data Documentation

PortableServer::POA_var TAO_CEC_ProxyPullConsumer::default_POA_ [private]

Store the default POA.

Definition at line 138 of file CEC_ProxyPullConsumer.h.

TAO_CEC_EventChannel* TAO_CEC_ProxyPullConsumer::event_channel_ [private]

The supplier admin, used for activation and memory managment.

Definition at line 120 of file CEC_ProxyPullConsumer.h.

Referenced by _decr_refcnt(), apply_policy(), connect_pull_supplier(), disconnect_pull_consumer(), try_pull_from_supplier(), and ~TAO_CEC_ProxyPullConsumer().

ACE_Lock* TAO_CEC_ProxyPullConsumer::lock_ [private]

The locking strategy.

Definition at line 125 of file CEC_ProxyPullConsumer.h.

CosEventComm::PullSupplier_var TAO_CEC_ProxyPullConsumer::nopolicy_supplier_ [private]

The supplier without any policies applied.

Definition at line 135 of file CEC_ProxyPullConsumer.h.

Referenced by apply_policy().

CORBA::ULong TAO_CEC_ProxyPullConsumer::refcount_ [private]

The reference count.

Definition at line 128 of file CEC_ProxyPullConsumer.h.

Referenced by _decr_refcnt(), and _incr_refcnt().

CosEventComm::PullSupplier_var TAO_CEC_ProxyPullConsumer::supplier_ [private]

The supplier -- use apply_policy() instead of assigning directly to supplier_. This will keep supplier_ and nopolicy_supplier_ in sync.

Definition at line 132 of file CEC_ProxyPullConsumer.h.

Referenced by cleanup_i(), connect_pull_supplier(), disconnect_pull_consumer(), shutdown(), and supplier_i().

ACE_Time_Value TAO_CEC_ProxyPullConsumer::timeout_ [private]

Definition at line 122 of file CEC_ProxyPullConsumer.h.


The documentation for this class was generated from the following files:
Generated on Tue Feb 2 17:44:59 2010 for TAO_CosEvent by  doxygen 1.4.7