ImR_Forwarder Class Reference

Implementation Repository Forwarder. More...

#include <Forwarder.h>

Inheritance diagram for ImR_Forwarder:

Inheritance graph
[legend]
Collaboration diagram for ImR_Forwarder:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ImR_Forwarder (ImR_Locator_i &imr_impl)
virtual PortableServer::Servant preinvoke (const PortableServer::ObjectId &oid, PortableServer::POA_ptr poa, const char *operation, PortableServer::ServantLocator::Cookie &cookie) throw (CORBA::SystemException, PortableServer::ForwardRequest)
 Called before the invocation begins.

virtual void postinvoke (const PortableServer::ObjectId &oid, PortableServer::POA_ptr adapter, const char *operation, PortableServer::ServantLocator::Cookie the_cookie, PortableServer::Servant the_servant) throw (CORBA::SystemException)
void init (CORBA::ORB_ptr orb)

Private Attributes

ImR_Locator_ilocator_
 Where we find out where to forward to.

PortableServer::Current_var poa_current_var_
 POA reference.

CORBA::ORB_ptr orb_
 Variable to save the ORB reference passed to the constr.


Detailed Description

Implementation Repository Forwarder.

This class provides a ServantLocator implementation that is used to handle arbitrary calls and forward them to the correct place.

Definition at line 39 of file Forwarder.h.


Constructor & Destructor Documentation

ImR_Forwarder::ImR_Forwarder ImR_Locator_i imr_impl  ) 
 

This constructor takes in orb and ImR_Locator_i pointers to store for later use. It also grabs a reference to the POACurrent object for use in preinvoke.

Definition at line 30 of file Forwarder.cpp.

00031   : locator_ (imr_impl)
00032 {
00033 }


Member Function Documentation

void ImR_Forwarder::init CORBA::ORB_ptr  orb  ) 
 

Definition at line 36 of file Forwarder.cpp.

References CORBA::Current::_narrow(), ACE_ASSERT, ACE_CATCHANY, ACE_CHECK, ACE_DEBUG, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_TRY_CHECK, ACE_TRY_NEW_ENV, LM_DEBUG, and poa_current_var_.

Referenced by ImR_Locator_i::init_with_orb().

00037 {
00038   ACE_ASSERT (! CORBA::is_nil(orb));
00039   this->orb_ = orb;
00040   ACE_TRY_NEW_ENV
00041     {
00042       CORBA::Object_var tmp =
00043         orb->resolve_initial_references ("POACurrent" ACE_ENV_ARG_PARAMETER);
00044       ACE_TRY_CHECK;
00045 
00046       this->poa_current_var_ =
00047         PortableServer::Current::_narrow (tmp.in () ACE_ENV_ARG_PARAMETER);
00048       ACE_TRY_CHECK;
00049     }
00050   ACE_CATCHANY
00051     {
00052       ACE_DEBUG ((LM_DEBUG, "ImR_Forwarder::init() Exception ignored.\n"));
00053     }
00054   ACE_ENDTRY;
00055   ACE_CHECK;
00056   ACE_ASSERT (!CORBA::is_nil (this->poa_current_var_.in ()));
00057 }

void ImR_Forwarder::postinvoke const PortableServer::ObjectId oid,
PortableServer::POA_ptr  adapter,
const char *  operation,
PortableServer::ServantLocator::Cookie  the_cookie,
PortableServer::Servant  the_servant
throw (CORBA::SystemException) [virtual]
 

Definition at line 153 of file Forwarder.cpp.

00160 {
00161 }

PortableServer::Servant ImR_Forwarder::preinvoke const PortableServer::ObjectId oid,
PortableServer::POA_ptr  poa,
const char *  operation,
PortableServer::ServantLocator::Cookie cookie
throw (CORBA::SystemException, PortableServer::ForwardRequest) [virtual]
 

Called before the invocation begins.

We figure out the intended recipient from the POA name. After activating the server, we throw a forwarding exception to the correct server.

The big complicated thing here is that we have to create the forwarding ior based on what we already have. So we combine the endpoint received from activate_server_i and append the objectid from the request to it.

Definition at line 68 of file Forwarder.cpp.

References ACE_ANY_EXCEPTION, ACE_ASSERT, ACE_CATCH, ACE_CATCHANY, ACE_CHECK_RETURN, ACE_CString, ACE_DEBUG, ACE_ENDTRY, ACE_ENV_ARG_PARAMETER, ACE_ERROR, ACE_PRINT_EXCEPTION, ACE_THROW_RETURN, ACE_TRY, ACE_TRY_CHECK, ACE_TRY_THROW, TAO::ObjectKey::encode_sequence_to_string(), TAO::Portable_Server::POA_Current::implementation(), CORBA::is_nil(), LM_DEBUG, LM_ERROR, TAO::Portable_Server::POA_Current_Impl::object_key(), and TAO_IMPLREPO_MINOR_CODE.

00074 {
00075   ACE_ASSERT (! CORBA::is_nil(poa));
00076   CORBA::Object_var forward_obj;
00077 
00078   ACE_TRY
00079     {
00080       CORBA::String_var server_name = poa->the_name();
00081 
00082       if (locator_.debug() > 1)
00083         ACE_DEBUG ((LM_DEBUG, "ImR: Activating server <%s>.\n", server_name.in()));
00084 
00085       // The activator stores a partial ior with each server. We can
00086       // just tack on the current ObjectKey to get a valid ior for
00087       // the desired server.
00088       CORBA::String_var pior = locator_.activate_server_by_name (server_name.in (), false ACE_ENV_ARG_PARAMETER);
00089       ACE_TRY_CHECK;
00090 
00091       ACE_CString ior = pior.in ();
00092 
00093       // Check that the returned ior is the expected partial ior with
00094       // missing ObjectKey.
00095       if (ior.find ("corbaloc:") != 0 || ior[ior.length () - 1] != '/')
00096         {
00097           ACE_ERROR ((LM_ERROR, "ImR_Forwarder::preinvoke () Invalid corbaloc ior.\n\t<%s>\n", ior.c_str()));
00098           ACE_TRY_THROW (CORBA::OBJECT_NOT_EXIST (
00099             CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
00100             CORBA::COMPLETED_NO));
00101         }
00102 
00103       CORBA::String_var key_str;
00104       // Unlike POA Current, this implementation cannot be cached.
00105       TAO::Portable_Server::POA_Current* tao_current =
00106         dynamic_cast <TAO::Portable_Server::POA_Current*> (this->poa_current_var_.in ());
00107 
00108       ACE_ASSERT(tao_current != 0);
00109       TAO::Portable_Server::POA_Current_Impl* impl = tao_current->implementation ();
00110       TAO::ObjectKey::encode_sequence_to_string (key_str.out (), impl->object_key ());
00111 
00112       ior += key_str.in();
00113 
00114       if (locator_.debug() > 0)
00115         ACE_DEBUG ((LM_DEBUG, "ImR: Forwarding invocation on <%s> to <%s>\n", server_name.in(), ior.c_str()));
00116 
00117       forward_obj =
00118         this->orb_->string_to_object (ior.c_str () ACE_ENV_ARG_PARAMETER);
00119       ACE_TRY_CHECK;
00120     }
00121   ACE_CATCH (ImplementationRepository::CannotActivate, ex)
00122     {
00123       ACE_TRY_THROW (CORBA::TRANSIENT (
00124         CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
00125         CORBA::COMPLETED_NO));
00126     }
00127   ACE_CATCH (ImplementationRepository::NotFound, ex)
00128     {
00129       ACE_TRY_THROW (CORBA::TRANSIENT (
00130         CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
00131         CORBA::COMPLETED_NO));
00132     }
00133   ACE_CATCHANY
00134     {
00135       ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Forwarder");
00136       ACE_TRY_THROW (CORBA::TRANSIENT (
00137         CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
00138         CORBA::COMPLETED_NO));
00139     }
00140   ACE_ENDTRY;
00141   ACE_CHECK_RETURN (0);
00142 
00143   if (!CORBA::is_nil (forward_obj.in ()))
00144     ACE_THROW_RETURN (PortableServer::ForwardRequest (forward_obj.in ()), 0);
00145 
00146   ACE_ERROR ((LM_ERROR, "Error: Forward_to reference is nil.\n"));
00147   ACE_THROW_RETURN (CORBA::OBJECT_NOT_EXIST (
00148     CORBA::SystemException::_tao_minor_code (TAO_IMPLREPO_MINOR_CODE, 0),
00149     CORBA::COMPLETED_NO), 0);
00150 }


Member Data Documentation

ImR_Locator_i& ImR_Forwarder::locator_ [private]
 

Where we find out where to forward to.

Definition at line 68 of file Forwarder.h.

CORBA::ORB_ptr ImR_Forwarder::orb_ [private]
 

Variable to save the ORB reference passed to the constr.

Definition at line 74 of file Forwarder.h.

PortableServer::Current_var ImR_Forwarder::poa_current_var_ [private]
 

POA reference.

Definition at line 71 of file Forwarder.h.

Referenced by init().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 13:37:11 2006 for TAO_Implementation_Repository by doxygen 1.3.6