Acceptor_Impl.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Acceptor_Impl.cpp,v 1.43 2006/03/10 07:19:04 jtc Exp
00004 
00005 // ============================================================================
00006 //
00007 // = LIBRARY
00008 //     TAO
00009 //
00010 // = FILENAME
00011 //     Acceptor_Impl.cpp
00012 //
00013 // = AUTHOR
00014 //     Carlos O'Ryan <coryan@uci.edu>
00015 //     Ossama Othman <ossama@dre.vanderbilt.edu>
00016 //
00017 // ============================================================================
00018 
00019 #ifndef TAO_ACCEPTOR_IMPL_CPP
00020 #define TAO_ACCEPTOR_IMPL_CPP
00021 
00022 #include "tao/Acceptor_Impl.h"
00023 
00024 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00025 # pragma once
00026 #endif /* ACE_LACKS_PRAGMA_ONCE */
00027 
00028 #include "tao/Thread_Per_Connection_Handler.h"
00029 #include "tao/Server_Strategy_Factory.h"
00030 #include "tao/ORB_Core.h"
00031 #include "tao/Transport_Cache_Manager.h"
00032 #include "tao/Thread_Lane_Resources.h"
00033 #include "tao/Transport.h"
00034 #include "tao/debug.h"
00035 
00036 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00037 
00038 //////////////////////////////////////////////////////////////////////////////
00039 
00040 template <class SVC_HANDLER>
00041 TAO_Creation_Strategy<SVC_HANDLER>::TAO_Creation_Strategy (TAO_ORB_Core *orb_core,
00042                                                            CORBA::Boolean flag)
00043   : ACE_Creation_Strategy<SVC_HANDLER> (0, orb_core->reactor()),
00044     orb_core_ (orb_core),
00045     lite_flag_ (flag)
00046 {
00047 }
00048 
00049 template <class SVC_HANDLER> int
00050 TAO_Creation_Strategy<SVC_HANDLER>::make_svc_handler (SVC_HANDLER *&sh)
00051 {
00052   if (sh == 0)
00053     {
00054       // Purge connections (if necessary)
00055       this->orb_core_->lane_resources ().transport_cache ().purge ();
00056 
00057       ACE_NEW_RETURN (sh,
00058                       SVC_HANDLER (this->orb_core_,
00059                                    this->lite_flag_),
00060                       -1);
00061     }
00062 
00063   return 0;
00064 }
00065 
00066 //////////////////////////////////////////////////////////////////////////////
00067 
00068 template <class SVC_HANDLER>
00069 TAO_Concurrency_Strategy<SVC_HANDLER>::TAO_Concurrency_Strategy (TAO_ORB_Core *orb_core)
00070   : orb_core_ (orb_core)
00071 {
00072 }
00073 
00074 template <class SVC_HANDLER> int
00075 TAO_Concurrency_Strategy<SVC_HANDLER>::activate_svc_handler (SVC_HANDLER *sh,
00076                                                              void *arg)
00077 {
00078   sh->transport ()->opened_as (TAO::TAO_SERVER_ROLE);
00079 
00080   // Indicate that this transport was opened in the server role
00081   if (TAO_debug_level > 6)
00082     ACE_DEBUG ((LM_DEBUG,
00083                 "TAO (%P|%t) - Concurrency_Strategy::activate_svc_handler, "
00084                 "opened as TAO_SERVER_ROLE\n"));
00085 
00086   // Here the service handler has been created and the new connection
00087   // has been accepted.  #REFCOUNT# is one at this point.
00088 
00089   if (this->ACE_Concurrency_Strategy<SVC_HANDLER>::activate_svc_handler (sh,
00090                                                                          arg) == -1)
00091     return -1;
00092 
00093   // The service handler has been activated. Now cache the handler.
00094   if (sh->add_transport_to_cache () == -1)
00095     {
00096       // Adding to the cache fails, close the handler.
00097       sh->close ();
00098 
00099       // #REFCOUNT# is zero at this point.
00100 
00101       if (TAO_debug_level > 0)
00102         {
00103           ACE_ERROR ((LM_ERROR,
00104                       ACE_TEXT ("TAO (%P|%t) - Concurrency_Strategy::activate_svc_handler, ")
00105                       ACE_TEXT ("could not add the handler to cache \n")));
00106         }
00107 
00108       return -1;
00109     }
00110 
00111   // Registration with cache is successful, #REFCOUNT# is two at this
00112   // point.
00113 
00114   TAO_Server_Strategy_Factory *f =
00115     this->orb_core_->server_factory ();
00116 
00117   int result = 0;
00118 
00119   // Do we need to create threads?
00120   if (f->activate_server_connections ())
00121     {
00122       // Thread-per-connection concurrency model
00123       TAO_Thread_Per_Connection_Handler *tpch = 0;
00124 
00125       ACE_NEW_RETURN (tpch,
00126                       TAO_Thread_Per_Connection_Handler (sh,
00127                                                          this->orb_core_),
00128                       -1);
00129 
00130       result =
00131         tpch->activate (f->server_connection_thread_flags (),
00132                         f->server_connection_thread_count ());
00133     }
00134   else
00135     {
00136       // Otherwise, it is the reactive concurrency model. We may want
00137       // to register ourselves with the reactor. Call the register
00138       // handler on the transport.
00139       result =
00140         sh->transport ()->register_handler ();
00141     }
00142 
00143   if (result != -1)
00144     {
00145       // Activation/registration successful: the handler has been
00146       // registered with either the Reactor or the
00147       // Thread-per-Connection_Handler, and the Transport Cache.
00148       // #REFCOUNT# is three at this point.
00149 
00150       // We can let go of our reference.
00151       sh->transport ()->remove_reference ();
00152     }
00153   else
00154     {
00155       // Activation/registration failure. #REFCOUNT# is two at this
00156       // point.
00157 
00158       // Remove from cache.
00159       sh->transport ()->purge_entry ();
00160 
00161       // #REFCOUNT# is one at this point.
00162 
00163       // Close handler.
00164       sh->close ();
00165 
00166       // #REFCOUNT# is zero at this point.
00167 
00168       if (TAO_debug_level > 0)
00169          {
00170            const ACE_TCHAR *error = 0;
00171            if (f->activate_server_connections ())
00172              error = ACE_TEXT("could not activate new connection");
00173            else
00174              error = ACE_TEXT("could not register new connection in the reactor");
00175 
00176            ACE_ERROR ((LM_ERROR,
00177                        "TAO (%P|%t) - Concurrency_Strategy::activate_svc_handler, "
00178                        "%s\n", error));
00179          }
00180 
00181       return -1;
00182     }
00183 
00184   // Success: #REFCOUNT# is two at this point.
00185   return result;
00186 }
00187 
00188 //////////////////////////////////////////////////////////////////////////////
00189 
00190 template <class SVC_HANDLER, ACE_PEER_ACCEPTOR_1>
00191 TAO_Accept_Strategy<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::TAO_Accept_Strategy (TAO_ORB_Core *orb_core)
00192   : orb_core_ (orb_core)
00193 {
00194 }
00195 
00196 template <class SVC_HANDLER, ACE_PEER_ACCEPTOR_1> int
00197 TAO_Accept_Strategy<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::open (const ACE_PEER_ACCEPTOR_ADDR &local_addr,
00198                                                              int restart)
00199 {
00200 
00201   return ACCEPT_STRATEGY_BASE::open (local_addr,
00202                                      restart);
00203 }
00204 
00205 template <class SVC_HANDLER, ACE_PEER_ACCEPTOR_1> int
00206 TAO_Accept_Strategy<SVC_HANDLER, ACE_PEER_ACCEPTOR_2>::accept_svc_handler (SVC_HANDLER *svc_handler)
00207 {
00208   return ACCEPT_STRATEGY_BASE::accept_svc_handler (svc_handler);
00209 }
00210 
00211 
00212 /////////////////////////////////////////////////////////////////////
00213 
00214 TAO_END_VERSIONED_NAMESPACE_DECL
00215 
00216 #endif /* TAO_ACCEPTOR_IMPL_CPP */

Generated on Thu Nov 9 11:54:07 2006 for TAO by doxygen 1.3.6