Public Member Functions | Private Types | Private Member Functions | Private Attributes

TAO_Muxed_TMS Class Reference

#include <Muxed_TMS.h>

Inheritance diagram for TAO_Muxed_TMS:
Inheritance graph
[legend]
Collaboration diagram for TAO_Muxed_TMS:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TAO_Muxed_TMS (TAO_Transport *transport)
 Constructor.
virtual ~TAO_Muxed_TMS (void)
 Destructor.
virtual CORBA::ULong request_id (void)
virtual int bind_dispatcher (CORBA::ULong request_id, ACE_Intrusive_Auto_Ptr< TAO_Reply_Dispatcher > rd)
 Bind the dispatcher with the request id.
virtual int unbind_dispatcher (CORBA::ULong request_id)
virtual int dispatch_reply (TAO_Pluggable_Reply_Params &params)
virtual int reply_timed_out (CORBA::ULong request_id)
virtual bool idle_after_send (void)
virtual bool idle_after_reply (void)
virtual void connection_closed (void)
virtual bool has_request (void)
 Do we have a request pending.

Private Types

typedef
ACE_Hash_Map_Manager_Ex
< CORBA::ULong,
ACE_Intrusive_Auto_Ptr
< TAO_Reply_Dispatcher >
, ACE_Hash< CORBA::ULong >
, ACE_Equal_To< CORBA::ULong >
, ACE_Null_Mutex
REQUEST_DISPATCHER_TABLE

Private Member Functions

void operator= (const TAO_Muxed_TMS &)
 TAO_Muxed_TMS (const TAO_Muxed_TMS &)
int clear_cache_i (void)

Private Attributes

ACE_Locklock_
 Lock to protect the state of the object.
CORBA::ULong request_id_generator_
TAO_ORB_Core *const orb_core_
REQUEST_DISPATCHER_TABLE dispatcher_table_
 Table of <Request ID, Reply Dispatcher> pairs.

Detailed Description

Using this strategy a single connection can have multiple outstanding requests. @ Can the performance of the demuxer be made more predictable, for example, using the request id as an active demux key?

Note:
Check the OMG resolutions about bidirectional connections, it is possible that the request ids can only assume even or odd values.

Definition at line 49 of file Muxed_TMS.h.


Member Typedef Documentation

Definition at line 98 of file Muxed_TMS.h.


Constructor & Destructor Documentation

TAO_Muxed_TMS::TAO_Muxed_TMS ( TAO_Transport transport  ) 

Constructor.

Definition at line 16 of file Muxed_TMS.cpp.

TAO_Muxed_TMS::~TAO_Muxed_TMS ( void   )  [virtual]

Destructor.

Definition at line 27 of file Muxed_TMS.cpp.

{
  delete this->lock_;
}

TAO_Muxed_TMS::TAO_Muxed_TMS ( const TAO_Muxed_TMS  )  [private]

Member Function Documentation

int TAO_Muxed_TMS::bind_dispatcher ( CORBA::ULong  request_id,
ACE_Intrusive_Auto_Ptr< TAO_Reply_Dispatcher rd 
) [virtual]

Bind the dispatcher with the request id.

Implements TAO_Transport_Mux_Strategy.

Definition at line 68 of file Muxed_TMS.cpp.

{
  ACE_GUARD_RETURN (ACE_Lock,
                    ace_mon,
                    *this->lock_,
                    -1);

  if (rd == 0)
    {
      if (TAO_debug_level > 0)
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("TAO (%P|%t) - TAO_Muxed_TMS::bind_dispatcher, ")
                      ACE_TEXT ("null reply dispatcher\n")));
        }
      return 0;
    }

  int const result = this->dispatcher_table_.bind (request_id, rd);

  if (result != 0)
    {
      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("TAO (%P|%t) - TAO_Muxed_TMS::bind_dispatcher, ")
                    ACE_TEXT ("bind dispatcher failed: result = %d, request id = %d\n"),
                    result, request_id));

      return -1;
    }

  return 0;
}

int TAO_Muxed_TMS::clear_cache_i ( void   )  [private]

Definition at line 260 of file Muxed_TMS.cpp.

{
  if (this->dispatcher_table_.current_size () == 0)
    return -1;

  REQUEST_DISPATCHER_TABLE::ITERATOR const end =
    this->dispatcher_table_.end ();

  ACE_Unbounded_Stack <ACE_Intrusive_Auto_Ptr<TAO_Reply_Dispatcher> > ubs;

  for (REQUEST_DISPATCHER_TABLE::ITERATOR i =
         this->dispatcher_table_.begin ();
       i != end;
       ++i)
    {
      ubs.push ((*i).int_id_);
    }

  this->dispatcher_table_.unbind_all ();
  size_t const sz = ubs.size ();

  for (size_t k = 0 ; k != sz ; ++k)
    {
      ACE_Intrusive_Auto_Ptr<TAO_Reply_Dispatcher> rd(0);

      if (ubs.pop (rd) == 0)
        {
          rd->connection_closed ();
        }
    }

  return 0;
}

void TAO_Muxed_TMS::connection_closed ( void   )  [virtual]

The transport object has closed the connection, inform all Reply dispatchers and waiting strategies.

Implements TAO_Transport_Mux_Strategy.

Definition at line 245 of file Muxed_TMS.cpp.

{
  ACE_GUARD (ACE_Lock,
             ace_mon,
             *this->lock_);

  int retval = 0;
  do
    {
      retval = this->clear_cache_i ();
    }
  while (retval != -1);
}

int TAO_Muxed_TMS::dispatch_reply ( TAO_Pluggable_Reply_Params params  )  [virtual]

Dispatch the reply for request_id, cleanup any resources allocated for that request.

Implements TAO_Transport_Mux_Strategy.

Definition at line 126 of file Muxed_TMS.cpp.

{
  int result = 0;
  ACE_Intrusive_Auto_Ptr<TAO_Reply_Dispatcher> rd(0);

  // Grab the reply dispatcher for this id.
  {
    ACE_GUARD_RETURN (ACE_Lock,
                      ace_mon,
                      *this->lock_,
                      -1);
    result = this->dispatcher_table_.unbind (params.request_id_, rd);
  }

    if (result == 0 && rd)
      {
        if (TAO_debug_level > 8)
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("TAO (%P|%t) - TAO_Muxed_TMS::dispatch_reply, ")
                      ACE_TEXT ("id = %d\n"),
                      params.request_id_));

        // Dispatch the reply.
        // They return 1 on success, and -1 on failure.
        result = rd->dispatch_reply (params);
      }
    else
      {
        if (TAO_debug_level > 0)
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("TAO (%P|%t) - TAO_Muxed_TMS::dispatch_reply, ")
                      ACE_TEXT ("unbind dispatcher failed, id %d: result = %d\n"),
                      params.request_id_,
                      result));

      // Result = 0 means that the mux strategy was not able
      // to find a registered reply handler, either because the reply
      // was not our reply - just forget about it - or it was ours, but
      // the reply timed out - just forget about the reply.
      result = 0;
    }


  return result;
}

bool TAO_Muxed_TMS::has_request ( void   )  [virtual]

Do we have a request pending.

Implements TAO_Transport_Mux_Strategy.

Definition at line 115 of file Muxed_TMS.cpp.

{
  ACE_GUARD_RETURN (ACE_Lock,
                    ace_mon,
                    *this->lock_,
                    false);

  return this->dispatcher_table_.current_size () > 0;
}

bool TAO_Muxed_TMS::idle_after_reply ( void   )  [virtual]

Request is sent and the reply is received. Idle the transport now. The return value indicates whether idling was successful or not.

Implements TAO_Transport_Mux_Strategy.

Definition at line 239 of file Muxed_TMS.cpp.

{
  return false;
}

bool TAO_Muxed_TMS::idle_after_send ( void   )  [virtual]

Request has been just sent, but the reply is not received. Idle the transport now. The return value indicates whether idling was successful or not.

Implements TAO_Transport_Mux_Strategy.

Definition at line 227 of file Muxed_TMS.cpp.

{
  // Irrespective of whether we are successful or not we need to
  // return true. If *this* class is not successfull in idling the
  // transport no one can.
  if (this->transport_ != 0)
    (void) this->transport_->make_idle ();

  return true;
}

void TAO_Muxed_TMS::operator= ( const TAO_Muxed_TMS  )  [private]
int TAO_Muxed_TMS::reply_timed_out ( CORBA::ULong  request_id  )  [virtual]

Dispatch a reply timeout for request request_id

Implements TAO_Transport_Mux_Strategy.

Definition at line 173 of file Muxed_TMS.cpp.

{
  int result = 0;
  ACE_Intrusive_Auto_Ptr<TAO_Reply_Dispatcher> rd(0);

  // Grab the reply dispatcher for this id.
  {
    ACE_GUARD_RETURN (ACE_Lock,
                      ace_mon,
                      *this->lock_,
                      -1);

    result = this->dispatcher_table_.unbind (request_id, rd);
  }

  if (result == 0 && rd)
    {
      if (TAO_debug_level > 8)
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("TAO (%P|%t) - TAO_Muxed_TMS::reply_timed_out, ")
                      ACE_TEXT ("id = %d\n"),
                      request_id));
        }

      // Do not move it outside the scope of the lock. A follower thread
      // could have timedout unwinding the stack and the reply
      // dispatcher, and that would mean the present thread could be left
      // with a dangling pointer and may crash. To safeguard against such
      // cases we dispatch with the lock held.
      // Dispatch the reply.
      rd->reply_timed_out ();
    }
  else
    {
      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("TAO (%P|%t) - TAO_Muxed_TMS::reply_timed_out, ")
                    ACE_TEXT ("unbind dispatcher failed, id %d: result = %d\n"),
                    request_id,
                    result));

      // Result = 0 means that the mux strategy was not able
      // to find a registered reply handler, either because the reply
      // was not our reply - just forget about it - or it was ours, but
      // the reply timed out - just forget about the reply.
      result = 0;
    }

  return result;
}

CORBA::ULong TAO_Muxed_TMS::request_id ( void   )  [virtual]

Generate and return an unique request id for the current invocation.

Implements TAO_Transport_Mux_Strategy.

Definition at line 35 of file Muxed_TMS.cpp.

{
  // @@ What is a good error return value?
  ACE_GUARD_RETURN (ACE_Lock,
                    ace_mon,
                    *this->lock_,
                    0);

  ++this->request_id_generator_;

  // if TAO_Transport::bidirectional_flag_
  //  ==  1 --> originating side
  //  ==  0 --> other side
  //  == -1 --> no bi-directional connection was negotiated
  // The originating side must have an even request ID, and the other
  // side must have an odd request ID.  Make sure that is the case.
  int const bidir_flag = this->transport_->bidirectional_flag ();

  if ((bidir_flag == 1 && ACE_ODD (this->request_id_generator_))
       || (bidir_flag == 0 && ACE_EVEN (this->request_id_generator_)))
    ++this->request_id_generator_;

  if (TAO_debug_level > 4)
    ACE_DEBUG ((LM_DEBUG,
                "TAO (%P|%t) - Muxed_TMS[%d]::request_id, <%d>\n",
                this->transport_->id (),
                this->request_id_generator_));

  return this->request_id_generator_;
}

int TAO_Muxed_TMS::unbind_dispatcher ( CORBA::ULong  request_id  )  [virtual]

Unbind the dispatcher, the client is no longer waiting for the request, for example, because the request timedout. The strategy can (must) cleanup any resources associated with the request. A later reply for that request should be ignored.

Implements TAO_Transport_Mux_Strategy.

Definition at line 104 of file Muxed_TMS.cpp.

{
  ACE_GUARD_RETURN (ACE_Lock,
                    ace_mon,
                    *this->lock_,
                    -1);

  return this->dispatcher_table_.unbind (request_id);
}


Member Data Documentation

Table of <Request ID, Reply Dispatcher> pairs.

Definition at line 101 of file Muxed_TMS.h.

Lock to protect the state of the object.

Definition at line 83 of file Muxed_TMS.h.

Keep track of the orb core pointer. We need to this to create the Reply Dispatchers.

Definition at line 91 of file Muxed_TMS.h.

Used to generate a different request_id on each call to request_id().

Definition at line 87 of file Muxed_TMS.h.


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