00001
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.i"
00010 #endif
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 ACE_ENV_ARG_DECL)
00051 {
00052 ACE_GUARD (Busy_Lock, ace_mon, this->lock_);
00053
00054 worker->set_size(this->collection_.size());
00055 ITERATOR end = this->collection_.end ();
00056 for (ITERATOR i = this->collection_.begin (); i != end; ++i)
00057 {
00058 worker->work (*i ACE_ENV_ARG_PARAMETER);
00059 ACE_CHECK;
00060
00061 }
00062 }
00063
00064 template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL> int
00065 TAO_ESF_Delayed_Changes<PROXY,COLLECTION,ITERATOR,ACE_SYNCH_USE>::
00066 busy (void)
00067 {
00068 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX_T, ace_mon, this->busy_lock_, -1);
00069
00070 while (this->busy_count_ >= this->busy_hwm_
00071 || this->write_delay_count_ >= this->max_write_delay_)
00072 this->busy_cond_.wait ();
00073 this->busy_count_++;
00074
00075 return 0;
00076 }
00077
00078 template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL> int
00079 TAO_ESF_Delayed_Changes<PROXY,COLLECTION,ITERATOR,ACE_SYNCH_USE>::
00080 idle (void)
00081 {
00082 ACE_GUARD_RETURN (ACE_SYNCH_MUTEX_T, ace_mon, this->busy_lock_, -1);
00083
00084 this->busy_count_--;
00085 if (this->busy_count_ == 0)
00086 {
00087 this->write_delay_count_ = 0;
00088 this->execute_delayed_operations ();
00089 this->busy_cond_.broadcast ();
00090 }
00091 return 0;
00092 }
00093
00094 template<class PROXY, class COLLECTION, class ITERATOR, ACE_SYNCH_DECL> int
00095 TAO_ESF_Delayed_Changes<PROXY,COLLECTION,ITERATOR,ACE_SYNCH_USE>::
00096 execute_delayed_operations (void)
00097 {
00098 while (!this->command_queue_.is_empty ())
00099 {
00100 ACE_Command_Base* command = 0;
00101 this->command_queue_.dequeue_head (command);
00102
00103 command->execute ();
00104
00105 delete command;
00106 }
00107 return 0;
00108 }
00109
00110 template<class PROXY, class C, class I,ACE_SYNCH_DECL> void
00111 TAO_ESF_Delayed_Changes<PROXY,C,I,ACE_SYNCH_USE>::
00112 connected (PROXY *proxy
00113 ACE_ENV_ARG_DECL)
00114 {
00115 ACE_GUARD_THROW_EX (ACE_SYNCH_MUTEX_T, ace_mon, this->busy_lock_,
00116 CORBA::INTERNAL ());
00117 ACE_CHECK;
00118
00119 proxy->_incr_refcnt ();
00120 if (this->busy_count_ == 0)
00121 {
00122
00123 this->connected_i (proxy ACE_ENV_ARG_PARAMETER);
00124 ACE_CHECK;
00125 }
00126 else
00127 {
00128 ACE_Command_Base* command = 0;
00129 ACE_NEW (command,
00130 Connected_Command (this,
00131 proxy));
00132 this->command_queue_.enqueue_tail (command);
00133 this->write_delay_count_++;
00134 }
00135 }
00136
00137 template<class PROXY, class C, class I,ACE_SYNCH_DECL> void
00138 TAO_ESF_Delayed_Changes<PROXY,C,I,ACE_SYNCH_USE>::
00139 reconnected (PROXY *proxy
00140 ACE_ENV_ARG_DECL)
00141 {
00142 ACE_GUARD_THROW_EX (ACE_SYNCH_MUTEX_T, ace_mon, this->busy_lock_,
00143 CORBA::INTERNAL ());
00144 ACE_CHECK;
00145
00146 proxy->_incr_refcnt ();
00147 if (this->busy_count_ == 0)
00148 {
00149
00150 this->reconnected_i (proxy ACE_ENV_ARG_PARAMETER);
00151 ACE_CHECK;
00152 }
00153 else
00154 {
00155 ACE_Command_Base* command;
00156 ACE_NEW (command,
00157 Reconnected_Command (this,
00158 proxy));
00159 this->command_queue_.enqueue_tail (command);
00160 this->write_delay_count_++;
00161 }
00162 }
00163
00164 template<class PROXY, class C, class I,ACE_SYNCH_DECL> void
00165 TAO_ESF_Delayed_Changes<PROXY,C,I,ACE_SYNCH_USE>::
00166 disconnected (PROXY *proxy
00167 ACE_ENV_ARG_DECL)
00168 {
00169 ACE_GUARD_THROW_EX (ACE_SYNCH_MUTEX_T, ace_mon, this->busy_lock_,
00170 CORBA::INTERNAL ());
00171 ACE_CHECK;
00172
00173 if (this->busy_count_ == 0)
00174 {
00175
00176 this->disconnected_i (proxy ACE_ENV_ARG_PARAMETER);
00177 ACE_CHECK;
00178 }
00179 else
00180 {
00181 ACE_Command_Base* command;
00182 ACE_NEW (command,
00183 Disconnected_Command (this,
00184 proxy));
00185 this->command_queue_.enqueue_tail (command);
00186 this->write_delay_count_++;
00187 }
00188 }
00189
00190 template<class PROXY, class C, class I,ACE_SYNCH_DECL> void
00191 TAO_ESF_Delayed_Changes<PROXY,C,I,ACE_SYNCH_USE>::
00192 shutdown (ACE_ENV_SINGLE_ARG_DECL)
00193 {
00194 ACE_GUARD_THROW_EX (ACE_SYNCH_MUTEX_T, ace_mon, this->busy_lock_,
00195 CORBA::INTERNAL ());
00196 ACE_CHECK;
00197
00198 if (this->busy_count_ == 0)
00199 {
00200
00201 this->shutdown_i (ACE_ENV_SINGLE_ARG_PARAMETER);
00202 ACE_CHECK;
00203 }
00204 else
00205 {
00206 ACE_Command_Base* command;
00207 ACE_NEW (command,
00208 Shutdown_Command (this));
00209 this->command_queue_.enqueue_tail (command);
00210 this->write_delay_count_++;
00211 }
00212 }
00213
00214 TAO_END_VERSIONED_NAMESPACE_DECL
00215
00216 #endif