org::xmlBlaster::util::Global Class Reference

Author:
Michele Laghi
More...

Inheritance diagram for org::xmlBlaster::util::Global:

Inheritance graph
[legend]
Collaboration diagram for org::xmlBlaster::util::Global:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Global ()
 The default constructor is made private to implement the singleton pattern.
Globaloperator= (Global &)
 ~Global ()
int getArgs ()
 Returns the length of getArgs().
char ** getArgc ()
 Returns the original argv from main().
void fillArgs (ArgsStruct_T &args)
 Fill all properties into a argc/argv representation similar to those delivered by main(argc, argv).
void freeArgs (ArgsStruct_T &args)
 Free the allocated memory.
GlobalRef createInstance (std::string &name, Property::MapType *propertyMapP=((void *) 0), bool holdReferenceCount=false)
 Get or create another instance.
bool containsInstance (std::string &name)
 Check if the Global instance is known.
bool destroyInstance (std::string &instanceName)
 Destroying a named instance.
std::string & getInstanceName ()
 Returns the name as registered with createInstance().
bool wantsHelp ()
 Allows you to query if user wants help.
Globalinitialize (int args=0, char *argv[]=0)
 Intitialize with the given environment settings.
Globalinitialize (org::xmlBlaster::util::Property::MapType &propertyMap)
 Intitialize with the given environment settings.
org::xmlBlaster::util::LogManagergetLogManager ()
 Access the used LogManager.
org::xmlBlaster::util::I_LoggetLog (std::string &logName="org.xmlBlaster")
 If no log is found with that name, one is created.
PropertygetProperty ()
 Returns the property object associated to this global.
std::string getLocalIP ()
std::string getBootstrapHostname ()
 Returns the bootstrap host name.
std::string getCbHostname ()
org::xmlBlaster::client::protocol::CbServerPluginManagergetCbServerPluginManager ()
org::xmlBlaster::util::dispatch::DispatchManagergetDispatchManager ()
TimeoutgetPingTimer ()
void setSessionName (org::xmlBlaster::util::SessionNameRef sessionName)
 Set the clients session name, changes after login.
org::xmlBlaster::util::SessionNameRef getSessionName ()
 Get the clients session name, changes after login.
std::string getId ()
 The absolute session name.
std::string getStrippedId ()
 Same as getId() but all 'special characters' are stripped so you can use it for file names.
std::string getImmutableId ()
 The relative session name.
std::string getStrippedImmutableId ()
 Same as getImmutableId() but all 'special characters' are stripped so you can use it for queue names.
std::string getStrippedString (std::string &text)
 Utility method to strip any std::string, all characters which prevent to be used for e.g.
void setId (std::string &id)
 Set after successful login.
void setImmutableId (std::string &id)
 Set by XmlBlasterAccess/ConnectionHandler to relative session name.
void resetInstanceId ()
 Reset the cached instance id.
std::string getInstanceId ()
 Unique id of the client, changes on each restart.

Static Public Member Functions

static GlobalgetInstance (std::string name="default")
 This method delivers the singleton instance or the named instance.
static std::string & getVersion ()
 The version field is automatically set by ant on compilation (see filter token in build.xml).
static std::string & getRevisionNumber ()
 The subversion revision number field is automatically set by ant on compilation (see filter token in build.xml).
static std::string & getReleaseId ()
 String containing getVersion() and getRevisionNumber().
static std::string & getBuildTimestamp ()
 The timestamp field is automatically set by ant on compilation (see filter token in build.xml).
static std::string & getCompiler ()
 The C++ compiler used.
static std::string & getDefaultProtocol ()
 Is overwritten be environment, for example "-protocol IOR".
static std::string usage ()
 Command line usage.
static std::string & getBoolAsString (bool val)
 Returns the specified value as a std::string.

Friends

class ManagedObject
class Object_Lifetime_Manager
GlobalgetInstance (std::string &instanceName)

Detailed Description

Author:
Michele Laghi

Definition at line 62 of file Global.h.


Constructor & Destructor Documentation

org::xmlBlaster::util::Global::Global (  ) 

The default constructor is made private to implement the singleton pattern.

Definition at line 93 of file Global.cpp.

org::xmlBlaster::util::Global::~Global (  ) 

Definition at line 132 of file Global.cpp.

References destroyInstance().


Member Function Documentation

Global & org::xmlBlaster::util::Global::operator= ( Global  ) 

Definition at line 125 of file Global.cpp.

int org::xmlBlaster::util::Global::getArgs (  ) 

Returns the length of getArgs().

Definition at line 499 of file Global.cpp.

Referenced by org::xmlBlaster::client::protocol::corba::CorbaConnection::CorbaConnection(), and org::xmlBlaster::test::TestEmbeddedServer::TestEmbeddedServer().

char ** org::xmlBlaster::util::Global::getArgc (  ) 

Returns the original argv from main().

NOTE: This contains NOT all other properties, you should in such a case use fillArgs(ArgsStruct_T)

Definition at line 504 of file Global.cpp.

Referenced by org::xmlBlaster::client::protocol::corba::CorbaConnection::CorbaConnection(), and org::xmlBlaster::test::TestEmbeddedServer::TestEmbeddedServer().

void org::xmlBlaster::util::Global::fillArgs ( ArgsStruct_T args  ) 

Fill all properties into a argc/argv representation similar to those delivered by main(argc, argv).

Example:

  ArgsStruct_T args;
  glob.fillArgs(args);
  // Do something ...
  glob.freeArgs(args);
 
  argv[0] = myProg (the executable name) 
  argv[1] = -name
  argv[2] = joe
 
NOTE: You have to take care on the memory allocated into args and free it with a call to freeArgs()
Parameters:
args A struct ArgsStruct instance which is filled with all properties

Definition at line 323 of file Global.cpp.

References org::xmlBlaster::util::ArgsStruct::argc, org::xmlBlaster::util::ArgsStruct::argv, and org::xmlBlaster::util::Property::getPropertyMap().

void org::xmlBlaster::util::Global::freeArgs ( ArgsStruct_T args  ) 

Free the allocated memory.

See also:
fillArgs(ArgsStruct_T &args)

Definition at line 348 of file Global.cpp.

References org::xmlBlaster::util::ArgsStruct::argc, and org::xmlBlaster::util::ArgsStruct::argv.

static Global& org::xmlBlaster::util::Global::getInstance ( std::string  name = "default"  )  [static]

This method delivers the singleton instance or the named instance.

Parameters:
name If specified the named global instance, "default" is the default setting and will return the first singleton instance
Returns:
As default the same first Global instance

GlobalRef org::xmlBlaster::util::Global::createInstance ( std::string &  name,
Property::MapType propertyMapP = ((void *) 0),
bool  holdReferenceCount = false 
)

Get or create another instance.

Parameters:
name The unique name of the Global instance, "default" can't be used, it is reserved for the first singleton instance
propertyMapP The optional configuration
holdReferenceCount If true we increment the reference counter on this instance, only an explicit call to destroyInstance() will free the memory. If false (which is default) only the caller code increments the reference counter, on last instance the Global is deleted (the memory is freed) automatically, the Global destructor automatically calls destroyInstance() in this case.
Returns:
The named Global instance, if it does not exist it is created
Exceptions:
XmlBlasterException On error

Referenced by Leak::checkConnection(), Leak::checkConnection2(), Leak::checkConnection3(), Leak::checkGlobal(), and Leak::checkGlobal2().

bool org::xmlBlaster::util::Global::containsInstance ( std::string &  name  ) 

Check if the Global instance is known.

Parameters:
name The unique name of the Global instance, "default" can't be used.
Returns:
true If the Global instance is known

Definition at line 249 of file Global.cpp.

bool org::xmlBlaster::util::Global::destroyInstance ( std::string &  instanceName  ) 

Destroying a named instance.

Parameters:
name The unique name of the Global instance, the "default" instance can't be destroyed with this method
Returns:
true if one instance was removed
Exceptions:
XmlBlasterException On wrong arguments

Definition at line 258 of file Global.cpp.

References org::xmlBlaster::util::USER_ILLEGALARGUMENT.

Referenced by Leak::checkGlobal(), Leak::checkGlobal2(), and ~Global().

string & org::xmlBlaster::util::Global::getInstanceName (  ) 

Returns the name as registered with createInstance().

Returns:
"default" for the first singleton instance

Definition at line 241 of file Global.cpp.

bool org::xmlBlaster::util::Global::wantsHelp (  ) 

Allows you to query if user wants help.

Returns:
true If '-help' or '-?' was passed to us

Definition at line 356 of file Global.cpp.

References org::xmlBlaster::util::Property::getBoolProperty(), and getProperty().

Referenced by main().

string & org::xmlBlaster::util::Global::getVersion (  )  [static]

The version field is automatically set by ant on compilation (see filter token in build.xml).

Returns:
The version std::string e.g. "0.842" or "@version@" if not set

Definition at line 364 of file Global.cpp.

Referenced by org::xmlBlaster::util::queue::SQLiteQueuePlugin::convertFromQueueException(), getReleaseId(), getRevisionNumber(), org::xmlBlaster::test::TestSub::setUp(), org::xmlBlaster::test::TestLeaveServer::setUp(), org::xmlBlaster::test::TestGet::setUp(), and org::xmlBlaster::test::TestCommand::setUp().

string & org::xmlBlaster::util::Global::getRevisionNumber (  )  [static]

The subversion revision number field is automatically set by ant on compilation (see filter token in build.xml).

Returns:
The revision number std::string e.g. "12708M" or getVersion() if not set

Definition at line 370 of file Global.cpp.

References getVersion().

Referenced by getReleaseId().

string & org::xmlBlaster::util::Global::getReleaseId (  )  [static]

String containing getVersion() and getRevisionNumber().

Returns:
For example "0.91 #12107M"

Definition at line 378 of file Global.cpp.

References getRevisionNumber(), and getVersion().

Referenced by main(), and usage().

string & org::xmlBlaster::util::Global::getBuildTimestamp (  )  [static]

The timestamp field is automatically set by ant on compilation (see filter token in build.xml).

Returns:
The compilation timestamp of format "MM/dd/yyyy hh:mm aa" or "@build.timestamp@" if not set

Definition at line 386 of file Global.cpp.

Referenced by org::xmlBlaster::util::queue::SQLiteQueuePlugin::convertFromQueueException(), org::xmlBlaster::test::TestSub::setUp(), org::xmlBlaster::test::TestLeaveServer::setUp(), org::xmlBlaster::test::TestGet::setUp(), org::xmlBlaster::test::TestCommand::setUp(), and usage().

string & org::xmlBlaster::util::Global::getCompiler (  )  [static]

The C++ compiler used.

Returns:
For example something like "Intel icc" for Intels C++ compiler

Definition at line 392 of file Global.cpp.

Referenced by usage().

string & org::xmlBlaster::util::Global::getDefaultProtocol (  )  [static]

Is overwritten be environment, for example "-protocol IOR".

Definition at line 402 of file Global.cpp.

References org::xmlBlaster::util::Constants::IOR, and org::xmlBlaster::util::Constants::SOCKET.

Referenced by org::xmlBlaster::util::qos::ConnectQosData::getServerRef(), org::xmlBlaster::client::XmlBlasterAccess::usage(), and org::xmlBlaster::util::dispatch::ConnectionsHandler::~ConnectionsHandler().

string org::xmlBlaster::util::Global::usage (  )  [static]

Command line usage.

Definition at line 423 of file Global.cpp.

References getBuildTimestamp(), getCompiler(), getInstance, getLog(), getReleaseId(), org::xmlBlaster::util::I_Log::usage(), org::xmlBlaster::util::qos::storage::CbQueueProperty::usage(), org::xmlBlaster::util::qos::storage::ClientQueueProperty::usage(), org::xmlBlaster::util::qos::SessionQosData::usage(), org::xmlBlaster::util::parser::Sax2Parser::usage(), org::xmlBlaster::client::protocol::corba::CorbaDriver::usage(), and org::xmlBlaster::client::protocol::socket::SocketDriver::usage().

Global & org::xmlBlaster::util::Global::initialize ( int  args = 0,
char *  argv[] = 0 
)

Intitialize with the given environment settings.

Parameters:
argv The command line arguments, for example "-protocol SOCKET"

Definition at line 291 of file Global.cpp.

References getLog(), org::xmlBlaster::util::Property::loadPropertyFile(), and org::xmlBlaster::util::I_Log::warn().

Referenced by main(), and org::xmlBlaster::test::TestDoubleGlobal::setUp().

Global & org::xmlBlaster::util::Global::initialize ( org::xmlBlaster::util::Property::MapType propertyMap  ) 

Intitialize with the given environment settings.

Parameters:
propertyMap A std::map which contains key and values pairs, for example key="protocol" and value="SOCKET"

Definition at line 307 of file Global.cpp.

References getLog(), org::xmlBlaster::util::Property::loadPropertyFile(), and org::xmlBlaster::util::I_Log::warn().

LogManager & org::xmlBlaster::util::Global::getLogManager (  ) 

Access the used LogManager.

Definition at line 474 of file Global.cpp.

org::xmlBlaster::util::I_Log& org::xmlBlaster::util::Global::getLog ( std::string &  logName = "org.xmlBlaster"  ) 

If no log is found with that name, one is created.

You should have initialized Global with your properties to before your first call to getLog(), for example:

 std::map<std::string, std::string, std::less<std::string> > propertyMap;
 ... // insert configuration key / values
 Global& myGlobal = Global::getInstance().initialize(propertyMap);
 I_Log& log = myGlobal.getLog("BlasterClient"));
 ...
 

Referenced by org::xmlBlaster::client::protocol::socket::SocketDriverFactory::getDriverInstance(), org::xmlBlaster::client::protocol::corba::CorbaDriverFactory::getDriverInstance(), getPingTimer(), initialize(), org::xmlBlaster::client::protocol::socket::SocketDriverFactory::killDriverInstance(), org::xmlBlaster::client::protocol::corba::CorbaDriverFactory::killDriverInstance(), main(), org::xmlBlaster::util::EmbeddedServerRunner::run(), and usage().

Property & org::xmlBlaster::util::Global::getProperty (  ) 

Returns the property object associated to this global.

Definition at line 414 of file Global.cpp.

References org::xmlBlaster::util::USER_CONFIGURATION.

Referenced by org::xmlBlaster::util::qos::AccessFilterQos::AccessFilterQos(), org::xmlBlaster::client::XmlBlasterAccess::connect(), MultiConnectDemo::execute(), HelloWorld2::execute(), getBootstrapHostname(), getCbHostname(), org::xmlBlaster::util::parser::ParserFactory::getLocale(), org::xmlBlaster::util::qos::HistoryQos::HistoryQos(), org::xmlBlaster::client::protocol::corba::CorbaConnection::initAuthenticationService(), SubscribeDemo::initEnvironment(), PublishDemo::initEnvironment(), Leak::Leak(), main(), org::xmlBlaster::util::parser::Sax2Parser::Sax2Parser(), org::xmlBlaster::test::TestDoubleGlobal::sessionQos(), org::xmlBlaster::test::TestDoubleGlobal::setUp(), org::xmlBlaster::util::queue::SQLiteQueuePlugin::SQLiteQueuePlugin(), org::xmlBlaster::test::TestEmbeddedServer::TestEmbeddedServer(), org::xmlBlaster::test::TestThread::testRecursiveThread(), org::xmlBlaster::test::TestConnectQos::testSessionQos(), org::xmlBlaster::test::TestSuite::TestSuite(), org::xmlBlaster::util::qos::TopicProperty::TopicProperty(), org::xmlBlaster::client::XmlBlasterAccess::usage(), and wantsHelp().

string org::xmlBlaster::util::Global::getLocalIP (  ) 

Definition at line 509 of file Global.cpp.

Referenced by getBootstrapHostname(), and getCbHostname().

string org::xmlBlaster::util::Global::getBootstrapHostname (  ) 

Returns the bootstrap host name.

Definition at line 515 of file Global.cpp.

References getLocalIP(), getProperty(), and org::xmlBlaster::util::Property::getStringProperty().

Referenced by org::xmlBlaster::util::qos::address::AddressBase::getHostname().

string org::xmlBlaster::util::Global::getCbHostname (  ) 

Definition at line 525 of file Global.cpp.

References getLocalIP(), getProperty(), and org::xmlBlaster::util::Property::getStringProperty().

CbServerPluginManager & org::xmlBlaster::util::Global::getCbServerPluginManager (  ) 

Definition at line 531 of file Global.cpp.

Referenced by org::xmlBlaster::client::XmlBlasterAccess::disconnect(), and org::xmlBlaster::client::XmlBlasterAccess::leaveServer().

DispatchManager & org::xmlBlaster::util::Global::getDispatchManager (  ) 

Definition at line 539 of file Global.cpp.

Referenced by org::xmlBlaster::util::dispatch::ConnectionsHandler::connect(), org::xmlBlaster::client::XmlBlasterAccess::connect(), and org::xmlBlaster::util::dispatch::ConnectionsHandler::~ConnectionsHandler().

Timeout & org::xmlBlaster::util::Global::getPingTimer (  ) 

Definition at line 547 of file Global.cpp.

References getLog(), and org::xmlBlaster::util::I_Log::trace().

Referenced by org::xmlBlaster::util::dispatch::ConnectionsHandler::startPinger(), and org::xmlBlaster::util::dispatch::ConnectionsHandler::~ConnectionsHandler().

string & org::xmlBlaster::util::Global::getBoolAsString ( bool  val  )  [static]

Returns the specified value as a std::string.

Deprecated:
Please use 'lexical_cast<string>(bool)' instead

Definition at line 559 of file Global.cpp.

Referenced by org::xmlBlaster::client::XmlBlasterAccess::disconnect(), and org::xmlBlaster::util::qos::ConnectQosData::getBoolAsString().

void org::xmlBlaster::util::Global::setSessionName ( org::xmlBlaster::util::SessionNameRef  sessionName  ) 

Set the clients session name, changes after login.

Definition at line 566 of file Global.cpp.

Referenced by org::xmlBlaster::util::dispatch::ConnectionsHandler::connect().

SessionNameRef org::xmlBlaster::util::Global::getSessionName (  ) 

Get the clients session name, changes after login.

Definition at line 571 of file Global.cpp.

Referenced by org::xmlBlaster::util::dispatch::ConnectionsHandler::queueSubscribe().

string org::xmlBlaster::util::Global::getId (  ) 

The absolute session name.

Before connection it is temporay the relative session name and changed to the absolute session name after connection (when we know the cluster id)

Returns:
For example "/node/heron/client/joe/2"

Definition at line 583 of file Global.cpp.

Referenced by getInstanceId(), org::xmlBlaster::client::protocol::socket::SocketDriverFactory::killDriverInstance(), and org::xmlBlaster::test::TestCommand::testSendAdministrativeCommand().

string org::xmlBlaster::util::Global::getStrippedId (  ) 

Same as getId() but all 'special characters' are stripped so you can use it for file names.

Returns:
""

Definition at line 593 of file Global.cpp.

References getStrippedString().

Referenced by org::xmlBlaster::client::protocol::corba::CorbaConnection::initAuthenticationService().

string org::xmlBlaster::util::Global::getImmutableId (  ) 

The relative session name.

We can't use the absolute session name (with cluster node informations) as this is known after connect(), but we need to name queues before connect() already -> The Id must be immutable!

Returns:
For example "client/joe/2"

Definition at line 588 of file Global.cpp.

string org::xmlBlaster::util::Global::getStrippedImmutableId (  ) 

Same as getImmutableId() but all 'special characters' are stripped so you can use it for queue names.

Returns:
""

Definition at line 598 of file Global.cpp.

References getStrippedString().

Referenced by org::xmlBlaster::util::queue::SQLiteQueuePlugin::SQLiteQueuePlugin().

std::string org::xmlBlaster::util::Global::getStrippedString ( std::string &  text  ) 

Utility method to strip any std::string, all characters which prevent to be used for e.g.

file names are replaced.

Parameters:
text e.g. "http://www.xmlBlaster.org:/home\\x"
Returns:
e.g. "http_www_xmlBlaster_org_homex"

Referenced by getStrippedId(), and getStrippedImmutableId().

void org::xmlBlaster::util::Global::setId ( std::string &  id  ) 

Set after successful login.

Set by XmlBlasterAccess/ConnectionHandler to absolute session name after successful connection (before it is temporary the relative name)

Parameters:
a unique id, for example "/node/heron/client/joe/2"

Referenced by org::xmlBlaster::util::dispatch::ConnectionsHandler::connect(), and org::xmlBlaster::client::XmlBlasterAccess::connect().

void org::xmlBlaster::util::Global::setImmutableId ( std::string &  id  ) 

Set by XmlBlasterAccess/ConnectionHandler to relative session name.

Parameters:
a unique id, for example "client/joe/2"

Referenced by org::xmlBlaster::util::dispatch::ConnectionsHandler::connect().

void org::xmlBlaster::util::Global::resetInstanceId (  ) 

Reset the cached instance id.

Definition at line 626 of file Global.cpp.

std::string org::xmlBlaster::util::Global::getInstanceId (  ) 

Unique id of the client, changes on each restart.

If 'client/joe' is restarted, the instanceId changes.

Returns:
id + timestamp, '/client/joe/instanceId/33470080380'

Definition at line 631 of file Global.cpp.

References getId(), org::xmlBlaster::util::TimestampFactory::getInstance, org::xmlBlaster::util::TimestampFactory::getTimestamp(), and org::xmlBlaster::util::lexical_cast().

Referenced by org::xmlBlaster::client::XmlBlasterAccess::connect().


Friends And Related Function Documentation

friend class ManagedObject [friend]

Definition at line 67 of file Global.h.

friend class Object_Lifetime_Manager [friend]

Definition at line 68 of file Global.h.

Global& getInstance ( std::string &  instanceName  )  [friend]

Referenced by usage(), and org::xmlBlaster::client::XmlBlasterAccess::usage().


The documentation for this class was generated from the following files: