Public Types | Public Member Functions | Protected Member Functions | Protected Attributes

ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 > Class Template Reference

Abstract factory for creating a service handler (SVC_HANDLER), connecting the SVC_HANDLER, and activating the SVC_HANDLER. More...

#include <Connector.h>

Inheritance diagram for ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >:
Inheritance graph
[legend]
Collaboration diagram for ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef ACE_Creation_Strategy
< SVC_HANDLER > 
creation_strategy_type
typedef ACE_Connect_Strategy
< SVC_HANDLER,
ACE_PEER_CONNECTOR_2 > 
connect_strategy_type
typedef
ACE_Concurrency_Strategy
< SVC_HANDLER > 
concurrency_strategy_type
typedef ACE_Connector
< SVC_HANDLER,
ACE_PEER_CONNECTOR_2 > 
base_type
typedef ACE_Creation_Strategy
< SVC_HANDLER > 
CREATION_STRATEGY
typedef ACE_Connect_Strategy
< SVC_HANDLER,
ACE_PEER_CONNECTOR_2 > 
CONNECT_STRATEGY
typedef
ACE_Concurrency_Strategy
< SVC_HANDLER > 
CONCURRENCY_STRATEGY
typedef ACE_Connector
< SVC_HANDLER,
ACE_PEER_CONNECTOR_2 > 
SUPER

Public Member Functions

 ACE_Strategy_Connector (ACE_Reactor *r=ACE_Reactor::instance(), ACE_Creation_Strategy< SVC_HANDLER > *=0, ACE_Connect_Strategy< SVC_HANDLER, ACE_PEER_CONNECTOR_2 > *=0, ACE_Concurrency_Strategy< SVC_HANDLER > *=0, int flags=0)
virtual int open (ACE_Reactor *r, int flags)
virtual int open (ACE_Reactor *r=ACE_Reactor::instance(), ACE_Creation_Strategy< SVC_HANDLER > *=0, ACE_Connect_Strategy< SVC_HANDLER, ACE_PEER_CONNECTOR_2 > *=0, ACE_Concurrency_Strategy< SVC_HANDLER > *=0, int flags=0)
virtual ~ACE_Strategy_Connector (void)
 Shutdown a connector and release resources.
virtual int close (void)
 Close down the Connector.
virtual ACE_Creation_Strategy
< SVC_HANDLER > * 
creation_strategy (void) const
virtual ACE_Connect_Strategy
< SVC_HANDLER,
ACE_PEER_CONNECTOR_2 > * 
connect_strategy (void) const
virtual
ACE_Concurrency_Strategy
< SVC_HANDLER > * 
concurrency_strategy (void) const

Protected Member Functions

virtual int make_svc_handler (SVC_HANDLER *&sh)
virtual int connect_svc_handler (SVC_HANDLER *&sh, const ACE_PEER_CONNECTOR_ADDR &remote_addr, ACE_Time_Value *timeout, const ACE_PEER_CONNECTOR_ADDR &local_addr, int reuse_addr, int flags, int perms)
virtual int connect_svc_handler (SVC_HANDLER *&sh, SVC_HANDLER *&sh_copy, const ACE_PEER_CONNECTOR_ADDR &remote_addr, ACE_Time_Value *timeout, const ACE_PEER_CONNECTOR_ADDR &local_addr, int reuse_addr, int flags, int perms)
virtual int activate_svc_handler (SVC_HANDLER *svc_handler)

Protected Attributes

CREATION_STRATEGYcreation_strategy_
 Creation strategy for an Connector.
bool delete_creation_strategy_
CONNECT_STRATEGYconnect_strategy_
 Connect strategy for a Connector.
bool delete_connect_strategy_
CONCURRENCY_STRATEGYconcurrency_strategy_
 Concurrency strategy for a Connector.
bool delete_concurrency_strategy_

Detailed Description

template<class SVC_HANDLER, ACE_PEER_CONNECTOR_1>
class ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >

Abstract factory for creating a service handler (SVC_HANDLER), connecting the SVC_HANDLER, and activating the SVC_HANDLER.

Implements a flexible and extensible set of strategies for actively establishing connections with clients. There are three main strategies: (1) creating a SVC_HANDLER, (2) actively initiating a new connection from the client, and (3) activating the SVC_HANDLER with a particular concurrency mechanism after the connection is established.

Definition at line 401 of file Connector.h.


Member Typedef Documentation

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
typedef ACE_Connector<SVC_HANDLER, ACE_PEER_CONNECTOR_2> ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::base_type

Definition at line 414 of file Connector.h.

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
typedef ACE_Concurrency_Strategy<SVC_HANDLER> ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::CONCURRENCY_STRATEGY

Definition at line 422 of file Connector.h.

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
typedef ACE_Concurrency_Strategy<SVC_HANDLER> ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::concurrency_strategy_type

Definition at line 412 of file Connector.h.

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
typedef ACE_Connect_Strategy<SVC_HANDLER, ACE_PEER_CONNECTOR_2> ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::CONNECT_STRATEGY

Definition at line 420 of file Connector.h.

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
typedef ACE_Connect_Strategy<SVC_HANDLER, ACE_PEER_CONNECTOR_2> ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::connect_strategy_type

Definition at line 410 of file Connector.h.

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
typedef ACE_Creation_Strategy<SVC_HANDLER> ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::CREATION_STRATEGY

Definition at line 418 of file Connector.h.

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
typedef ACE_Creation_Strategy<SVC_HANDLER> ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::creation_strategy_type

Definition at line 408 of file Connector.h.

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
typedef ACE_Connector<SVC_HANDLER, ACE_PEER_CONNECTOR_2> ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::SUPER

Definition at line 424 of file Connector.h.


Constructor & Destructor Documentation

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::ACE_Strategy_Connector ( ACE_Reactor r = ACE_Reactor::instance (),
ACE_Creation_Strategy< SVC_HANDLER > *  cre_s = 0,
ACE_Connect_Strategy< SVC_HANDLER, ACE_PEER_CONNECTOR_2 > *  conn_s = 0,
ACE_Concurrency_Strategy< SVC_HANDLER > *  con_s = 0,
int  flags = 0 
)

Initialize a connector. flags indicates how SVC_HANDLER's should be initialized prior to being activated. Right now, the only flag that is processed is ACE_NONBLOCK, which enabled non-blocking I/O on the SVC_HANDLER when it is opened.

Definition at line 871 of file Connector.cpp.

  : creation_strategy_ (0),
    delete_creation_strategy_ (false),
    connect_strategy_ (0),
    delete_connect_strategy_ (false),
    concurrency_strategy_ (0),
    delete_concurrency_strategy_ (false)
{
  ACE_TRACE ("ACE_Connector<SVC_HANDLER, ACE_PEER_CONNECTOR_2>::ACE_Strategy_Connector");

  if (this->open (reactor, cre_s, conn_s, con_s, flags) == -1)
    ACE_ERROR ((LM_ERROR,  ACE_TEXT ("%p\n"),  ACE_TEXT ("ACE_Strategy_Connector::ACE_Strategy_Connector")));
}

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::~ACE_Strategy_Connector ( void   )  [virtual]

Shutdown a connector and release resources.

Definition at line 890 of file Connector.cpp.

{
  ACE_TRACE ("ACE_Strategy_Connector<SVC_HANDLER, ACE_PEER_CONNECTOR_2>::~ACE_Strategy_Connector");

  // Close down
  this->close ();
}


Member Function Documentation

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
int ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::activate_svc_handler ( SVC_HANDLER *  svc_handler  )  [protected, virtual]

Bridge method for activating a SVC_HANDLER with the appropriate concurrency strategy. The default behavior of this method is to activate the SVC_HANDLER by calling its <open> method (which allows the SVC_HANDLER to define its own concurrency strategy). However, subclasses can override this strategy to do more sophisticated concurrency activations (such as creating the SVC_HANDLER as an "active object" via multi-threading or multi-processing).

Reimplemented from ACE_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_2 >.

Definition at line 966 of file Connector.cpp.

{
  return this->concurrency_strategy_->activate_svc_handler (svc_handler, this);
}

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
int ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::close ( void   )  [virtual]

Close down the Connector.

Reimplemented from ACE_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_2 >.

Definition at line 899 of file Connector.cpp.

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
ACE_Concurrency_Strategy< SVC_HANDLER > * ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::concurrency_strategy ( void   )  const [virtual]

Definition at line 984 of file Connector.cpp.

{
  return this->concurrency_strategy_;
}

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
ACE_Connect_Strategy< SVC_HANDLER, ACE_PEER_CONNECTOR_2 > * ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::connect_strategy ( void   )  const [virtual]

Definition at line 978 of file Connector.cpp.

{
  return this->connect_strategy_;
}

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
int ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::connect_svc_handler ( SVC_HANDLER *&  sh,
const ACE_PEER_CONNECTOR_ADDR &  remote_addr,
ACE_Time_Value timeout,
const ACE_PEER_CONNECTOR_ADDR &  local_addr,
int  reuse_addr,
int  flags,
int  perms 
) [protected, virtual]

Bridge method for connecting the new connection into the SVC_HANDLER. The default behavior delegates to the <PEER_CONNECTOR::connect> in the <Connect_Strategy>.

Reimplemented from ACE_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_2 >.

Definition at line 927 of file Connector.cpp.

{
  return this->connect_strategy_->connect_svc_handler (sh,
                                                       remote_addr,
                                                       timeout,
                                                       local_addr,
                                                       reuse_addr,
                                                       flags,
                                                       perms);
}

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
int ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::connect_svc_handler ( SVC_HANDLER *&  sh,
SVC_HANDLER *&  sh_copy,
const ACE_PEER_CONNECTOR_ADDR &  remote_addr,
ACE_Time_Value timeout,
const ACE_PEER_CONNECTOR_ADDR &  local_addr,
int  reuse_addr,
int  flags,
int  perms 
) [protected, virtual]

Bridge method for connecting the new connection into the SVC_HANDLER. The default behavior delegates to the <PEER_CONNECTOR::connect> in the <Connect_Strategy>. sh_copy is used to obtain a copy of the sh pointer, but that can be kept in the stack; the motivation is a bit too long to include here, but basically we want to modify sh safely, using the internal locks in the Connect_Strategy, while saving a TSS copy in sh_copy, usually located in the stack.

Reimplemented from ACE_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_2 >.

Definition at line 946 of file Connector.cpp.

{
  return this->connect_strategy_->connect_svc_handler (sh,
                                                       sh_copy,
                                                       remote_addr,
                                                       timeout,
                                                       local_addr,
                                                       reuse_addr,
                                                       flags,
                                                       perms);
}

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
ACE_Creation_Strategy< SVC_HANDLER > * ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::creation_strategy ( void   )  const [virtual]

Definition at line 972 of file Connector.cpp.

{
  return this->creation_strategy_;
}

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
int ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::make_svc_handler ( SVC_HANDLER *&  sh  )  [protected, virtual]

Bridge method for creating a SVC_HANDLER. The strategy for creating a SVC_HANDLER are configured into the Connector via it's <creation_strategy_>. The default is to create a new SVC_HANDLER only if sh == 0, else sh is unchanged. However, subclasses can override this policy to perform SVC_HANDLER creation in any way that they like (such as creating subclass instances of SVC_HANDLER, using a singleton, dynamically linking the handler, etc.). Returns -1 if failure, else 0.

Reimplemented from ACE_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_2 >.

Definition at line 920 of file Connector.cpp.

{
  return this->creation_strategy_->make_svc_handler (sh);
}

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
int ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::open ( ACE_Reactor r,
int  flags 
) [virtual]

Initialize a connector. flags indicates how SVC_HANDLER's should be initialized prior to being activated. Right now, the only flag that is processed is ACE_NONBLOCK, which enabled non-blocking I/O on the SVC_HANDLER when it is opened. Default strategies would be created and used.

Reimplemented from ACE_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_2 >.

Definition at line 778 of file Connector.cpp.

{
  ACE_TRACE ("ACE_Strategy_Connector<SVC_HANDLER, ACE_PEER_CONNECTOR_2>::open");
  return this->open (r, 0, 0, 0, flags);
}

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
int ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::open ( ACE_Reactor r = ACE_Reactor::instance (),
ACE_Creation_Strategy< SVC_HANDLER > *  cre_s = 0,
ACE_Connect_Strategy< SVC_HANDLER, ACE_PEER_CONNECTOR_2 > *  conn_s = 0,
ACE_Concurrency_Strategy< SVC_HANDLER > *  con_s = 0,
int  flags = 0 
) [virtual]

Initialize a connector. flags indicates how SVC_HANDLER's should be initialized prior to being activated. Right now, the only flag that is processed is ACE_NONBLOCK, which enabled non-blocking I/O on the SVC_HANDLER when it is opened.

Definition at line 787 of file Connector.cpp.

{
  ACE_TRACE ("ACE_Strategy_Connector<SVC_HANDLER, ACE_PEER_CONNECTOR_2>::open");

  this->reactor (r);

  // @@ Not implemented yet.
  // this->flags_ = flags;
  ACE_UNUSED_ARG (flags);

  // Initialize the creation strategy.

  // First we decide if we need to clean up.
  if (this->creation_strategy_ != 0 &&
      this->delete_creation_strategy_ &&
      cre_s != 0)
    {
      delete this->creation_strategy_;
      this->creation_strategy_ = 0;
      this->delete_creation_strategy_ = false;
    }

  if (cre_s != 0)
    this->creation_strategy_ = cre_s;
  else if (this->creation_strategy_ == 0)
    {
      ACE_NEW_RETURN (this->creation_strategy_,
                      CREATION_STRATEGY,
                      -1);
      this->delete_creation_strategy_ = true;
    }


  // Initialize the accept strategy.

  if (this->connect_strategy_ != 0 &&
      this->delete_connect_strategy_ &&
      conn_s != 0)
    {
      delete this->connect_strategy_;
      this->connect_strategy_ = 0;
      this->delete_connect_strategy_ = false;
    }

  if (conn_s != 0)
    this->connect_strategy_ = conn_s;
  else if (this->connect_strategy_ == 0)
    {
      ACE_NEW_RETURN (this->connect_strategy_,
                      CONNECT_STRATEGY,
                      -1);
      this->delete_connect_strategy_ = true;
    }

  // Initialize the concurrency strategy.

  if (this->concurrency_strategy_ != 0 &&
      this->delete_concurrency_strategy_ &&
      con_s != 0)
    {
      delete this->concurrency_strategy_;
      this->concurrency_strategy_ = 0;
      this->delete_concurrency_strategy_ = false;
    }

  if (con_s != 0)
    this->concurrency_strategy_ = con_s;
  else if (this->concurrency_strategy_ == 0)
    {
      ACE_NEW_RETURN (this->concurrency_strategy_,
                      CONCURRENCY_STRATEGY,
                      -1);
      this->delete_concurrency_strategy_ = true;
    }

  return 0;
}


Member Data Documentation

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
CONCURRENCY_STRATEGY* ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::concurrency_strategy_ [protected]

Concurrency strategy for a Connector.

Definition at line 550 of file Connector.h.

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
CONNECT_STRATEGY* ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::connect_strategy_ [protected]

Connect strategy for a Connector.

Definition at line 543 of file Connector.h.

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
CREATION_STRATEGY* ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::creation_strategy_ [protected]

Creation strategy for an Connector.

Definition at line 536 of file Connector.h.

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
bool ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::delete_concurrency_strategy_ [protected]

True if Connector created the concurrency strategy and thus should delete it, else false.

Definition at line 554 of file Connector.h.

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
bool ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::delete_connect_strategy_ [protected]

True if Connector created the connect strategy and thus should delete it, else false.

Definition at line 547 of file Connector.h.

template<class SVC_HANDLER , ACE_PEER_CONNECTOR_1 >
bool ACE_Strategy_Connector< SVC_HANDLER, ACE_PEER_CONNECTOR_1 >::delete_creation_strategy_ [protected]

True if Connector created the creation strategy and thus should delete it, else false.

Definition at line 540 of file Connector.h.


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