summaryrefslogtreecommitdiff
path: root/TAO/tao/Dynamic_TP/DTP_ORBInitializer.cpp
blob: fc8e97f187faf26d2dac9c64138a6f0d9d95378b (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// $Id$

#include "tao/Dynamic_TP/DTP_ORBInitializer.h"

#if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0

#include "tao/Dynamic_TP/DTP_Config.h"
#include "tao/Dynamic_TP/DTP_Thread_Lane_Resources_Manager.h"
#include "tao/Dynamic_TP/DTP_Thread_Pool.h"
#include "tao/Exception.h"
#include "tao/ORB_Core.h"
#include "tao/PI/ORBInitInfo.h"
#include "tao/debug.h"
#include "tao/Leader_Follower.h"

#include "ace/Service_Repository.h"
#include "ace/Svc_Conf.h"
#include "ace/Sched_Params.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

TAO_DTP_ORBInitializer::TAO_DTP_ORBInitializer (/*const ACE_CString &tplist*/)
{

}

void
TAO_DTP_ORBInitializer::pre_init (PortableInterceptor::ORBInitInfo_ptr info)
{
  TAO_ORBInitInfo_var tao_info = TAO_ORBInitInfo::_narrow (info);

  if (CORBA::is_nil (tao_info.in ()))
    {
      if (TAO_debug_level > 0)
        TAOLIB_ERROR ((LM_ERROR,
                    ACE_TEXT ("(%P|%t) TAO_DTP_ORBInitializer::pre_init:\n")
                    ACE_TEXT ("(%P|%t)    Unable to narrow ")
                    ACE_TEXT ("\"PortableInterceptor::ORBInitInfo_ptr\" to\n")
                    ACE_TEXT ("(%P|%t)   \"TAO_ORBInitInfo *.\"\n")));

      throw ::CORBA::INTERNAL ();
    }


  ACE_Service_Gestalt *gestalt = tao_info->orb_core ()->configuration();

  ACE_Service_Object * const config_obj =
    ACE_Dynamic_Service<ACE_Service_Object>::instance (
      gestalt,
      "DTP_Config",
      true);
  if (config_obj == 0)
    {
      // no config manager object loaded
      return;
    }

  TAO_DTP_Config *config_mgr = dynamic_cast<TAO_DTP_Config *>(config_obj);
  if (config_mgr == 0)
    {
      if (TAO_debug_level > 0)
        TAOLIB_ERROR ((LM_ERROR,
                    ACE_TEXT ("(%P|%t) TAO_DTP_ORBInitializer::pre_init:\n")
                    ACE_TEXT ("(%P|%t)   Unable to resolve DTP_Config ")
                    ACE_TEXT ("object\n")));

      throw ::CORBA::INTERNAL ();
    }

  // Set the name of the thread lane resources manager to be
  // DTP_Thread_Lane_Resources_Manager.
  tao_info->orb_core ()->orb_params ()
    ->thread_lane_resources_manager_factory_name (
        "DTP_Thread_Lane_Resources_Manager_Factory");
  ACE_Service_Config::process_directive (
    ace_svc_desc_TAO_DTP_Thread_Lane_Resources_Manager_Factory);

}

void
TAO_DTP_ORBInitializer::post_init (PortableInterceptor::ORBInitInfo_ptr info)
{
  TAO_ORBInitInfo_var tao_info = TAO_ORBInitInfo::_narrow (info);

  TAO_Thread_Lane_Resources_Manager &tlrm =
    tao_info->orb_core ()->thread_lane_resources_manager();

  ACE_Service_Gestalt *gestalt = tao_info->orb_core ()->configuration();

  const char *dtp_name =
    tao_info->orb_core ()->orb_params ()->dynamic_thread_pool_config_name ();

  if (dtp_name != 0 && dtp_name[0] != 0)
    {
      if (TAO_debug_level > 0)
        {
          TAOLIB_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("(%P|%t) TAO_DTP_ORBInitializer::post_init ")
                      ACE_TEXT ("using thread pool name %s\n"), dtp_name));
        }

      TAO_DTP_Config_Registry *config_registry =
        dynamic_cast<TAO_DTP_Config_Registry *>
        (ACE_Dynamic_Service<ACE_Service_Object>::instance
         (gestalt, "DTP_Config_Registry", true));

      TAO_DTP_Definition def;

      if (config_registry == 0 || !config_registry->find(dtp_name, def))
        {
          if (TAO_debug_level > 0)
            TAOLIB_ERROR ((LM_ERROR,
                        ACE_TEXT ("(%P|%t) TAO_DTP_ORBInitializer::")
                        ACE_TEXT ("post_init:\n")
                        ACE_TEXT ("(%P|%t)   Unable to resolve ")
                        ACE_TEXT ("DTP_Config object\n")));

          throw ::CORBA::INTERNAL ();
        }

      TAO_DTP_Thread_Lane_Resources_Manager &dtp_tlrm =
        dynamic_cast<TAO_DTP_Thread_Lane_Resources_Manager &>(tlrm);

      dtp_tlrm.tp_manager().create_threadpool (def);

      tao_info->orb_core ()->leader_follower ().set_avoid_client_leader ();

    }


}


TAO_END_VERSIONED_NAMESPACE_DECL

#endif /* TAO_HAS_CORBA_MESSAGING && TAO_HAS_CORBA_MESSAGING != 0 */