summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/LoadBalancing/LB_ReplicaLocator.cpp
blob: 8948d06ffc2f02727cf780fcc04b6a49909be193 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// -*- C++ -*-

// $Id$

#include "LB_ReplicaLocator.h"
#include "LoadBalancingI.h"

ACE_RCSID (LoadBalancing,
           LB_ReplicaLocator,
           "$Id$")

TAO_LB_ReplicaLocator::TAO_LB_ReplicaLocator (
  TAO_LoadBalancing_ReplicationManager_i *lb)
  : load_balancer_ (lb)  // Obviously, this pointer shouldn't be zero!
{
}

PortableServer::Servant
TAO_LB_ReplicaLocator::preinvoke (
      const PortableServer::ObjectId &oid,
      PortableServer::POA_ptr /* adapter */,
      const char * /* operation */,
      PortableServer::ServantLocator::Cookie & /* the_cookie */
      TAO_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   PortableServer::ForwardRequest))
{
  TAO_ENV_ARG_DEFN;

  if (this->load_balancer_ == 0)
    ACE_THROW_RETURN (CORBA::INTERNAL (), 0);

  CORBA::Object_var replica =
    this->load_balancer_->replica (oid, ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

//   ACE_DEBUG ((LM_DEBUG,
//               "FORWARDED\n"));

  // Throw a forward exception to force the client to redirect its
  // requests to the Replica chosen by the LoadBalancer.
  ACE_THROW_RETURN (PortableServer::ForwardRequest (
                      replica.in ()),
                    0);
}

void
TAO_LB_ReplicaLocator::postinvoke (
    const PortableServer::ObjectId & /* oid */,
    PortableServer::POA_ptr /* adapter */,
    const char * /* operation */,
    PortableServer::ServantLocator::Cookie /* the_cookie */,
    PortableServer::Servant /* the_servant */
    TAO_ENV_ARG_DECL_NOT_USED)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
}