From c142882be155ea940e3dc9b18c532d2f59d6a6df Mon Sep 17 00:00:00 2001 From: coryan Date: Fri, 28 May 1999 21:52:16 +0000 Subject: ChangeLogTag:Fri May 28 16:50:46 1999 Carlos O'Ryan --- TAO/ChangeLog-99c | 11 ++++++ TAO/tao/Invocation.h | 8 ++-- TAO/tao/Reply_Dispatcher.cpp | 2 +- TAO/tao/Reply_Dispatcher.h | 30 +++++++------- TAO/tao/Request_Mux_Strategy.cpp | 2 +- TAO/tao/Request_Mux_Strategy.h | 59 ++++++++++++++-------------- TAO/tao/Wait_Strategy.cpp | 85 +++++++++++++++++++++++----------------- TAO/tao/Wait_Strategy.h | 72 ++++++++++++++++++++++------------ 8 files changed, 159 insertions(+), 110 deletions(-) diff --git a/TAO/ChangeLog-99c b/TAO/ChangeLog-99c index db1faebea8a..ee9b08667e6 100644 --- a/TAO/ChangeLog-99c +++ b/TAO/ChangeLog-99c @@ -1,3 +1,14 @@ +Fri May 28 16:50:46 1999 Carlos O'Ryan + + * tao/Invocation.h: + * tao/Reply_Dispatcher.h: + * tao/Reply_Dispatcher.cpp: + * tao/Request_Mux_Strategy.h: + * tao/Request_Mux_Strategy.cpp: + * tao/Wait_Strategy.h: + * tao/Wait_Strategy.cpp: + Minor fixes and several @@ comments. + Fri May 28 11:58:16 1999 Alexander Babu Arulanthu * tao/Wait_Strategy.cpp: diff --git a/TAO/tao/Invocation.h b/TAO/tao/Invocation.h index 18d4c3470b8..ca106f437c7 100644 --- a/TAO/tao/Invocation.h +++ b/TAO/tao/Invocation.h @@ -154,7 +154,7 @@ protected: CORBA::ULong request_id_; // Request ID of this operation. - + char buffer [ACE_CDR::DEFAULT_BUFSIZE]; // Buffer used for both the output and input CDR streams, this is // "safe" because we only one of the streams at a time. @@ -219,7 +219,7 @@ public: TAO_InputCDR &inp_stream (void); // return the underlying input stream - + private: int invoke_i (CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)); @@ -229,9 +229,9 @@ private: private: TAO_InputCDR inp_stream_; // Stream into which the reply is placed. - + TAO_Synch_Reply_Dispatcher rd_; - // Reply dispatcher for the current synchronous invocation. + // Reply dispatcher for the current synchronous invocation. }; class TAO_Export TAO_GIOP_Oneway_Invocation : public TAO_GIOP_Invocation diff --git a/TAO/tao/Reply_Dispatcher.cpp b/TAO/tao/Reply_Dispatcher.cpp index 952391b5bed..a6249ef9c36 100644 --- a/TAO/tao/Reply_Dispatcher.cpp +++ b/TAO/tao/Reply_Dispatcher.cpp @@ -69,6 +69,6 @@ TAO_Synch_Reply_Dispatcher::~TAO_Synch_Reply_Dispatcher (void) int TAO_Synch_Reply_Dispatcher::dispatch_reply (void) { - // @@ Handover the input CDR to the Invocation class. + // @@ Handover the input CDR to the Invocation class. return 0; } diff --git a/TAO/tao/Reply_Dispatcher.h b/TAO/tao/Reply_Dispatcher.h index 01d3c9b3138..cb616e7a8ad 100644 --- a/TAO/tao/Reply_Dispatcher.h +++ b/TAO/tao/Reply_Dispatcher.h @@ -9,7 +9,7 @@ // Reply_Dispatcher.h // // = DESCRIPTION -// Dispatch the reply appropriately. +// Dispatch the reply appropriately. // // = AUTHOR // Alexander Babu Arulanthu @@ -19,7 +19,7 @@ #ifndef TAO_REPLY_DISPATCHER_H #define TAO_REPLY_DISPATCHER_H -#include "tao/GIOP.h" +#include "tao/corbafwd.h" // Forward Declarations. @@ -32,25 +32,25 @@ class TAO_Export TAO_Reply_Dispatcher // // = DESCRIPTION // - + public: TAO_Reply_Dispatcher (void); // Constructor. - + virtual ~TAO_Reply_Dispatcher (void); // Destructor. - + void request_id (CORBA::ULong request_id); // Set the request id. - + CORBA::ULong request_id (void) const; // Return the request id. void reply_status (CORBA::ULong reply_status); // Set the reply status. Reply status is stored as read from the // incoming message. Readers of this data should see it whether this - // number fits into the TAO_GIOP_ReplyStatusType type. - + // number fits into the TAO_GIOP_ReplyStatusType type. + CORBA::ULong reply_status (void) const; // Get the reply status. @@ -59,17 +59,17 @@ public: TAO_InputCDR *cdr (void) const; // Get the CDR stream. - + virtual int dispatch_reply (void) = 0; // Dispatch the reply. protected: CORBA::ULong request_id_; // Request ID for this request. - + TAO_InputCDR *cdr_; // CDR stream for reading the input. - + CORBA::ULong reply_status_; // Replt status. }; @@ -77,11 +77,11 @@ protected: class TAO_Export TAO_Synch_Reply_Dispatcher : public TAO_Reply_Dispatcher { // = TITLE - // - // Reply dispatcher for Synchoronous Method Invocation (SMI)s. + // + // Reply dispatcher for Synchoronous Method Invocation (SMI)s. // // = DESCRIPTION - // + // public: TAO_Synch_Reply_Dispatcher (void); @@ -89,7 +89,7 @@ public: virtual ~TAO_Synch_Reply_Dispatcher (void); // Destructor. - + virtual int dispatch_reply (void); // NO OP. }; diff --git a/TAO/tao/Request_Mux_Strategy.cpp b/TAO/tao/Request_Mux_Strategy.cpp index 48ad156cd42..a71994d264b 100644 --- a/TAO/tao/Request_Mux_Strategy.cpp +++ b/TAO/tao/Request_Mux_Strategy.cpp @@ -117,7 +117,7 @@ TAO_Exclusive_RMS::find_dispatcher (CORBA::ULong request_id) "%N:%l:TAO_Exclusive_RMS::find_handler: " "Failed to find the handler\n"), 0); - + return this->rd_; } diff --git a/TAO/tao/Request_Mux_Strategy.h b/TAO/tao/Request_Mux_Strategy.h index 3a382cd191f..7a0555fb7f2 100644 --- a/TAO/tao/Request_Mux_Strategy.h +++ b/TAO/tao/Request_Mux_Strategy.h @@ -29,14 +29,14 @@ class TAO_Reply_Dispatcher; class TAO_Export TAO_Request_Mux_Strategy { // = TITLE - // + // // Strategy to determine whether the connection should be // multiplexed for multiple requests or it is exclusive for a - // single request at a time. - // + // single request at a time. + // // = DESCRIPTION - // - + // + public: TAO_Request_Mux_Strategy (void); // Base class constructor. @@ -46,29 +46,29 @@ public: virtual CORBA::ULong request_id (void) = 0; // Generate and return an unique request id for the current - // invocation. + // invocation. // = Bind and Find methods for the // pairs. The ReplyDispatcher is not the CORBA ReplyDispatcher of - // the AMI's. - + // the AMI's. + virtual int bind_dispatcher (CORBA::ULong request_id, - TAO_Reply_Dispatcher *rh) = 0; + TAO_Reply_Dispatcher *rh) = 0; // Bind the dispatcher with the request id. - + virtual TAO_Reply_Dispatcher* find_dispatcher (CORBA::ULong request_id) = 0; // Find the Reply Dispatcher. // = "Factory methods" to obtain the CDR stream, in the Muxed case // the factory simply allocates a new one, in the Exclusive case - // the factory returns a pointer to the pre-allocated CDR. + // the factory returns a pointer to the pre-allocated CDR. virtual void set_cdr_stream (TAO_InputCDR *cdr) = 0; // Set the CDR stream. virtual TAO_InputCDR *get_cdr_stream (void); // Get the CDR stream. - + virtual void destroy_cdr_stream (void) = 0; // Destroy the CDR stream. @@ -78,7 +78,7 @@ protected: // is obtained from the Invocation object. This is preallocated in // the SMI and dynamically allocated in AMI. }; - + class TAO_Export TAO_Muxed_RMS : public TAO_Request_Mux_Strategy { // = TITLE @@ -86,28 +86,28 @@ class TAO_Export TAO_Muxed_RMS : public TAO_Request_Mux_Strategy // Connection is multiplexed for many requests. // // = DESCRIPTION - // + // public: TAO_Muxed_RMS (void); // Constructor. - + virtual ~TAO_Muxed_RMS (void); // Destructor. virtual CORBA::ULong request_id (void); // Generate and return an unique request id for the current - // invocation. + // invocation. virtual int bind_dispatcher (CORBA::ULong request_id, TAO_Reply_Dispatcher *rh); // Bind the dispatcher with the request id. - + virtual TAO_Reply_Dispatcher* find_dispatcher (CORBA::ULong request_id); // Find the Reply Dispatcher. - + // virtual TAO_InputCDR *cdr_stream (void); - // Create a new CDR stream and return. + // Create a new CDR stream and return. virtual void set_cdr_stream (TAO_InputCDR *cdr); // Set the CDR stream. @@ -120,21 +120,21 @@ public: protected: // @@ HASH TABLE??? -}; +}; class TAO_Export TAO_Exclusive_RMS : public TAO_Request_Mux_Strategy { // = TITLE - // + // // Connection exclusive for the request. // // = DESCRIPTION - // + // public: TAO_Exclusive_RMS (void); // Constructor. - + virtual ~TAO_Exclusive_RMS (void); // Destructor. @@ -146,13 +146,13 @@ public: virtual int bind_dispatcher (CORBA::ULong request_id, TAO_Reply_Dispatcher *rh); // Bind the dispatcher with the request id. - + virtual TAO_Reply_Dispatcher* find_dispatcher (CORBA::ULong request_id); // Find the Reply Dispatcher. - + // virtual TAO_InputCDR *get_cdr_stream (void); // Return the preallocated CDR stream. - + virtual void set_cdr_stream (TAO_InputCDR *cdr); // Set the CDR stream. @@ -165,8 +165,9 @@ public: protected: CORBA::ULong request_id_; // Request id for the current request. - + TAO_Reply_Dispatcher *rd_; - // Reply Dispatcher corresponding to the request. -}; + // Reply Dispatcher corresponding to the request. +}; + #endif /* REQUEST_MUX_STRATEGY_H */ diff --git a/TAO/tao/Wait_Strategy.cpp b/TAO/tao/Wait_Strategy.cpp index 8a0b7d148d9..6273a26a91c 100644 --- a/TAO/tao/Wait_Strategy.cpp +++ b/TAO/tao/Wait_Strategy.cpp @@ -4,6 +4,8 @@ #include "tao/Pluggable.h" #include "tao/ORB_Core.h" +ACE_RCSID(tao, Wait_Strategy, "$Id$") + // Constructor. TAO_Wait_Strategy::TAO_Wait_Strategy (TAO_Transport *transport) : transport_ (transport) @@ -29,17 +31,23 @@ TAO_Wait_On_Reactor::~TAO_Wait_On_Reactor (void) } // Return value just like the return value of -// . +// . int TAO_Wait_On_Reactor::wait (void) { int result = 0; + // @@ Alex: I assume the reactor was not changing inside of the + // loop, so I took it out, the code is more readable that way + // too. + ACE_Reactor* reactor = + this->transport_->orb_core ()->reactor (); + // Do the event loop, till there are no events and no errors. while (result == 0) { // Do the event loop. - result = this->transport_->orb_core ()->reactor ()->handle_events (/* timeout */); + result = reactor->handle_events (/* timeout */); } return result; @@ -50,6 +58,11 @@ TAO_Wait_On_Reactor::handle_input (void) { int result = 0; + + // @@ Alex: There is no *way* another thread can use the same + // reactor because this class only work in single threaded + // environments. + // Temporarily remove ourself from notification so that if // another sub event loop is in effect still waiting for its // response, it doesn't spin tightly gobbling up CPU. @@ -60,11 +73,11 @@ TAO_Wait_On_Reactor::handle_input (void) "suspend_handler failed"), -1); - // Ask the Transport object to read the input without blocking. + // Ask the Transport object to read the input without blocking. result = this->transport_->handle_client_input (0); if (result == -1) return -1; - + // Resume the handler. if (this->transport_->resume_handler () == -1) ACE_ERROR_RETURN ((LM_ERROR, @@ -73,7 +86,7 @@ TAO_Wait_On_Reactor::handle_input (void) -1); return 0; -} +} // Register the handler with the Reactor. int @@ -116,7 +129,7 @@ TAO_Wait_On_Leader_Follower::wait (void) // @@ Do we need this code? (Alex). ACE_Reactor *r = this->transport_->orb_core ()->reactor (); - + if (this->handler_reactor () != r) { ACE_Reactor_Mask mask = @@ -135,9 +148,9 @@ TAO_Wait_On_Leader_Follower::wait (void) "Failed to get the lock.\n"), -1); - // Set the state so that we know we're looking for a response. + // Set the state so that we know we're looking for a response. this->expecting_response_ = 1; - + // Remember in which thread the client connection handler was running this->calling_thread_ = ACE_Thread::self (); @@ -146,7 +159,7 @@ TAO_Wait_On_Leader_Follower::wait (void) !this->transport_->orb_core ()->I_am_the_leader_thread ()) { // = Wait as a follower. - + // wait as long as no input is available and/or // no leader is available while (!this->input_available_ && @@ -160,9 +173,9 @@ TAO_Wait_On_Leader_Follower::wait (void) "Failed to add a follower thread\n")); cond->wait (); } - + // Now somebody woke us up to become a leader or to handle - // our input. We are already removed from the follower queue. + // our input. We are already removed from the follower queue. if (this->input_available_) { // There is input waiting for me. @@ -173,17 +186,17 @@ TAO_Wait_On_Leader_Follower::wait (void) "TAO:%N:%l:(%P|%t): TAO_Wait_On_Leader_Follower::wait: " "Failed to release the lock.\n"), -1); - + // The following variables are safe, because we are not // registered with the reactor any more. this->input_available_ = 0; this->expecting_response_ = 0; this->calling_thread_ = ACE_OS::NULL_thread; - // Ready to receive the input message. + // Ready to receive the input message. // @@ Is it ok to read it blockingly. (Alex). result = this->transport_->handle_client_input (1); - + // Resume the handler. if (this->transport_->resume_handler () == -1) ACE_ERROR_RETURN ((LM_ERROR, @@ -191,7 +204,7 @@ TAO_Wait_On_Leader_Follower::wait (void) " failed.\n"), -1); - // We should have read the whole message. + // We should have read the whole message. if (result != 1) ACE_ERROR_RETURN ((LM_WARNING, "TAO:%N:%l:(%P|%t):TAO_Wait_On_Leader_Follower::wait: " @@ -205,10 +218,10 @@ TAO_Wait_On_Leader_Follower::wait (void) // update to a leader or we are doing nested upcalls in this // case we do increase the refcount on the leader in // TAO_ORB_Core. - - // This might increase the refcount of the leader. + + // This might increase the refcount of the leader. this->transport_->orb_core ()->set_leader_thread (); - + // Release the lock. if (this->transport_->orb_core ()->leader_follower_lock ().release () == -1) ACE_ERROR_RETURN ((LM_ERROR, @@ -218,20 +231,20 @@ TAO_Wait_On_Leader_Follower::wait (void) // Become owner of the reactor. this->transport_->orb_core ()->reactor ()->owner (ACE_Thread::self ()); - + // Run the reactor event loop. - + result = 0; while (result != -1 && !this->input_available_) result = this->transport_->orb_core ()->reactor ()->handle_events (); - + if (result == -1) ACE_ERROR_RETURN ((LM_ERROR, "TAO:%N:%l:(%P|%t):TAO_Wait_On_Leader_Follower::wait: " "handle_events failed.\n"), -1); - + // Wake up the next leader, we cannot do that in handle_input, // because the woken up thread would try to get into // handle_events, which is at the time in handle_input still @@ -242,12 +255,12 @@ TAO_Wait_On_Leader_Follower::wait (void) "TAO:%N:%l:(%P|%t):TAO_Client_Connection_Handler::send_request: " "Failed to unset the leader and wake up a new follower.\n"), -1); - + // Make use reusable this->input_available_ = 0; this->expecting_response_ = 0; this->calling_thread_ = ACE_OS::NULL_thread; - + return 0; #if 0 @@ -312,7 +325,7 @@ TAO_Wait_On_Leader_Follower::handle_input (void) "Failed to get the lock.\n"), -1); -#if 0 +#if 0 // @@ Later (Alex). if (!this->expecting_response_) @@ -333,7 +346,7 @@ TAO_Wait_On_Leader_Follower::handle_input (void) ACE_Thread::self ())) { // We are now a leader getting its response. - + // Set the flag on. this->input_available_ = 1; @@ -343,9 +356,9 @@ TAO_Wait_On_Leader_Follower::handle_input (void) "(%P|%t) TAO_Client_Connection_Handler::handle_input: " "Failed to release the lock.\n"), -1); - + // Suspend the handler. is called in - // TAO_GIOP_Invocation::invoke + // TAO_GIOP_Invocation::invoke if (this->transport_->suspend_handler () == -1) ACE_ERROR_RETURN ((LM_ERROR, "TAO:%N:%l:(%P|%t): TAO_Wait_On_Leader_Follower::handle_input: " @@ -354,11 +367,11 @@ TAO_Wait_On_Leader_Follower::handle_input (void) // Ask the transport object to read the message. But we should // not block on receiving the whole reply. - + // @@ Are the states such as message_size and message_offset // thread safe, in the Transport object? (Alex). result = this->transport_->handle_client_input (0); - + // Resume the handler. if (this->transport_->resume_handler () == -1) ACE_ERROR_RETURN ((LM_ERROR, @@ -389,7 +402,7 @@ TAO_Wait_On_Leader_Follower::handle_input (void) "TAO:%N:%l:(%P|%t): TAO_Wait_On_Leader_Follower::handle_input: " "Failed to release the lock.\n"), -1); - + // We should wake suspend the thread before we wake him up. // resume_handler is called in TAO_GIOP_Invocation::invoke. if (this->transport_->suspend_handler () == -1) @@ -408,7 +421,7 @@ TAO_Wait_On_Leader_Follower::handle_input (void) "TAO:%N:%l:(%P|%t): TAO_Wait_On_Leader_Follower::handle_input: " "Failed to acquire the lock.\n"), -1); - + // The thread was already selected to become a leader, so we // will be called again. this->input_available_ = 1; @@ -429,9 +442,9 @@ int TAO_Wait_On_Leader_Follower::register_handler (TAO_IIOP_Handler_Base *) { return 0; -} +} -// Resume the connection handler. +// Resume the connection handler. int TAO_Wait_On_Leader_Follower::resume_handler (ACE_Reactor *reactor) { @@ -439,7 +452,7 @@ TAO_Wait_On_Leader_Follower::resume_handler (ACE_Reactor *reactor) } // Send the request in . -// @@ Why do I need here, when I have . +// @@ Why do I need here, when I have . int TAO_Wait_On_Leader_Follower::send_request (TAO_ORB_Core* /* orb_core */, TAO_OutputCDR &stream) @@ -512,7 +525,7 @@ int TAO_Wait_On_Read::register_handler (TAO_IIOP_Handler_Base *) { return 0; -} +} int TAO_Wait_On_Read::resume_handler (ACE_Reactor *reactor) diff --git a/TAO/tao/Wait_Strategy.h b/TAO/tao/Wait_Strategy.h index f0a5179ab89..a1a9d8f2b8f 100644 --- a/TAO/tao/Wait_Strategy.h +++ b/TAO/tao/Wait_Strategy.h @@ -16,7 +16,13 @@ // // ============================================================================ +// @@ Alex: don't forget to protect your files against multiple +// inclusion: +#ifndef TAO_WAIT_STRATEGY_H +#define TAO_WAIT_STRATEGY_H + +// @@ Alex: why do you need this #include? #include "tao/GIOP.h" class TAO_Request_Mux_Strategy; @@ -28,41 +34,49 @@ class TAO_Export TAO_Wait_Strategy // = TITLE // // Strategy for waiting for the reply. - // + // // = DESCRIPTION - // - + // + public: TAO_Wait_Strategy (TAO_Transport *transport); // Constructor. - + virtual ~TAO_Wait_Strategy (void); // Destructor. - + virtual int wait (void) = 0; // Base class virtual method. virtual int handle_input (void) = 0; // Handle the input. + // @@ Alex: this class should *not* depend on the IIOP_Handlers, + // can't you use TAO_Transport for this? After all it returns an + // Event_Handler if you need one... + virtual int register_handler (TAO_IIOP_Handler_Base *handler) = 0; // Register the handler with the Reactor if it makes sense for the // strategy. virtual int resume_handler (ACE_Reactor *reactor) = 0; - // Depending on the wait strategy resume the connect handler. - + // Depending on the wait strategy resume the connect handler. + protected: TAO_Transport *transport_; // Transport object. }; +// @@ Alex: we should consider moving these classes to separate files, +// that can minimize the footprint of systems that use only one of +// the strategies.... + class TAO_Export TAO_Wait_On_Reactor : public TAO_Wait_Strategy { // = TITLE - // + // // Wait on the Reactor. Happens in s Single Threaded client - // environment. + // environment. // // = DESCRIPTION // @@ -70,10 +84,10 @@ class TAO_Export TAO_Wait_On_Reactor : public TAO_Wait_Strategy public: TAO_Wait_On_Reactor (TAO_Transport *transport); // Constructor. - + virtual ~TAO_Wait_On_Reactor (void); // Destructor. - + virtual int wait (void); // Do the event loop of the Reactor. @@ -81,11 +95,15 @@ public: // Handle the input. Delegate this job to Transport object. Before // that suspend the handler in the Reactor. + // @@ Alex: this class should *not* depend on the IIOP_Handlers, + // can't you use TAO_Transport for this? After all it returns an + // Event_Handler if you need one... + virtual int register_handler (TAO_IIOP_Handler_Base *handler); // Register the handler with the Reactor. - + virtual int resume_handler (ACE_Reactor *reactor); - // Resume the connection handler. + // Resume the connection handler. }; class TAO_Export TAO_Wait_On_Leader_Follower : public TAO_Wait_Strategy @@ -95,17 +113,17 @@ class TAO_Export TAO_Wait_On_Leader_Follower : public TAO_Wait_Strategy // Wait according to the Leader-Follower model. Leader does the // event loop of the Reactor and the Followers wait on the // condition variable. - // + // // = DESCRIPTION - // + // public: TAO_Wait_On_Leader_Follower (TAO_Transport *transport); // Constructor. - + virtual ~TAO_Wait_On_Leader_Follower (void); // Destructor. - + virtual int wait (void); // Wait according to the L-F model. @@ -113,11 +131,13 @@ public: // Handle the input. Delegate this job to Transport object. Before // that, suspend the handler in the Reactor. + // @@ Alex: another use of IIOP_Handler... + virtual int register_handler (TAO_IIOP_Handler_Base *handler); // Register the handler with the Reactor. virtual int resume_handler (ACE_Reactor *reactor); - // Resume the connection handler. + // Resume the connection handler. virtual int send_request (TAO_ORB_Core* orb_core, TAO_OutputCDR &stream); @@ -126,13 +146,13 @@ public: protected: ACE_SYNCH_CONDITION* cond_response_available (void); // Return the cond_response_available, initializing it if necessary. - + ACE_thread_t calling_thread_; // the thread ID of the thread we were running in. - + ACE_SYNCH_CONDITION* cond_response_available_; // wait on reponse if the leader-follower model is active. - + int expecting_response_; // State flag which, if non-zero, indicates that we were expecting // respose. Otherwise, any input received is unexpected. @@ -146,12 +166,12 @@ protected: class TAO_Export TAO_Wait_On_Read : public TAO_Wait_Strategy { // = TITLE - // + // // Wait on receiving the reply. // // = DESCRIPTION // - + public: TAO_Wait_On_Read (TAO_Transport *transport); // Constructor. @@ -165,9 +185,13 @@ public: virtual int handle_input (void); // Handle the input. Delegate this job to Transport object. + // @@ Alex: another use of IIOP_Handler... + virtual int register_handler (TAO_IIOP_Handler_Base *handler); // No-op. Return 0. - + virtual int resume_handler (ACE_Reactor *reactor); // Resume the connection handler. No-op. Returns 0. }; + +#endif /* TAO_WAIT_STRATEGY_H */ -- cgit v1.2.1