00001 00002 #include "Event_Handler.h" 00003 #include "Reactor.h" 00004 00017 class LookupService_Impl : 00018 public POA_LookupService, Event_Handler { 00019 public: 00020 LookupService_Impl () {}; 00021 ~LookupService_Impl () {}; 00022 00035 Lease_ptr bind (const CosNaming::Name &name, 00036 CORBA::Object_ptr object, 00037 TimeBase::TimeT duration, 00038 LeaseHolder_ptr lease_holder) 00039 throw (InvalidDuration) 00040 { 00041 if (this->duration_is_acceptable (duration)) 00042 { 00043 // Create a new lease 00044 Lease_Impl *lease_impl = 00045 new Lease_Impl (current_time () + duration, 00046 this->_this(), name, lease_holder); 00047 00048 // Get the CORBA object reference 00049 Lease_var lease = lease_impl->_this (); 00050 00051 reactor_->register_timer (duration, 00052 this, 00053 lease); 00054 00055 // Delegate binding to actual Naming Service 00056 name_service_->bind (name, object); 00057 00058 return lease; 00059 } 00060 else 00061 { 00062 // Reject the bind request 00063 throw InvalidDuration(); 00064 } 00065 } 00066 00072 void cancel_lease (Lease_ptr lease) 00073 { 00074 CosNaming::Name_var name = lease->get_name (); 00075 00076 // Delegate to the Naming Service 00077 name_service_->unbind (name); 00078 00079 // Cancel timer with the reactor 00080 reactor_->unregister_timer (this, lease); 00081 } 00082 00090 TimeBase::TimeT prolong_lease (Lease_ptr lease, 00091 TimeBase::TimeT duration) 00092 throw (InvalidDuration) 00093 { 00094 if (this->duration_is_acceptable (duration)) 00095 { 00096 // Reschedule the timer with the reactor for the 00097 // new duration of the lease 00098 reactor_->unregister_timer (this, lease); 00099 reactor_->register_timer (duration, 00100 this, 00101 lease); 00102 } 00103 else // Reject the bind request 00104 { 00105 throw InvalidDuration(); 00106 } 00107 } 00108 00109 00115 void on_timer_expire (Lease_ptr lease) 00116 { 00117 LeaseHolder_var lease_holder = 00118 lease->get_lease_holder (); 00119 00120 // Notify lease holder of lease expriation 00121 lease_holder->lease_expired (lease); 00122 00123 if (lease->get_remaining_time () <= 0) 00124 { 00125 // If the lease did not get renewed by the lease holder 00126 lease->expired (); 00127 CosNaming::Name_var name = lease->get_name (); 00128 name_service_->unbind (name); 00129 } 00130 } 00131 00132 private: 00133 bool duration_is_acceptable (TimeBase::TimeT time) 00134 { 00135 return TRUE; 00136 } 00137 00138 TimeBase::TimeT current_time () 00139 { 00140 } 00141 00142 CosNaming::NamingContext_ptr name_service_; 00143 Reactor *reactor_; 00144 };
These pages document the source code of the patterns Lookup, Eager Acquisition, and Leasing.
Copyright 2004 John Wiley and Sons. All Rights Reserved.