HydraExpress™ C++ 2019 |
HydraExpress™ C++ API Reference Guide |
Product Documentation: HydraExpress C++ Documentation Home |
A handle to a named object implementation. A named object is loaded at service startup and is then available to any services in a context. More...
#include <rwsf/core/NamedObject.h>
Public Member Functions | |
NamedObject () | |
NamedObject (const NamedObject &obj) | |
~NamedObject () | |
rwsf::Config | getInitParams () |
void | init () |
NamedObject & | operator= (const NamedObject &obj) |
void | setInitParams (const rwsf::Config &initParams) |
Public Member Functions inherited from rwsf::HandleBase | |
bool | isValid (void) const |
bool | operator!= (const HandleBase &second) const |
bool | operator== (const HandleBase &second) const |
Related Functions | |
(Note that these are not member functions.) | |
template<class T > | |
void | naming_extract (const NamedObject &attr, T *&value) |
template<class T > | |
void | operator<< (NamedObject &attr, const T &value) |
template<class T > | |
void | operator>> (const NamedObject &attr, T &value) |
Additional Inherited Members | |
Protected Member Functions inherited from rwsf::HandleBase | |
HandleBase (void) | |
HandleBase (StaticCtor) | |
HandleBase (BodyBase *body) | |
HandleBase (const HandleBase &second) | |
virtual | ~HandleBase (void) |
BodyBase & | body (void) const |
HandleBase & | operator= (const HandleBase &second) |
Any object may be loaded at program start, where it is available to services as needed, using named object functionality.
Named objects are also used internally; for instance, transports and message handlers are stored in rwsf::NamedObject instances. In addition, almost any object can be stored in a named object in order to make it available to a service at runtime.
All named objects for a project are defined and configured in a generated configuration file (client-objects.xml
for clients and <servicename>_objects.xml
for servers). This file exists for each project and defines a "name" and initialization parameters for each named object, hence the term "named object." Once an object has been defined in the relevant configuration file, it is instantiated at runtime and is available by name throughout the service implementation. A global object configuration file can also be specified and loaded separately.
Creating and loading a named object:
Configure the named object to be either local to a service, global, or both:
Global: Reference a named object configuration in the Agent's main configuration file (rwagent.xml
by default), specifically within its preStartup
and postShutdown
methods sections, so that the referenced named objects are loaded at startup. (No objects are loaded by default.)
Add the method
element to the preStartup
element in rwagent.xml
as shown above. The name
of the method can be anything, but must be unique. The property on the startup method must be named rwsf:objects-file.The
value of this property should be set to the named objects configuration file you wish to load.
At Agent startup, this file is loaded and parsed. All named objects specified in this file are created and stored on the global instance of rwsf::NamingContext.You can retrieve named objects using the lookup() method on rwsf::NamingContext.
To destroy all loaded objects at program exit, define the second method in the postShutdown
section. This ensures that the destructors are run for cleanup tasks; otherwise, the program may exit without destroying the global named objects. This method must appear exactly as in the above example and requires no special properties.
Define the named object in the relevant object configuration file, whether local, global, or both.
rwsf:objects-file
property for of the object's loading method ("${RWSF_CONF}/objects.xml"
in the example above).Here is an example of a new NamedObject definition:
objects
element.naming-obj
element for each object you wish to define. This includes:naming-name
is the name used to look up the object. Required.naming-class
declares the libraryName.createClassName
directive used to load the library and instantiate the object (See the Web Service Development Guide for more information). Required.init-param
element can appear 0-N times, each declaring a new initialization parameter with the given param-name
as its name and the given param-value
as its value. Optional.Add an extern "C"
function to the specified library (libraryName
in this example). The NamingContext, when parsing the above file, tries to call the listed function (createClassName()
in this case). This function must have this signature:
This function must create the object you wish to store and wrap it in NamedObjectImp body. The easiest way to do this is to use a PointerNamedObjectImp templatized on your class type. For example:
This, of course, requires that the object is constructable using the default constructor. If you need to create your object first, use the PointerNamedObjectImp constructor that takes the T*
parameter, i.e. rwsf::PointerNamedObjectImp::PointerNamedObjectImp(T*,bool), and pass either true
or false
to the needsDeletion parameter, depending on how you wish to control the lifetime of the object.
Add a function to your class with the following signature, used for object initialization:
The rwsf::Config object contains all the init-params
specified for the object with the param-name
mapped to the param-value
entries. You can add any initialization parameters required by your object. Failure to include this function will result in errors when compiling or linking your create method due to template errors.
Your object is now available via the global NamingContext from anywhere in your code. Use the naming_extract() global function to access it after the lookup(), like so:
rwsf::NamedObject::NamedObject | ( | ) |
Constructs an invalid handle where isValid() returns false.
rwsf::NamedObject::NamedObject | ( | const NamedObject & | obj | ) |
Copies a NamedObject handle. Does not copy the data.
rwsf::NamedObject::~NamedObject | ( | ) |
Destructor. If this is the last handle pointing to the data, the data is also destroyed.
rwsf::Config rwsf::NamedObject::getInitParams | ( | ) |
Returns the initialization parameters for this named object.
void rwsf::NamedObject::init | ( | ) |
Initializes the object. For PointerNamedObjectImp object types, this calls init() on the dereferenced object (see class description).
NamedObject& rwsf::NamedObject::operator= | ( | const NamedObject & | obj | ) |
Assigns a NamedObject handle. Does not copy the data.
void rwsf::NamedObject::setInitParams | ( | const rwsf::Config & | initParams | ) |
Defines initialization parameters for this named object.
|
related |
Serializes a PointerNamedObjectImp to an argument value of type T*
. The provided NamedObject attr must be a handle to a PointerNamedObjectImp.
rwsf::BadCastException | The body is not a PointerNamedObjectImp. |
|
related |
Serializes the provided value of type T
into a TypedNamedObjectImp and then sets it as the body of the NamedObject handle attr. If attr already pointed to a body, that reference is lost (and deleted if the last reference), but will not be overwritten.
|
related |
Serializes a TypedNamedObjectImp to an argument value of type T
. The provided NamedObject attr must be a handle to a TypedNamedObjectImp.
rwsf::BadCastException | The body is not a TypedNamedObjectImp. |
Copyright © 2019 Rogue Wave Software, Inc. All Rights Reserved. |