summaryrefslogtreecommitdiff
path: root/cpp/src/IceBox/ServiceManagerI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/IceBox/ServiceManagerI.cpp')
-rw-r--r--cpp/src/IceBox/ServiceManagerI.cpp620
1 files changed, 310 insertions, 310 deletions
diff --git a/cpp/src/IceBox/ServiceManagerI.cpp b/cpp/src/IceBox/ServiceManagerI.cpp
index c3097d5b99e..047be74601b 100644
--- a/cpp/src/IceBox/ServiceManagerI.cpp
+++ b/cpp/src/IceBox/ServiceManagerI.cpp
@@ -53,33 +53,33 @@ IceBox::ServiceManagerI::startService(const string& name, const Current&)
vector<ServiceInfo>::iterator p;
for(p = _services.begin(); p != _services.end(); ++p)
{
- ServiceInfo& info = *p;
- if(info.name == name)
- {
- if(info.active)
- {
- throw AlreadyStartedException();
- }
-
- try
- {
- info.service->start(name, info.communicator == 0 ? _communicator : info.communicator, info.args);
- info.active = true;
- }
- catch(const Ice::Exception& ex)
- {
+ ServiceInfo& info = *p;
+ if(info.name == name)
+ {
+ if(info.active)
+ {
+ throw AlreadyStartedException();
+ }
+
+ try
+ {
+ info.service->start(name, info.communicator == 0 ? _communicator : info.communicator, info.args);
+ info.active = true;
+ }
+ catch(const Ice::Exception& ex)
+ {
Warning out(_logger);
- out << "ServiceManager: exception in start for service " << info.name << ":\n";
- out << ex;
- }
- catch(...)
- {
+ out << "ServiceManager: exception in start for service " << info.name << ":\n";
+ out << ex;
+ }
+ catch(...)
+ {
Warning out(_logger);
- out << "ServiceManager: unknown exception in start for service " << info.name;
- }
+ out << "ServiceManager: unknown exception in start for service " << info.name;
+ }
- return;
- }
+ return;
+ }
}
throw NoSuchServiceException();
@@ -97,33 +97,33 @@ IceBox::ServiceManagerI::stopService(const string& name, const Current&)
vector<ServiceInfo>::iterator p;
for(p = _services.begin(); p != _services.end(); ++p)
{
- ServiceInfo& info = *p;
- if(info.name == name)
- {
- if(!info.active)
- {
- throw AlreadyStoppedException();
- }
-
- try
- {
- info.service->stop();
- info.active = false;
- }
- catch(const Ice::Exception& ex)
- {
+ ServiceInfo& info = *p;
+ if(info.name == name)
+ {
+ if(!info.active)
+ {
+ throw AlreadyStoppedException();
+ }
+
+ try
+ {
+ info.service->stop();
+ info.active = false;
+ }
+ catch(const Ice::Exception& ex)
+ {
Warning out(_logger);
- out << "ServiceManager: exception in stop for service " << info.name << ":\n";
- out << ex;
- }
- catch(...)
- {
+ out << "ServiceManager: exception in stop for service " << info.name << ":\n";
+ out << ex;
+ }
+ catch(...)
+ {
Warning out(_logger);
- out << "ServiceManager: unknown exception in stop for service " << info.name;
- }
+ out << "ServiceManager: unknown exception in stop for service " << info.name;
+ }
- return;
- }
+ return;
+ }
}
throw NoSuchServiceException();
@@ -149,10 +149,10 @@ IceBox::ServiceManagerI::start()
//
ObjectAdapterPtr adapter = _communicator->createObjectAdapter("IceBox.ServiceManager");
- PropertiesPtr properties = _communicator->getProperties();
+ PropertiesPtr properties = _communicator->getProperties();
Identity identity;
- identity.category = properties->getPropertyWithDefault("IceBox.InstanceName", "IceBox");
- identity.name = "ServiceManager";
+ identity.category = properties->getPropertyWithDefault("IceBox.InstanceName", "IceBox");
+ identity.name = "ServiceManager";
adapter->add(obj, identity);
//
@@ -191,7 +191,7 @@ IceBox::ServiceManagerI::start()
//
const string prefix = "IceBox.Service.";
PropertyDict services = properties->getPropertiesForPrefix(prefix);
- PropertyDict::iterator p;
+ PropertyDict::iterator p;
for(StringSeq::const_iterator q = loadOrder.begin(); q != loadOrder.end(); ++q)
{
p = services.find(prefix + *q);
@@ -204,8 +204,8 @@ IceBox::ServiceManagerI::start()
load(*q, p->second);
services.erase(p);
}
- for(p = services.begin(); p != services.end(); ++p)
- {
+ for(p = services.begin(); p != services.end(); ++p)
+ {
string name = p->first.substr(prefix.size());
load(name, p->second);
}
@@ -228,16 +228,16 @@ IceBox::ServiceManagerI::start()
cout << bundleName << " ready" << endl;
}
- try
- {
- adapter->activate();
- }
- catch(const ObjectAdapterDeactivatedException&)
- {
- //
- // Expected if the communicator has been shutdown.
- //
- }
+ try
+ {
+ adapter->activate();
+ }
+ catch(const ObjectAdapterDeactivatedException&)
+ {
+ //
+ // Expected if the communicator has been shutdown.
+ //
+ }
}
catch(const FailureException& ex)
{
@@ -279,16 +279,16 @@ IceBox::ServiceManagerI::load(const string& name, const string& value)
else
{
entryPoint = value.substr(0, pos);
- try
- {
- args = IceUtil::Options::split(value.substr(pos + 1));
- }
- catch(const IceUtil::BadOptException& ex)
- {
- FailureException e(__FILE__, __LINE__);
- e.reason = "ServiceManager: invalid arguments for service `" + name + "':\n" + ex.reason;
- throw e;
- }
+ try
+ {
+ args = IceUtil::Options::split(value.substr(pos + 1));
+ }
+ catch(const IceUtil::BadOptException& ex)
+ {
+ FailureException e(__FILE__, __LINE__);
+ e.reason = "ServiceManager: invalid arguments for service `" + name + "':\n" + ex.reason;
+ throw e;
+ }
}
start(name, entryPoint, args);
}
@@ -363,148 +363,148 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint,
//
try
{
- //
- // If Ice.UseSharedCommunicator.<name> is not defined, create
- // a communicator for the service. The communicator inherits
- // from the shared communicator properties. If it's defined
- // add the service properties to the shared commnunicator
- // property set.
- //
- PropertiesPtr properties = _communicator->getProperties();
-
-
- if(properties->getPropertyAsInt("IceBox.UseSharedCommunicator." + service) > 0)
- {
- PropertiesPtr serviceProperties = createProperties(info.args, properties);
-
- //
- // Erase properties in 'properties'
- //
- PropertyDict allProps = properties->getPropertiesForPrefix("");
- for(PropertyDict::iterator p = allProps.begin(); p != allProps.end(); ++p)
- {
- if(serviceProperties->getProperty(p->first) == "")
- {
- properties->setProperty(p->first, "");
- }
- }
-
- //
- // Put all serviceProperties into 'properties'
- //
- properties->parseCommandLineOptions("", serviceProperties->getCommandLineOptions());
-
- //
- // Parse <service>.* command line options
- // (the Ice command line options were parse by the createProperties above)
- //
- info.args = properties->parseCommandLineOptions(service, info.args);
- }
- else
- {
- string name = properties->getProperty("Ice.ProgramName");
- PropertiesPtr serviceProperties;
- if(properties->getPropertyAsInt("IceBox.InheritContainerProperties") > 0)
- {
- serviceProperties = createProperties(info.args, properties);
- }
- else
- {
- serviceProperties = createProperties(info.args);
- }
-
- if(name == serviceProperties->getProperty("Ice.ProgramName"))
- {
- //
- // If the service did not set its own program-name, and
- // the icebox program-name != service, append the service name to the
- // program name.
- //
- if(name != service)
- {
- name = name.empty() ? service : name + "-" + service;
- }
- serviceProperties->setProperty("Ice.ProgramName", name);
- }
-
- //
- // Parse <service>.* command line options
- // (the Ice command line options were parsed by the createProperties above)
- //
- info.args = serviceProperties->parseCommandLineOptions(service, info.args);
-
- //
- // Remaining command line options are passed to the
- // communicator with argc/argv. This is necessary for Ice
- // plugin properties (e.g.: IceSSL).
- //
- int argc = static_cast<int>(info.args.size());
- char** argv = new char*[argc + 1];
- int i = 0;
- for(Ice::StringSeq::const_iterator p = info.args.begin(); p != info.args.end(); ++p, ++i)
- {
- argv[i] = strdup(p->c_str());
- }
- argv[argc] = 0;
-
- InitializationData initData;
- initData.properties = serviceProperties;
- info.communicator = initialize(argc, argv, initData);
-
- for(i = 0; i < argc + 1; ++i)
- {
- free(argv[i]);
- }
- delete[] argv;
- }
-
- CommunicatorPtr communicator = info.communicator ? info.communicator : _communicator;
-
- //
- // Start the service.
- //
- try
- {
- info.service->start(service, communicator, info.args);
- info.active = true;
- }
- catch(...)
- {
- if(info.communicator)
- {
- try
- {
- info.communicator->shutdown();
- info.communicator->waitForShutdown();
- }
- catch(const Ice::CommunicatorDestroyedException&)
- {
- //
- // Ignore, the service might have already destroyed
- // the communicator for its own reasons.
- //
- }
- catch(const Ice::Exception& ex)
- {
- Warning out(_logger);
- out << "ServiceManager: exception in shutting down communicator for service " << service << ":\n";
- out << ex;
- }
-
- try
- {
- info.communicator->destroy();
- info.communicator = 0;
- }
- catch(const Exception& ex)
- {
- Warning out(_logger);
- out << "ServiceManager: exception in shutting down communicator for service " << service << ":\n";
- out << ex;
- }
- }
- throw;
- }
+ //
+ // If Ice.UseSharedCommunicator.<name> is not defined, create
+ // a communicator for the service. The communicator inherits
+ // from the shared communicator properties. If it's defined
+ // add the service properties to the shared commnunicator
+ // property set.
+ //
+ PropertiesPtr properties = _communicator->getProperties();
+
+
+ if(properties->getPropertyAsInt("IceBox.UseSharedCommunicator." + service) > 0)
+ {
+ PropertiesPtr serviceProperties = createProperties(info.args, properties);
+
+ //
+ // Erase properties in 'properties'
+ //
+ PropertyDict allProps = properties->getPropertiesForPrefix("");
+ for(PropertyDict::iterator p = allProps.begin(); p != allProps.end(); ++p)
+ {
+ if(serviceProperties->getProperty(p->first) == "")
+ {
+ properties->setProperty(p->first, "");
+ }
+ }
+
+ //
+ // Put all serviceProperties into 'properties'
+ //
+ properties->parseCommandLineOptions("", serviceProperties->getCommandLineOptions());
+
+ //
+ // Parse <service>.* command line options
+ // (the Ice command line options were parse by the createProperties above)
+ //
+ info.args = properties->parseCommandLineOptions(service, info.args);
+ }
+ else
+ {
+ string name = properties->getProperty("Ice.ProgramName");
+ PropertiesPtr serviceProperties;
+ if(properties->getPropertyAsInt("IceBox.InheritContainerProperties") > 0)
+ {
+ serviceProperties = createProperties(info.args, properties);
+ }
+ else
+ {
+ serviceProperties = createProperties(info.args);
+ }
+
+ if(name == serviceProperties->getProperty("Ice.ProgramName"))
+ {
+ //
+ // If the service did not set its own program-name, and
+ // the icebox program-name != service, append the service name to the
+ // program name.
+ //
+ if(name != service)
+ {
+ name = name.empty() ? service : name + "-" + service;
+ }
+ serviceProperties->setProperty("Ice.ProgramName", name);
+ }
+
+ //
+ // Parse <service>.* command line options
+ // (the Ice command line options were parsed by the createProperties above)
+ //
+ info.args = serviceProperties->parseCommandLineOptions(service, info.args);
+
+ //
+ // Remaining command line options are passed to the
+ // communicator with argc/argv. This is necessary for Ice
+ // plugin properties (e.g.: IceSSL).
+ //
+ int argc = static_cast<int>(info.args.size());
+ char** argv = new char*[argc + 1];
+ int i = 0;
+ for(Ice::StringSeq::const_iterator p = info.args.begin(); p != info.args.end(); ++p, ++i)
+ {
+ argv[i] = strdup(p->c_str());
+ }
+ argv[argc] = 0;
+
+ InitializationData initData;
+ initData.properties = serviceProperties;
+ info.communicator = initialize(argc, argv, initData);
+
+ for(i = 0; i < argc + 1; ++i)
+ {
+ free(argv[i]);
+ }
+ delete[] argv;
+ }
+
+ CommunicatorPtr communicator = info.communicator ? info.communicator : _communicator;
+
+ //
+ // Start the service.
+ //
+ try
+ {
+ info.service->start(service, communicator, info.args);
+ info.active = true;
+ }
+ catch(...)
+ {
+ if(info.communicator)
+ {
+ try
+ {
+ info.communicator->shutdown();
+ info.communicator->waitForShutdown();
+ }
+ catch(const Ice::CommunicatorDestroyedException&)
+ {
+ //
+ // Ignore, the service might have already destroyed
+ // the communicator for its own reasons.
+ //
+ }
+ catch(const Ice::Exception& ex)
+ {
+ Warning out(_logger);
+ out << "ServiceManager: exception in shutting down communicator for service " << service << ":\n";
+ out << ex;
+ }
+
+ try
+ {
+ info.communicator->destroy();
+ info.communicator = 0;
+ }
+ catch(const Exception& ex)
+ {
+ Warning out(_logger);
+ out << "ServiceManager: exception in shutting down communicator for service " << service << ":\n";
+ out << ex;
+ }
+ }
+ throw;
+ }
info.library = library;
_services.push_back(info);
@@ -515,12 +515,12 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint,
}
catch(const Exception& ex)
{
- ostringstream s;
- s << "ServiceManager: exception while starting service " << service << ":\n";
- s << ex;
+ ostringstream s;
+ s << "ServiceManager: exception while starting service " << service << ":\n";
+ s << ex;
- FailureException e(__FILE__, __LINE__);
- e.reason = s.str();
+ FailureException e(__FILE__, __LINE__);
+ e.reason = s.str();
throw e;
}
}
@@ -541,103 +541,103 @@ IceBox::ServiceManagerI::stopAll()
//
for(p = _services.rbegin(); p != _services.rend(); ++p)
{
- ServiceInfo& info = *p;
- try
- {
- info.service->stop();
- info.active = false;
- }
- catch(const Ice::Exception& ex)
- {
+ ServiceInfo& info = *p;
+ try
+ {
+ info.service->stop();
+ info.active = false;
+ }
+ catch(const Ice::Exception& ex)
+ {
Warning out(_logger);
- out << "ServiceManager: exception in stop for service " << info.name << ":\n";
- out << ex;
- }
- catch(...)
- {
+ out << "ServiceManager: exception in stop for service " << info.name << ":\n";
+ out << ex;
+ }
+ catch(...)
+ {
Warning out(_logger);
- out << "ServiceManager: unknown exception in stop for service " << info.name;
- }
+ out << "ServiceManager: unknown exception in stop for service " << info.name;
+ }
}
for(p = _services.rbegin(); p != _services.rend(); ++p)
{
- ServiceInfo& info = *p;
-
- if(info.communicator)
- {
- try
- {
- info.communicator->shutdown();
- info.communicator->waitForShutdown();
- }
- catch(const Ice::CommunicatorDestroyedException&)
- {
- //
- // Ignore, the service might have already destroyed
- // the communicator for its own reasons.
- //
- }
- catch(const Ice::Exception& ex)
- {
- Warning out(_logger);
- out << "ServiceManager: exception in stop for service " << info.name << ":\n";
- out << ex;
- }
- }
-
- //
- // Release the service, the service communicator and then the library. The order is important,
- // the service must be released before destroying the communicator so that the communicator
- // leak detector doesn't report potential leaks, and the communicator must be destroyed before
- // the library is released since the library will destroy its global state.
- //
- try
- {
- info.service = 0;
- }
- catch(const Exception& ex)
- {
- Warning out(_logger);
- out << "ServiceManager: exception in stop for service " << info.name << ":\n";
- out << ex;
- }
- catch(...)
- {
+ ServiceInfo& info = *p;
+
+ if(info.communicator)
+ {
+ try
+ {
+ info.communicator->shutdown();
+ info.communicator->waitForShutdown();
+ }
+ catch(const Ice::CommunicatorDestroyedException&)
+ {
+ //
+ // Ignore, the service might have already destroyed
+ // the communicator for its own reasons.
+ //
+ }
+ catch(const Ice::Exception& ex)
+ {
+ Warning out(_logger);
+ out << "ServiceManager: exception in stop for service " << info.name << ":\n";
+ out << ex;
+ }
+ }
+
+ //
+ // Release the service, the service communicator and then the library. The order is important,
+ // the service must be released before destroying the communicator so that the communicator
+ // leak detector doesn't report potential leaks, and the communicator must be destroyed before
+ // the library is released since the library will destroy its global state.
+ //
+ try
+ {
+ info.service = 0;
+ }
+ catch(const Exception& ex)
+ {
Warning out(_logger);
- out << "ServiceManager: unknown exception in stop for service " << info.name;
- }
-
- if(info.communicator)
- {
- try
- {
- info.communicator->destroy();
- info.communicator = 0;
- }
- catch(const Exception& ex)
- {
- Warning out(_logger);
- out << "ServiceManager: exception in stop for service " << info.name << ":\n";
- out << ex;
- }
- }
-
- try
- {
- info.library = 0;
- }
- catch(const Exception& ex)
- {
- Warning out(_logger);
- out << "ServiceManager: exception in stop for service " << info.name << ":\n";
- out << ex;
- }
- catch(...)
- {
+ out << "ServiceManager: exception in stop for service " << info.name << ":\n";
+ out << ex;
+ }
+ catch(...)
+ {
Warning out(_logger);
- out << "ServiceManager: unknown exception in stop for service " << info.name;
- }
+ out << "ServiceManager: unknown exception in stop for service " << info.name;
+ }
+
+ if(info.communicator)
+ {
+ try
+ {
+ info.communicator->destroy();
+ info.communicator = 0;
+ }
+ catch(const Exception& ex)
+ {
+ Warning out(_logger);
+ out << "ServiceManager: exception in stop for service " << info.name << ":\n";
+ out << ex;
+ }
+ }
+
+ try
+ {
+ info.library = 0;
+ }
+ catch(const Exception& ex)
+ {
+ Warning out(_logger);
+ out << "ServiceManager: exception in stop for service " << info.name << ":\n";
+ out << ex;
+ }
+ catch(...)
+ {
+ Warning out(_logger);
+ out << "ServiceManager: unknown exception in stop for service " << info.name;
+ }
}
_services.clear();