summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/LoadBalancing/GenericFactory/DeadMemberDetection_App_Ctrl/Basic.cpp
blob: c0e4eea6316e5aa98426a2a21e8403b30a6813df (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "Basic.h"
#include "LB_server.h"
#include "ace/OS_NS_unistd.h"

extern int pong_delay;

Basic::Basic (int server_id)
: server_id_ (server_id)
{
}

Basic::Basic (CORBA::Object_ptr object_group,
              CosLoadBalancing::LoadManager_ptr lm,
              CORBA::ORB_ptr orb,
              const char *loc,
              int server_id)
  : orb_ (CORBA::ORB::_duplicate (orb)),
    server_id_ (server_id)
{
  this->object_group_ = CORBA::Object::_duplicate (object_group);
  this->lm_ = CosLoadBalancing::LoadManager::_duplicate (lm);
  this->location_ = CORBA::string_dup (loc);
}


/// Default _non_existent: always returns false.
CORBA::Boolean
Basic::_non_existent (void)
{
  if (pong_delay > 0)
    ACE_DEBUG ((LM_DEBUG, "(%P|%t)%T Basic::_non_existent server %d sleep %d seconds ... \n",
      server_id_, pong_delay));
  int i = 0;
  while (i < pong_delay)
  {
    ++i;
    ACE_OS::sleep (1);
  }
  return false;
}

char *
Basic::get_string (void)
{
  return CORBA::string_dup (this->location_.in ());
}

void
Basic::remove_member (void)
{
  try
    {
      PortableGroup::Location location (1);
      location.length (1);
      location[0].id = CORBA::string_dup (this->location_.in ());
      this->lm_->remove_member (this->object_group_.in (),
                                location);

      ACE_DEBUG ((LM_DEBUG, "(%P|%t)%T - Removed Member at Location <%s>\n",
                      this->location_.in ()));
    }
  catch (const PortableGroup::ObjectNotFound& ex)
    {
      ex._tao_print_exception ("Caught exception in remove_member");
      throw CORBA::INTERNAL ();
    }
  catch (const PortableGroup::MemberNotFound& ex)
    {
      ex._tao_print_exception ("Caught exception in remove_member");
      throw CORBA::INTERNAL ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught while destroying member\n");
    }

}

void
Basic::shutdown (void)
{
  this->orb_->shutdown (false);
}

void
Basic::exit (void)
{
  ACE_DEBUG ((LM_DEBUG, "(%P|%t)%T - Basic::exit  server %d exit \n",
                      this->server_id_));

  ACE_OS::exit (0);
}