dynamicTAO Strategy Factories can be dynamically added to the ORB, thus modifying its behavior. All Strategy Factories must inherit from Simple_Strategy_Factory. This last class inherits from ACE_Service_Object, wihch is the abstract base class common to all service implementations.
Strategy_Factories are implemented as DLLs.
Simple_Strategy_Factory defines five virtual methods:
The last method returns a pointer to the strategy that is going to be installed in the ORB.
- virtual int open ()
- virtual int init (int, char *[])
- virtual int info (char **info_string, size_t length)
- virtual int fini ()
- virtual void *strategy ()
Creating a new Strategy_Factory
Following sections explain the steps involved in creating a new Strategy_Factory.
In order to make it clear, an example will be used. The example that will
be used is the Reactive_Strategy and can be obtained from the dynamicTAO
source code.
1. Defining a new strategy factory
New strategies must always inherit from Simple_Strategy_Factory,
and
provide an implementation for the virtual methods defined in the base class.
Ex:
class Reactive_Strategy_Factory : public Simple_Strategy_FactoryAnd once the class has defined, the ACE_FACTORY_DECLARE must be called because it is responsible for declaring the method that will be called when the Strategy_Factory is dynamically loaded.
{
public:Reactive_Strategy_Factory (void);
~Reactive_Strategy_Factory(void);int open (void);
int info (char **info_string, size_t length) const;void *strategy (void);
ACE_Reactive_Strategy TAO_Server_Connection_Handler> reactive_strategy_; //This is the instance to the Reactive_Strategy object.
};
ACE_FACTORY_DECLARE (ACE, Reactive_Strategy_Factory)
2. Implementing the class
Once the class is defined, its methods must be implemented.
When the class is dynamically loaded, the init method it is called. This method is responsible for initializing the object. In the example being used, nothing needs to be done in order to initialize the Reactive_Strategy_Factory, so the base class default implementation (does nothing) is used.
The open method is called by the application configurator's install method, whenever we ask to hook a new service.
int Reactive_Strategy_Factory::open (void)In the case of our example, this method obtains a pointer to the TAO_ORB_Core, gets the ORB's reactor and passes it to the open method of the reactive_strategy instance.
{
TAO_ORB_Core *orb_core = TAO_ORB_Core_instance ();return reactive_strategy_.open (orb_core->reactor ());
}
The info method simply returns a string that contains a brief description of the actual strategy_factory:
int Reactive_Strategy_Factory::info (char **info_string,
size_t length) const
{
if (*info_string ==
0)
return -1;
ACE_OS::strncpy(*info_string,
"Single-threaded Reactive Strategy\r\n", length);
return ACE_OS::strlen (*info_string);
}
The strategy method simply returns a pointer to the strategy instance
void *Reactive_Strategy_Factory::strategy (void)
{
return reactive_strategy_;
}
Finally, the fini method is called whenever dynamic unlinking
occurs. It is responsible for terminating the object.
Once the methods have been implemented, the macro ACE_FACTORY_DEFINE
must be used:
ACE_FACTORY_DEFINE (ACE, Reactive_Strategy_Factory)
This macro creates the function that is used as the entry point of the
DLL.