In order to implement the Dynamic Configurator component, the guidelines used for the POA implementation will be followed.
1. IDL Interface Definition
2. Clients and servants point of
view
3. Obtaining and using the Dynamic
Configurator
4. Modifying the ORB
Below comes the listing of the IDL interface used by the Dynamic Configurator.
interface DynamicConfigurator
{
//Exceptions
exception UNEXISTING_SERVICE{};
exception UNKNOWN_ENTITY{};
exception LOAD_SERVICE_ERROR{};
exception HOOK_SERVICE_ERROR{};
exception SUSPEND_SERVICE_ERROR{};
exception RESUME_SERVICE_ERROR{};
exception REMOVE_SERVICE_ERROR{};
exception REPLACE_SERVICE_ERROR{};
exception CONFIGURE_SERVICE_ERROR{};
typedef sequence<string> stringList;
stringList list_loaded_services
();
stringList list_services();
stringList list_implementations(in
string serviceName) raises(UNEXISTING_SERVICE);
stringList get_usage(in
string request);
stringList get_info
(in
string serviceName) raises(UNKNOWN_ENTITY);
stringList list_applications
();
stringList list_hooks
(in
string appName) raises(UNKNOWN_ENTITY);
void load_service
(in
string serviceName, in string impName, in string params) raises(LOAD_SERVICE_ERROR);
void hook_service
(in
string serviceName, in string appName, in string hookName) raises(HOOK_SERVICE_ERROR);
void suspend_service
(in
string serviceName) raises(SUSPEND_SERVICE_ERROR);
void resume_service
(in
string serviceName) raises(RESUME_SERVICE_ERROR);
void remove_service
(in
string serviceName) raises(REMOVE_SERVICE_ERROR);
void replace_service
(in
string serviceName) raises(REPLACE_SERVICE_ERROR);
void configure_service
(in
string serviceName) raises(CONFIGURE_SERVICE_ERROR);
};
2. Clients and servants point of view
By using this new interface, both clients and applications will be able to modify the behavior of the ORB on which they are sitting. This component or service can be obtained in the same way the rest of the ORB components are obtained, that is, by using the resolve_initial_references method. Section 3 provides an example of how to obtain the reference to the DynamicConfigurator and how to modify the behavior of the ORB.
Figure 1 shows how the new component fits in the ORB:
3. Obtaining and using the Dynamic Configurator
As it has been mentioned in the previous section, obtaining the Dynamic Configurator is straightforward, since it adheres to the CORBA specification for obtaining CORBA components.
Next is an example that shows how to obtain the Dynamic Configurator:
CORBA::ORB_var orb;
CORBA::Object_var dynconf_obj;
//Obtain the reference
to the ORB
orb=CORBA::ORB_init(argc,argv,"internet",TAO_TRY_ENV);
dynconf_obj=orb->resolve_initial_references ("DynamicConfigurator");
if (CORBA::is_nil (dynconf_obj.in
()))
ACE_ERROR_RETURN ((LM_ERROR," (%P|%t) Unable to resolve the DynConf Service.\n"),-1);
DynamicConfigurator_var
dyn_conf = DynamicConfigurator::_narrow (dynconf_obj.in (),TAO_TRY_ENV);
Once the reference to the DynamicConfigurator is obtained, it can be used to modify the behavior of the ORB. The next example shows how to obtain a list of services:
DynamicConfigurator::stringList_var
sl;
CORBA::Environment ce;
sl=dyn_conf->list_services(ce);
unsigned int length=sl->length();
ACE_OS::printf("Length of list:%d\n",length);
for(unsigned i=0;i<length;i++)
{
TAO_String_Manager pp=sl[i];
ACE_OS::printf("%s\n",(const char*)pp);
}
Next step consists on modifying the TAO's ORB in order to add the new
component.
4.1 TAO_ORB_Core
The first class that must be modified is TAO_ORB_Core (which is contained in ORB_Core.h). This class contains several key components of the ORB such as the Reactor, the Thread Manager, the Connector, the Acceptor, the POA, etc.
The lines that have been added to the file are:
#if defined(twoK)
#include
"DynamicConfigurator/dynamicConfigurator.h"
#endif
And the lines added to the class are:
(in the public part)
#if defined(twoK)
DynamicConfigurator *dynconf(DynamicConfigurator *dc);
DynamicConfigurator *dynconf(void); //The code of this method is contained
in ORB_Core.i
#endif
This methods are used to get and set the Dynamic Configurator
(in the private part)
#if defined(twoK)
void create_and_set_dynconf (void);
//Initializes the pointer defined below
DynamicConfigurator *dynconf_;
//Pointer to the component.
#endif
The constructor has also been modified in order to assign 0 to dc, when
TAO_ORB_Core is instantiated.
4.2 TAO_Resource_Factory
This class contains the resources that are used by the ORB. It has enough information to decide whether the resourcer is global, belongs to a thread, and so on. By now I will assume that the Dynamic Configurator is a global resource.
The file that contains this class is also ORB_Core.h, and the lines that I have added to TAO_Resource_Factory class are the ones listed below:
(All of them belong to the public part).
#if defined(twoK)
DynamicConfigurator *get_dynconf(void);
#endif
#if defined(twoK)
DynamicConfigurator *dynconf;
#endif
The TAO_Resource_Factory contains two structs: one that contains resources
that can only be allocated after obtaining information from the application,
and another that contains resources that don't need information from applications.
The Dynamic Configurator will be declared inside the first struct, just
in case we need to provide some parameters.
4.3 CORBA.h
This is the master header file for the TAO CORBA ORB. The lines that have been added are:
#if defined(twoK)
#include "dynamicConfigurator/dynamicConfigurator.h"
#endif
4.4 Class CORBA
This class is contained in file ORB.h and it is used for bootsrapping (reference to string, resolve initial references...). The idea of the design of the Dynamic Configurator consists on being able of obtaining its reference in the same way other components are obtained (POA, NameService...).
Within the protected part of the interface, the lines listed below have been added:
#if defined(twoK)
CORBA_Object_ptr resolve_dynconf(void);
#endif
And its implementation can be found in ORB.cpp