Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends

TAO::CSD::Strategy_Base Class Reference

Base class for all Custom Servant Dispatching Strategies. More...

#include <CSD_Strategy_Base.h>

Inheritance diagram for TAO::CSD::Strategy_Base:
Inheritance graph
[legend]
Collaboration diagram for TAO::CSD::Strategy_Base:
Collaboration graph
[legend]

List of all members.

Public Types

enum  DispatchResult { DISPATCH_HANDLED, DISPATCH_REJECTED, DISPATCH_DEFERRED }
 

Result Type for dispatching method(s).

More...

Public Member Functions

virtual ~Strategy_Base ()
 Virtual Destructor.
CORBA::Boolean apply_to (PortableServer::POA_ptr poa)

Protected Member Functions

 Strategy_Base ()
 Default Constructor.
virtual DispatchResult dispatch_remote_request_i (TAO_ServerRequest &server_request, const PortableServer::ObjectId &object_id, PortableServer::POA_ptr poa, const char *operation, PortableServer::Servant servant)=0
 Subclass provides implementation to dispatch a remote request.
virtual DispatchResult dispatch_collocated_request_i (TAO_ServerRequest &server_request, const PortableServer::ObjectId &object_id, PortableServer::POA_ptr poa, const char *operation, PortableServer::Servant servant)=0
 Subclass provides implementation to dispatch a collocated request.
virtual bool poa_activated_event_i (TAO_ORB_Core &orb_core)=0
 Event - The POA has been activated.
virtual void poa_deactivated_event_i ()=0
 Event - The POA has been deactivated.
virtual void servant_activated_event_i (PortableServer::Servant servant, const PortableServer::ObjectId &oid)
 Event - A servant has been activated.
virtual void servant_deactivated_event_i (PortableServer::Servant servant, const PortableServer::ObjectId &oid)
 Event - A servant has been deactivated.

Private Member Functions

void dispatch_request (TAO_ServerRequest &server_request,::TAO::Portable_Server::Servant_Upcall &upcall)
bool poa_activated_event (TAO_ORB_Core &orb_core)
void poa_deactivated_event ()
void servant_activated_event (PortableServer::Servant servant, const PortableServer::ObjectId &oid)
 Event - A servant has been activated.
void servant_deactivated_event (PortableServer::Servant servant, const PortableServer::ObjectId &oid)

Private Attributes

::PortableServer::POA_var poa_
 The POA to which this strategy has been applied.
bool poa_activated_

Friends

class Strategy_Proxy

Detailed Description

Base class for all Custom Servant Dispatching Strategies.

This class serves as the base class for all "custom" strategies that perform servant dispatching. An instance of (a subclass of) this class can be applied to a POA object. Any servant requests for the POA will be "dispatched" to this strategy object.

Definition at line 56 of file CSD_Strategy_Base.h.


Member Enumeration Documentation

enum TAO::CSD::Strategy_Base::DispatchResult

Result Type for dispatching method(s).

Enumerator:
DISPATCH_HANDLED 
DISPATCH_REJECTED 
DISPATCH_DEFERRED 

Definition at line 63 of file CSD_Strategy_Base.h.

      {
        // The request dispatching has been handled.
        DISPATCH_HANDLED,

        // The request dispatching has been rejected.
        DISPATCH_REJECTED,

        // Defer to "default" dispatching strategy (use the caller's thread).
        DISPATCH_DEFERRED
      };


Constructor & Destructor Documentation

TAO::CSD::Strategy_Base::~Strategy_Base (  )  [virtual]

Virtual Destructor.

Definition at line 21 of file CSD_Strategy_Base.cpp.

{
}

TAO::CSD::Strategy_Base::Strategy_Base (  )  [protected]

Default Constructor.

Definition at line 10 of file CSD_Strategy_Base.inl.

  : poa_activated_(false)
{
}


Member Function Documentation

CORBA::Boolean TAO::CSD::Strategy_Base::apply_to ( PortableServer::POA_ptr  poa  ) 

This method is invoked to "attach" this strategy object to the supplied POA. Returns true for success, and false for failure.

Definition at line 26 of file CSD_Strategy_Base.cpp.

{
  if (CORBA::is_nil(poa))
    {
      if (TAO_debug_level > 0)
        ACE_ERROR((LM_ERROR,
                   ACE_TEXT("(%P|%t) CSD Strategy cannot ")
                   ACE_TEXT("be applied to a nil POA.\n")));
      return false;
    }

  if (!CORBA::is_nil(this->poa_.in()))
    {
      if (TAO_debug_level > 0)
        ACE_ERROR((LM_ERROR,
                   ACE_TEXT("(%P|%t) CSD Strategy already ")
                   ACE_TEXT("applied to a POA.\n")));
      return false;
    }

  // The POA is a local interface (IDL terminology), and thus we know that
  // we can downcast the POA_ptr to its (TAO) implementation type.
  TAO_CSD_POA* poa_impl = dynamic_cast<TAO_CSD_POA*>(poa);

  if (poa_impl == 0)
    {
      if (TAO_debug_level > 0)
        ACE_ERROR((LM_ERROR,
                   ACE_TEXT("(%P|%t) CSD Strategy cannot ")
                   ACE_TEXT("be applied to a non CSD POA.\n")));
      return false;
    }

  // We need to check to see if the POA is already "active".  If this is
  // the case, then we need to handle the poa_activated_event() right now.
  // If the POA is not already "active", then we can just wait until it
  // does get activated, and we (the strategy) will be informed of the
  // poa_activated_event() at that time.
  if (poa_impl->tao_poa_manager().get_state() ==
                                       PortableServer::POAManager::ACTIVE)
    {
      // The POA is already "active" (since its POAManager is active).
      // We need to "raise" the poa_activated_event() now.  Otherwise,
      // the event will be raised when the POAManager does become active.
      if (!this->poa_activated_event( poa_impl->orb_core() ))
        {
          // An error has been already been reported to the log with
          // the detailed reason for the failure to handle the event.
          return false;
        }
    }

  // Set the CSD Strategy_Base on the strategy proxy object owned by the POA.
  bool strategy_set = false;
  try
    {
      poa_impl->set_csd_strategy (this);
      strategy_set = true;
    }
  catch (const ::CORBA::Exception&)
    {
    }

  if (! strategy_set)
    {
      // We need to make sure that we raise a poa_deactivated_event() if
      // we earlier raised a poa_activated_event().
      this->poa_deactivated_event();

      // An error has been already been reported to the log with
      // the detailed reason why the proxy will not accept the
      // custom strategy.
      return false;
    }

  // Save a duplicate of the poa into our data member.
  this->poa_ = PortableServer::POA::_duplicate (poa);

  // Success
  return true;
}

virtual DispatchResult TAO::CSD::Strategy_Base::dispatch_collocated_request_i ( TAO_ServerRequest server_request,
const PortableServer::ObjectId object_id,
PortableServer::POA_ptr  poa,
const char *  operation,
PortableServer::Servant  servant 
) [protected, pure virtual]

Subclass provides implementation to dispatch a collocated request.

Implemented in TAO::CSD::TP_Strategy.

virtual DispatchResult TAO::CSD::Strategy_Base::dispatch_remote_request_i ( TAO_ServerRequest server_request,
const PortableServer::ObjectId object_id,
PortableServer::POA_ptr  poa,
const char *  operation,
PortableServer::Servant  servant 
) [protected, pure virtual]

Subclass provides implementation to dispatch a remote request.

Implemented in TAO::CSD::TP_Strategy.

void TAO::CSD::Strategy_Base::dispatch_request ( TAO_ServerRequest server_request,
::TAO::Portable_Server::Servant_Upcall &  upcall 
) [private]

This CSD Strategy_Base has been asked to dispatch a (collocated or remote) request.

bool TAO::CSD::Strategy_Base::poa_activated_event ( TAO_ORB_Core orb_core  )  [private]

Event - The POA has been activated. This happens when the POA_Manager is activated.

Definition at line 87 of file CSD_Strategy_Base.inl.

{
  // Notify the subclass of the event, saving the result.
  this->poa_activated_ = this->poa_activated_event_i(orb_core);

  // Return the result
  return this->poa_activated_;
}

virtual bool TAO::CSD::Strategy_Base::poa_activated_event_i ( TAO_ORB_Core orb_core  )  [protected, pure virtual]

Event - The POA has been activated.

Implemented in TAO::CSD::TP_Strategy.

void TAO::CSD::Strategy_Base::poa_deactivated_event (  )  [private]

Event - The POA has been deactivated. This happens when the POAManager is deactivated, or when the POA is destroyed.

Definition at line 98 of file CSD_Strategy_Base.inl.

{
  if (this->poa_activated_)
    {
      this->poa_activated_ = false;

      // Notify the subclass of the event.
      this->poa_deactivated_event_i();

      // Reset the poa to nil to decrement the reference count.
      // This will break the circular dependency of the deletion
      // of the CSD POA.
      this->poa_ = 0;
    }
}

virtual void TAO::CSD::Strategy_Base::poa_deactivated_event_i (  )  [protected, pure virtual]

Event - The POA has been deactivated.

Implemented in TAO::CSD::TP_Strategy.

void TAO::CSD::Strategy_Base::servant_activated_event ( PortableServer::Servant  servant,
const PortableServer::ObjectId oid 
) [private]

Event - A servant has been activated.

Definition at line 117 of file CSD_Strategy_Base.inl.

{
  this->servant_activated_event_i(servant, oid);
}

void TAO::CSD::Strategy_Base::servant_activated_event_i ( PortableServer::Servant  servant,
const PortableServer::ObjectId oid 
) [protected, virtual]

Event - A servant has been activated.

Reimplemented in TAO::CSD::TP_Strategy.

Definition at line 111 of file CSD_Strategy_Base.cpp.

{
  // do nothing.
}

void TAO::CSD::Strategy_Base::servant_deactivated_event ( PortableServer::Servant  servant,
const PortableServer::ObjectId oid 
) [private]

Event - A servant has been deactivated. This also occurs when the POA is destroyed.

Definition at line 126 of file CSD_Strategy_Base.inl.

{
  this->servant_deactivated_event_i(servant, oid);
}

void TAO::CSD::Strategy_Base::servant_deactivated_event_i ( PortableServer::Servant  servant,
const PortableServer::ObjectId oid 
) [protected, virtual]

Event - A servant has been deactivated.

Reimplemented in TAO::CSD::TP_Strategy.

Definition at line 120 of file CSD_Strategy_Base.cpp.

{
  // do nothing.
}


Friends And Related Function Documentation

friend class Strategy_Proxy [friend]

Only our friend, the proxy, is allowed to invoke our private operations. This allows us to not pollute the public interface of the CSD Strategy_Base subclasses with methods that should never be called (except by the proxy, of course).

Definition at line 124 of file CSD_Strategy_Base.h.


Member Data Documentation

::PortableServer::POA_var TAO::CSD::Strategy_Base::poa_ [private]

The POA to which this strategy has been applied.

Definition at line 149 of file CSD_Strategy_Base.h.

bool TAO::CSD::Strategy_Base::poa_activated_ [private]

This flag indicates that the POA is currently active (true) or currently inactive (false).

Definition at line 153 of file CSD_Strategy_Base.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines