summaryrefslogtreecommitdiff
path: root/cpp/src/IceBox/ServiceManagerI.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2009-03-24 11:45:18 +0100
committerBenoit Foucher <benoit@zeroc.com>2009-03-24 11:45:18 +0100
commit06a08ecf28e205277336a97a6173db7ccbed1adc (patch)
treea369a5044a63f8cdba9e7c0a461e24ae344486b4 /cpp/src/IceBox/ServiceManagerI.cpp
parentMerge branch 'R3_3_branch' (diff)
parentBug 3924: slice2py missing from VC60 installer (diff)
downloadice-06a08ecf28e205277336a97a6173db7ccbed1adc.tar.bz2
ice-06a08ecf28e205277336a97a6173db7ccbed1adc.tar.xz
ice-06a08ecf28e205277336a97a6173db7ccbed1adc.zip
Merge commit 'origin/R3_3_branch'
Conflicts: CHANGES cpp/demo/Freeze/backup/.depend cpp/demo/Freeze/bench/.depend cpp/demo/Freeze/casino/.depend cpp/demo/Freeze/customEvictor/.depend cpp/demo/Freeze/library/.depend cpp/demo/Freeze/phonebook/.depend cpp/demo/Freeze/transform/.depend cpp/demo/Glacier2/callback/.depend cpp/demo/Glacier2/chat/.depend cpp/demo/Ice/async/.depend cpp/demo/Ice/bidir/.depend cpp/demo/Ice/callback/.depend cpp/demo/Ice/converter/.depend cpp/demo/Ice/hello/.depend cpp/demo/Ice/invoke/.depend cpp/demo/Ice/latency/.depend cpp/demo/Ice/minimal/.depend cpp/demo/Ice/multicast/.depend cpp/demo/Ice/nested/.depend cpp/demo/Ice/nrvo/.depend cpp/demo/Ice/session/.depend cpp/demo/Ice/throughput/.depend cpp/demo/Ice/value/.depend cpp/demo/IceBox/hello/.depend cpp/demo/IceGrid/allocate/.depend cpp/demo/IceGrid/icebox/.depend cpp/demo/IceGrid/replication/.depend cpp/demo/IceGrid/sessionActivation/.depend cpp/demo/IceGrid/simple/.depend cpp/demo/IceStorm/clock/.depend cpp/demo/IceStorm/counter/.depend cpp/demo/IceStorm/replicated/.depend cpp/demo/IceStorm/replicated2/.depend cpp/demo/book/freeze_filesystem/.depend cpp/demo/book/lifecycle/.depend cpp/demo/book/printer/.depend cpp/demo/book/simple_filesystem/.depend cpp/src/Freeze/.depend cpp/src/FreezeScript/.depend cpp/src/Ice/.depend cpp/src/Ice/UdpTransceiver.cpp cpp/src/Ice/UdpTransceiver.h cpp/src/IceBox/.depend cpp/src/IceGrid/.depend cpp/src/IceGridLib/.depend cpp/src/IcePatch2/.depend cpp/src/IceStorm/.depend cpp/src/slice2freeze/.depend cpp/test/Freeze/complex/.depend cpp/test/Freeze/dbmap/.depend cpp/test/Freeze/evictor/.depend cpp/test/Freeze/oldevictor/.depend cpp/test/FreezeScript/dbmap/.depend cpp/test/FreezeScript/evictor/.depend cpp/test/Glacier2/attack/.depend cpp/test/Glacier2/dynamicFiltering/.depend cpp/test/Glacier2/router/.depend cpp/test/Glacier2/sessionControl/.depend cpp/test/Glacier2/ssl/.depend cpp/test/Glacier2/staticFiltering/.depend cpp/test/Ice/adapterDeactivation/.depend cpp/test/Ice/background/.depend cpp/test/Ice/binding/.depend cpp/test/Ice/checksum/.depend cpp/test/Ice/checksum/server/.depend cpp/test/Ice/custom/.depend cpp/test/Ice/exceptions/.depend cpp/test/Ice/facets/.depend cpp/test/Ice/faultTolerance/.depend cpp/test/Ice/gc/.depend cpp/test/Ice/hold/.depend cpp/test/Ice/inheritance/.depend cpp/test/Ice/interceptor/.depend cpp/test/Ice/location/.depend cpp/test/Ice/objects/.depend cpp/test/Ice/operations/.depend cpp/test/Ice/proxy/.depend cpp/test/Ice/retry/.depend cpp/test/Ice/servantLocator/.depend cpp/test/Ice/slicing/exceptions/.depend cpp/test/Ice/slicing/objects/.depend cpp/test/Ice/stream/.depend cpp/test/Ice/stringConverter/.depend cpp/test/Ice/timeout/.depend cpp/test/Ice/udp/.depend cpp/test/IceBox/configuration/.depend cpp/test/IceGrid/activation/.depend cpp/test/IceGrid/allocation/.depend cpp/test/IceGrid/deployer/.depend cpp/test/IceGrid/distribution/.depend cpp/test/IceGrid/replicaGroup/.depend cpp/test/IceGrid/replication/.depend cpp/test/IceGrid/session/.depend cpp/test/IceGrid/simple/.depend cpp/test/IceGrid/update/.depend cpp/test/IceSSL/configuration/.depend cpp/test/IceStorm/federation/.depend cpp/test/IceStorm/federation2/.depend cpp/test/IceStorm/rep1/.depend cpp/test/IceStorm/repgrid/.depend cpp/test/IceStorm/repstress/.depend cpp/test/IceStorm/single/.depend cpp/test/IceStorm/stress/.depend cpp/test/Slice/keyword/.depend cs/src/Ice/Instance.cs cs/src/IceSSL/ConnectorI.cs java/demo/book/simple_filesystem/Filesystem/DirectoryI.java java/demo/book/simple_filesystem/Filesystem/FileI.java java/src/IceInternal/TcpConnector.java java/src/IceSSL/ConnectorI.java py/modules/IcePy/.depend rb/src/IceRuby/.depend
Diffstat (limited to 'cpp/src/IceBox/ServiceManagerI.cpp')
-rw-r--r--cpp/src/IceBox/ServiceManagerI.cpp301
1 files changed, 151 insertions, 150 deletions
diff --git a/cpp/src/IceBox/ServiceManagerI.cpp b/cpp/src/IceBox/ServiceManagerI.cpp
index 0cb8aba1c9d..e80a49474e6 100644
--- a/cpp/src/IceBox/ServiceManagerI.cpp
+++ b/cpp/src/IceBox/ServiceManagerI.cpp
@@ -76,6 +76,50 @@ private:
const PropertiesPtr _properties;
};
+struct StartServiceInfo
+{
+ StartServiceInfo(const std::string& service, const std::string& value, const Ice::StringSeq& serverArgs)
+ {
+ name = service;
+
+ //
+ // Separate the entry point from the arguments.
+ //
+ string::size_type pos = value.find_first_of(" \t\n");
+ if(pos == string::npos)
+ {
+ entryPoint = value;
+ }
+ else
+ {
+ entryPoint = value.substr(0, pos);
+ try
+ {
+ args = IceUtilInternal::Options::split(value.substr(pos + 1));
+ }
+ catch(const IceUtilInternal::BadOptException& ex)
+ {
+ FailureException e(__FILE__, __LINE__);
+ e.reason = "ServiceManager: invalid arguments for service `" + name + "':\n" + ex.reason;
+ throw e;
+ }
+ }
+
+ for(Ice::StringSeq::const_iterator p = serverArgs.begin(); p != serverArgs.end(); ++p)
+ {
+ if(p->find("--" + name + ".") == 0)
+ {
+ args.push_back(*p);
+ }
+ }
+ }
+
+ string name;
+ string entryPoint;
+ Ice::StringSeq args;
+};
+
+
}
IceBox::ServiceManagerI::ServiceManagerI(CommunicatorPtr communicator, int& argc, char* argv[]) :
@@ -138,7 +182,7 @@ IceBox::ServiceManagerI::startService(const string& name, const Current&)
bool started = false;
try
{
- info.service->start(name, info.communicator == 0 ? _communicator : info.communicator, info.args);
+ info.service->start(name, info.communicator == 0 ? _sharedCommunicator : info.communicator, info.args);
started = true;
}
catch(const Ice::Exception& ex)
@@ -343,19 +387,19 @@ IceBox::ServiceManagerI::start()
}
//
- // Load and start the services defined in the property set
- // with the prefix "IceBox.Service.". These properties should
- // have the following format:
+ // Parse the property set with the prefix "IceBox.Service.". These
+ // properties should have the following format:
//
// IceBox.Service.Foo=entry_point [args]
//
- // We load the services specified in IceBox.LoadOrder first,
- // then load any remaining services.
+ // We parse the service properties specified in IceBox.LoadOrder
+ // first, then the ones from remaining services.
//
const string prefix = "IceBox.Service.";
PropertyDict services = properties->getPropertiesForPrefix(prefix);
PropertyDict::iterator p;
StringSeq loadOrder = properties->getPropertyAsList("IceBox.LoadOrder");
+ vector<StartServiceInfo> servicesInfo;
for(StringSeq::const_iterator q = loadOrder.begin(); q != loadOrder.end(); ++q)
{
p = services.find(prefix + *q);
@@ -365,13 +409,76 @@ IceBox::ServiceManagerI::start()
ex.reason = "ServiceManager: no service definition for `" + *q + "'";
throw ex;
}
- load(*q, p->second);
+ servicesInfo.push_back(StartServiceInfo(*q, p->second, _argv));
services.erase(p);
}
for(p = services.begin(); p != services.end(); ++p)
{
- string name = p->first.substr(prefix.size());
- load(name, p->second);
+ servicesInfo.push_back(StartServiceInfo(p->first.substr(prefix.size()), p->second, _argv));
+ }
+
+ //
+ // Check if some services are using the shared communicator in which
+ // case we create the shared communicator now with a property set which
+ // is the union of all the service properties (services which are using
+ // the shared communicator).
+ //
+ PropertyDict sharedCommunicatorServices = properties->getPropertiesForPrefix("IceBox.UseSharedCommunicator.");
+ if(!sharedCommunicatorServices.empty())
+ {
+ InitializationData initData;
+ initData.properties = createServiceProperties("SharedCommunicator");
+ for(vector<StartServiceInfo>::iterator q = servicesInfo.begin(); q != servicesInfo.end(); ++q)
+ {
+ if(properties->getPropertyAsInt("IceBox.UseSharedCommunicator." + q->name) <= 0)
+ {
+ continue;
+ }
+
+ //
+ // Load the service properties using the shared communicator properties as
+ // the default properties.
+ //
+ PropertiesPtr svcProperties = createProperties(q->args, initData.properties);
+
+ //
+ // Erase properties from the shared communicator which don't exist in the
+ // service properties (which include the shared communicator properties
+ // overriden by the service properties).
+ //
+ PropertyDict allProps = initData.properties->getPropertiesForPrefix("");
+ for(PropertyDict::iterator p = allProps.begin(); p != allProps.end(); ++p)
+ {
+ if(svcProperties->getProperty(p->first) == "")
+ {
+ initData.properties->setProperty(p->first, "");
+ }
+ }
+
+ //
+ // Add the service properties to the shared communicator properties.
+ //
+ PropertyDict props = svcProperties->getPropertiesForPrefix("");
+ for(PropertyDict::const_iterator r = props.begin(); r != props.end(); ++r)
+ {
+ initData.properties->setProperty(r->first, r->second);
+ }
+
+ //
+ // Parse <service>.* command line options (the Ice command line options
+ // were parsed by the createProperties above)
+ //
+ q->args = initData.properties->parseCommandLineOptions(q->name, q->args);
+ }
+ _sharedCommunicator = initialize(initData);
+ }
+
+ //
+ // Start the services.
+ //
+ for(vector<StartServiceInfo>::const_iterator r = servicesInfo.begin(); r != servicesInfo.end(); ++r)
+ {
+ start(r->name, r->entryPoint, r->args);
}
//
@@ -459,62 +566,14 @@ IceBox::ServiceManagerI::stop()
}
void
-IceBox::ServiceManagerI::load(const string& name, const string& value)
-{
- //
- // Separate the entry point from the arguments.
- //
- string entryPoint;
- StringSeq args;
- string::size_type pos = value.find_first_of(" \t\n");
- if(pos == string::npos)
- {
- entryPoint = value;
- }
- else
- {
- entryPoint = value.substr(0, pos);
- try
- {
- args = IceUtilInternal::Options::split(value.substr(pos + 1));
- }
- catch(const IceUtilInternal::BadOptException& ex)
- {
- FailureException e(__FILE__, __LINE__);
- e.reason = "ServiceManager: invalid arguments for service `" + name + "':\n" + ex.reason;
- throw e;
- }
- }
- start(name, entryPoint, args);
-}
-
-void
IceBox::ServiceManagerI::start(const string& service, const string& entryPoint, const StringSeq& args)
{
IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
- //
- // Create the service property set from the service arguments and
- // the server arguments. The service property set will be used to
- // create a new communicator, or will be added to the shared
- // communicator, depending on the value of the
- // IceBox.UseSharedCommunicator property.
- //
ServiceInfo info;
info.name = service;
info.status = Stopped;
- StringSeq::size_type j;
- for(j = 0; j < args.size(); j++)
- {
- info.args.push_back(args[j]);
- }
- for(j = 0; j < _argv.size(); j++)
- {
- if(_argv[j].find("--" + service + ".") == 0)
- {
- info.args.push_back(_argv[j]);
- }
- }
+ info.args = args;
//
// Load the entry point.
@@ -539,6 +598,9 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint,
SERVICE_FACTORY factory = (SERVICE_FACTORY)sym;
try
{
+#if defined(__BCPLUSPLUS__) && (__BCPLUSPLUS__ >= 0x0600)
+ IceUtil::DummyBCC dummy;
+#endif
info.service = factory(_communicator);
}
catch(const Exception& ex)
@@ -569,52 +631,40 @@ IceBox::ServiceManagerI::start(const string& service, const string& entryPoint,
Ice::CommunicatorPtr communicator;
if(_communicator->getProperties()->getPropertyAsInt("IceBox.UseSharedCommunicator." + service) > 0)
{
- if(!_sharedCommunicator)
- {
- Ice::StringSeq dummy = Ice::StringSeq();
- _sharedCommunicator = createCommunicator("", dummy);
- }
+ assert(_sharedCommunicator);
communicator = _sharedCommunicator;
-
- PropertiesPtr properties = _sharedCommunicator->getProperties();
-
- PropertiesPtr svcProperties = createProperties(info.args, properties);
-
+ }
+ else
+ {
//
- // Erase properties from the shared communicator which don't exist in the
- // service properties (which include the shared communicator properties
- // overriden by the service properties).
+ // Create the service properties. We use the communicator properties as the default
+ // properties if IceBox.InheritProperties is set.
//
- PropertyDict allProps = properties->getPropertiesForPrefix("");
- for(PropertyDict::iterator p = allProps.begin(); p != allProps.end(); ++p)
+ InitializationData initData;
+ initData.properties = createServiceProperties(service);
+ if(!info.args.empty())
{
- if(svcProperties->getProperty(p->first) == "")
- {
- properties->setProperty(p->first, "");
- }
- }
+ //
+ // Create the service properties with the given service arguments. This should
+ // read the service config file if it's specified with --Ice.Config.
+ //
+ initData.properties = createProperties(info.args, initData.properties);
- //
- // Add the service properties to the shared communicator properties.
- //
- PropertyDict props = svcProperties->getPropertiesForPrefix("");
- for(PropertyDict::const_iterator q = props.begin(); q != props.end(); ++q)
- {
- properties->setProperty(q->first, q->second);
+ //
+ // Next, parse the service "<service>.*" command line options (the Ice command
+ // line options were parsed by the createProperties above)
+ //
+ info.args = initData.properties->parseCommandLineOptions(service, info.args);
}
//
- // Parse <service>.* command line options (the Ice command line options
- // were parsed by the createProperties above)
+ // Remaining command line options are passed to the communicator. This is
+ // necessary for Ice plug-in properties (e.g.: IceSSL).
//
- info.args = properties->parseCommandLineOptions(service, info.args);
- }
- else
- {
- info.communicator = createCommunicator(service, info.args);
+ info.communicator = initialize(info.args, initData);
communicator = info.communicator;
}
-
+
//
// Start the service.
//
@@ -892,16 +942,11 @@ IceBox::ServiceManagerI::observerRemoved(const ServiceObserverPrx& observer, con
}
}
-Ice::CommunicatorPtr
-IceBox::ServiceManagerI::createCommunicator(const string& service, Ice::StringSeq& args)
+Ice::PropertiesPtr
+IceBox::ServiceManagerI::createServiceProperties(const string& service)
{
- PropertiesPtr communicatorProperties = _communicator->getProperties();
-
- //
- // Create the service properties. We use the communicator properties as the default
- // properties if IceBox.InheritProperties is set.
- //
PropertiesPtr properties;
+ PropertiesPtr communicatorProperties = _communicator->getProperties();
if(communicatorProperties->getPropertyAsInt("IceBox.InheritProperties") > 0)
{
properties = communicatorProperties->clone();
@@ -911,59 +956,15 @@ IceBox::ServiceManagerI::createCommunicator(const string& service, Ice::StringSe
{
properties = createProperties();
}
-
- //
- // Set the default program name for the service properties. By default it's
- // the IceBox program name + "-" + the service name, or just the IceBox
- // program name if we're creating the shared communicator (service == "").
- //
+
string programName = communicatorProperties->getProperty("Ice.ProgramName");
- if(service.empty())
+ if(programName.empty())
{
- if(programName.empty())
- {
- properties->setProperty("Ice.ProgramName", "SharedCommunicator");
- }
- else
- {
- properties->setProperty("Ice.ProgramName", programName + "-SharedCommunicator");
- }
+ properties->setProperty("Ice.ProgramName", service);
}
else
{
- if(programName.empty())
- {
- properties->setProperty("Ice.ProgramName", service);
- }
- else
- {
- properties->setProperty("Ice.ProgramName", programName + "-" + service);
- }
- }
-
- if(!args.empty())
- {
- //
- // Create the service properties with the given service arguments. This should
- // read the service config file if it's specified with --Ice.Config.
- //
- properties = createProperties(args, properties);
-
- if(!service.empty())
- {
- //
- // Next, parse the service "<service>.*" command line options (the Ice command
- // line options were parsed by the createProperties above)
- //
- args = properties->parseCommandLineOptions(service, args);
- }
+ properties->setProperty("Ice.ProgramName", programName + "-" + service);
}
-
- //
- // Remaining command line options are passed to the communicator. This is
- // necessary for Ice plug-in properties (e.g.: IceSSL).
- //
- InitializationData initData;
- initData.properties = properties;
- return initialize(args, initData);
+ return properties;
}