ESF_Delayed_Changes.cpp

Go to the documentation of this file.
00001 // $Id: ESF_Delayed_Changes.cpp 80179 2007-12-03 19:07:10Z sowayaa $
00002 
00003 #ifndef TAO_ESF_DELAYED_CHANGES_CPP
00004 #define TAO_ESF_DELAYED_CHANGES_CPP
00005 
00006 #include "orbsvcs/ESF/ESF_Delayed_Changes.h"
00007 
00008 #if ! defined (__ACE_INLINE__)
00009 #include "orbsvcs/ESF/ESF_Delayed_Changes.inl"
00010 #endif /* __ACE_INLINE__ */
00011 
00012 #include "orbsvcs/ESF/ESF_Defaults.h"
00013 #include "orbsvcs/ESF/ESF_Worker.h"
00014 #include "orbsvcs/ESF/ESF_Delayed_Command.h"
00015 
00016 #include "ace/Functor.h"
00017 
00018 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00019 
00020 // ****************************************************************
00021 
00022 template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL>
00023 TAO_ESF_Delayed_Changes<PROXY,COLLECTION,ITERATOR,ACE_SYNCH_USE>::
00024     TAO_ESF_Delayed_Changes (void)
00025       :  lock_ (this),
00026          busy_cond_ (busy_lock_),
00027          busy_count_ (0),
00028          write_delay_count_ (0),
00029          busy_hwm_ (TAO_ESF_DEFAULT_BUSY_HWM),
00030          max_write_delay_ (TAO_ESF_DEFAULT_MAX_WRITE_DELAY)
00031 {
00032 }
00033 
00034 template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL>
00035 TAO_ESF_Delayed_Changes<PROXY,COLLECTION,ITERATOR,ACE_SYNCH_USE>::
00036     TAO_ESF_Delayed_Changes (const COLLECTION &collection)
00037       :  collection_ (collection),
00038          lock_ (this),
00039          busy_cond_ (busy_lock_),
00040          busy_count_ (0),
00041          write_delay_count_ (0),
00042          busy_hwm_ (TAO_ESF_DEFAULT_BUSY_HWM),
00043          max_write_delay_ (TAO_ESF_DEFAULT_MAX_WRITE_DELAY)
00044 {
00045 }
00046 
00047 template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL> void
00048 TAO_ESF_Delayed_Changes<PROXY,COLLECTION,ITERATOR,ACE_SYNCH_USE>::
00049     for_each (TAO_ESF_Worker<PROXY> *worker)
00050 {
00051   ACE_GUARD (Busy_Lock, ace_mon, this->lock_);
00052 
00053   worker->set_size(this->collection_.size());
00054   ITERATOR end = this->collection_.end ();
00055   for (ITERATOR i = this->collection_.begin (); i != end; ++i)
00056     {
00057       worker->work (*i);
00058 
00059   }
00060 }
00061 
00062 template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL> int
00063 TAO_ESF_Delayed_Changes<PROXY,COLLECTION,ITERATOR,ACE_SYNCH_USE>::
00064     busy (void)
00065 {
00066   ACE_GUARD_RETURN (ACE_SYNCH_MUTEX_T, ace_mon, this->busy_lock_, -1);
00067 
00068   while (this->busy_count_ >= this->busy_hwm_
00069          || this->write_delay_count_ >= this->max_write_delay_)
00070     this->busy_cond_.wait ();
00071   ++this->busy_count_;
00072 
00073   return 0;
00074 }
00075 
00076 template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL> int
00077 TAO_ESF_Delayed_Changes<PROXY,COLLECTION,ITERATOR,ACE_SYNCH_USE>::
00078     idle (void)
00079 {
00080   ACE_GUARD_RETURN (ACE_SYNCH_MUTEX_T, ace_mon, this->busy_lock_, -1);
00081 
00082   --this->busy_count_;
00083   if (this->busy_count_ == 0)
00084     {
00085       this->write_delay_count_ = 0;
00086       this->execute_delayed_operations ();
00087       this->busy_cond_.broadcast ();
00088     }
00089   return 0;
00090 }
00091 
00092 template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL> int
00093 TAO_ESF_Delayed_Changes<PROXY,COLLECTION,ITERATOR,ACE_SYNCH_USE>::
00094     execute_delayed_operations (void)
00095 {
00096   while (!this->command_queue_.is_empty ())
00097     {
00098       ACE_Command_Base* command = 0;
00099       this->command_queue_.dequeue_head (command);
00100 
00101       command->execute ();
00102 
00103       delete command;
00104     }
00105   return 0;
00106 }
00107 
00108 template<class PROXY, class C, class I,ACE_SYNCH_DECL> void
00109 TAO_ESF_Delayed_Changes<PROXY,C,I,ACE_SYNCH_USE>::
00110     connected (PROXY *proxy)
00111 {
00112   ACE_GUARD_THROW_EX (ACE_SYNCH_MUTEX_T, ace_mon, this->busy_lock_,
00113       CORBA::INTERNAL ());
00114 
00115   proxy->_incr_refcnt ();
00116   if (this->busy_count_ == 0)
00117     {
00118       // We can add the object immediately
00119       this->connected_i (proxy);
00120     }
00121   else
00122     {
00123       ACE_Command_Base* command = 0;
00124       ACE_NEW (command,
00125                Connected_Command (this,
00126                                   proxy));
00127       this->command_queue_.enqueue_tail (command);
00128       this->write_delay_count_++;
00129     }
00130 }
00131 
00132 template<class PROXY, class C, class I,ACE_SYNCH_DECL> void
00133 TAO_ESF_Delayed_Changes<PROXY,C,I,ACE_SYNCH_USE>::
00134     reconnected (PROXY *proxy)
00135 {
00136   ACE_GUARD_THROW_EX (ACE_SYNCH_MUTEX_T, ace_mon, this->busy_lock_,
00137       CORBA::INTERNAL ());
00138 
00139   proxy->_incr_refcnt ();
00140   if (this->busy_count_ == 0)
00141     {
00142       // We can reconnect the object immediately
00143       this->reconnected_i (proxy);
00144     }
00145   else
00146     {
00147       ACE_Command_Base* command;
00148       ACE_NEW (command,
00149                Reconnected_Command (this,
00150                                     proxy));
00151       this->command_queue_.enqueue_tail (command);
00152       this->write_delay_count_++;
00153     }
00154 }
00155 
00156 template<class PROXY, class C, class I,ACE_SYNCH_DECL> void
00157 TAO_ESF_Delayed_Changes<PROXY,C,I,ACE_SYNCH_USE>::
00158     disconnected (PROXY *proxy)
00159 {
00160   ACE_GUARD_THROW_EX (ACE_SYNCH_MUTEX_T, ace_mon, this->busy_lock_,
00161       CORBA::INTERNAL ());
00162 
00163   if (this->busy_count_ == 0)
00164     {
00165       // We can remove the object immediately
00166       this->disconnected_i (proxy);
00167     }
00168   else
00169     {
00170       ACE_Command_Base* command;
00171       ACE_NEW (command,
00172                Disconnected_Command (this,
00173                                      proxy));
00174       this->command_queue_.enqueue_tail (command);
00175       this->write_delay_count_++;
00176     }
00177 }
00178 
00179 template<class PROXY, class C, class I,ACE_SYNCH_DECL> void
00180 TAO_ESF_Delayed_Changes<PROXY,C,I,ACE_SYNCH_USE>::shutdown (void)
00181 {
00182   ACE_GUARD_THROW_EX (ACE_SYNCH_MUTEX_T, ace_mon, this->busy_lock_,
00183       CORBA::INTERNAL ());
00184 
00185   if (this->busy_count_ == 0)
00186     {
00187       // We can shutdown the object immediately
00188       this->shutdown_i ();
00189     }
00190   else
00191     {
00192       ACE_Command_Base* command;
00193       ACE_NEW (command,
00194                Shutdown_Command (this));
00195       this->command_queue_.enqueue_tail (command);
00196       this->write_delay_count_++;
00197     }
00198 }
00199 
00200 TAO_END_VERSIONED_NAMESPACE_DECL
00201 
00202 #endif /* TAO_ESF_DELAYED_CHANGES_CPP */

Generated on Tue Feb 2 17:43:47 2010 for TAO_ESF by  doxygen 1.4.7