1 #include "tao/Object.h"
3 #include "tao/Adapter_Registry.h"
4 #include "tao/Adapter.h"
5 #include "tao/SystemException.h"
7 #include "tao/TAO_Server_Request.h"
9 #include "ace/Log_Msg.h"
10 #include "ace/OS_NS_string.h"
11 #include "ace/CORBA_macros.h"
14 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
16 TAO_Adapter_Registry::TAO_Adapter_Registry (TAO_ORB_Core
*)
17 : adapters_capacity_ (16), // @@ Make it configurable
21 ACE_NEW (this->adapters_
,
22 TAO_Adapter
*[this->adapters_capacity_
]);
25 TAO_Adapter_Registry::~TAO_Adapter_Registry ()
27 for (size_t i
= 0; i
!= this->adapters_count_
; ++i
)
28 delete this->adapters_
[i
];
30 delete[] this->adapters_
;
34 TAO_Adapter_Registry::close (int wait_for_completion
)
38 for (size_t i
= 0; i
!= this->adapters_count_
; ++i
)
40 this->adapters_
[i
]->close (wait_for_completion
);
43 catch (const::CORBA::Exception
&ex
)
45 if (TAO_debug_level
> 3)
47 ex
._tao_print_exception (
48 "Exception in TAO_Adapter_Registry::close ()");
57 TAO_Adapter_Registry::check_close (int wait_for_completion
)
59 for (size_t i
= 0; i
!= this->adapters_count_
; ++i
)
61 this->adapters_
[i
]->check_close (wait_for_completion
);
66 TAO_Adapter_Registry::insert (TAO_Adapter
*adapter
)
68 if (this->adapters_capacity_
== this->adapters_count_
)
70 this->adapters_capacity_
*= 2;
71 TAO_Adapter
**tmp
= nullptr;
72 ACE_NEW_THROW_EX (tmp
,
73 TAO_Adapter
*[this->adapters_capacity_
],
76 for (size_t i
= 0; i
!= this->adapters_count_
; ++i
)
77 tmp
[i
] = this->adapters_
[i
];
78 delete[] this->adapters_
;
79 this->adapters_
= tmp
;
82 int const priority
= adapter
->priority ();
83 for (size_t i
= 0; i
!= this->adapters_count_
; ++i
)
85 if (this->adapters_
[i
]->priority () >= priority
)
87 for (size_t j
= this->adapters_count_
+ 1;
91 this->adapters_
[j
] = this->adapters_
[j
- 1];
93 this->adapters_
[i
] = adapter
;
94 ++this->adapters_count_
;
98 this->adapters_
[this->adapters_count_
++] = adapter
;
102 TAO_Adapter_Registry::dispatch (TAO::ObjectKey
&key
,
103 TAO_ServerRequest
&request
,
104 CORBA::Object_out forward_to
)
106 for (size_t i
= 0; i
!= this->adapters_count_
; ++i
)
108 int const r
= this->adapters_
[i
]->dispatch (key
, request
, forward_to
);
110 if (r
!= TAO_Adapter::DS_MISMATCHED_KEY
)
116 if (!request
.is_forwarded ())
118 throw ::CORBA::OBJECT_NOT_EXIST ();
123 TAO_Adapter_Registry::create_collocated_object (TAO_Stub
*stub
,
124 const TAO_MProfile
&mprofile
)
126 for (size_t i
= 0; i
!= this->adapters_count_
; ++i
)
128 CORBA::Object_ptr x
=
129 this->adapters_
[i
]->create_collocated_object (stub
, mprofile
);
132 if (!stub
->collocated_servant ())
134 // This adapter created an object but it was not able to locate
135 // a servant so we need to give the rest of the adapters a chance to
136 // initialise the stub and find a servant or forward us or whatever.
137 for (CORBA::Long go_on
= 1; go_on
&& i
!= this->adapters_count_
;
140 // initialize_collocated_object only returns 0 if it has completely
141 // initialised the object.
142 go_on
= this->adapters_
[i
]->initialize_collocated_object (
153 TAO_Adapter_Registry::initialize_collocated_object (TAO_Stub
*stub
)
155 for (size_t i
= 0; i
!= this->adapters_count_
; ++i
)
158 this->adapters_
[i
]->initialize_collocated_object (stub
);
161 // initialize_collocated_object only returns 0 if it has completely
162 // initialised the object. We can return early.
170 TAO_Adapter_Registry::find_adapter (const char *name
) const
172 for (TAO_Adapter
**i
= this->adapters_
;
173 i
!= this->adapters_
+ this->adapters_count_
;
175 if (std::strcmp ((*i
)->name (), name
) == 0)
181 TAO_END_VERSIONED_NAMESPACE_DECL