summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2007-01-05 18:50:12 +0000
committerDwayne Boone <dwayne@zeroc.com>2007-01-05 18:50:12 +0000
commit738623799efdaab619e744919fb7c3821ded703c (patch)
tree8e9a20c99c07f6cab855b1ff246101dfdc4dfc28
parentAdded ObjectAdapter::destroy (diff)
downloadice-738623799efdaab619e744919fb7c3821ded703c.tar.bz2
ice-738623799efdaab619e744919fb7c3821ded703c.tar.xz
ice-738623799efdaab619e744919fb7c3821ded703c.zip
Added ObejctAdapter::destroy
-rw-r--r--cpp/CHANGES5
-rw-r--r--cpp/demo/Freeze/library/Collocated.cpp3
-rw-r--r--cpp/demo/Freeze/phonebook/Collocated.cpp3
-rw-r--r--cpp/demo/IceBox/hello/HelloServiceI.cpp3
-rw-r--r--cpp/slice/Ice/Communicator.ice5
-rw-r--r--cpp/slice/Ice/ObjectAdapter.ice18
-rw-r--r--cpp/src/Ice/Instance.cpp2
-rw-r--r--cpp/src/Ice/ObjectAdapterFactory.cpp29
-rw-r--r--cpp/src/Ice/ObjectAdapterFactory.h1
-rw-r--r--cpp/src/Ice/ObjectAdapterI.cpp59
-rw-r--r--cpp/src/Ice/ObjectAdapterI.h3
-rw-r--r--cpp/test/Freeze/evictor/TestI.cpp3
-rw-r--r--cpp/test/Freeze/oldevictor/TestI.cpp3
-rw-r--r--cpp/test/Ice/adapterDeactivation/AllTests.cpp7
-rw-r--r--cpp/test/Ice/adapterDeactivation/TestI.cpp3
-rw-r--r--cpp/test/Ice/binding/TestI.cpp3
-rw-r--r--cpp/test/IceGrid/session/AllTests.cpp19
17 files changed, 121 insertions, 48 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES
index f0971f4521a..af7ecff4249 100644
--- a/cpp/CHANGES
+++ b/cpp/CHANGES
@@ -1,6 +1,11 @@
Changes since version 3.1.1
---------------------------
+- Added destroy method to the ObjectAdapter interface. It is necessary
+ to call destroy to clean up the adapter resources and be able to
+ recreate a new adapter with the same name. Communicator destroy
+ automatically calls destroy on all its adapters.
+
- Added a per-process logger and two methods to get/set the logger,
Ice::getProcessLogger() and Ice::setProcessLogger(). Get will create a
default process logger when called if set has not been called. The
diff --git a/cpp/demo/Freeze/library/Collocated.cpp b/cpp/demo/Freeze/library/Collocated.cpp
index a309690b169..f3ae12a21bb 100644
--- a/cpp/demo/Freeze/library/Collocated.cpp
+++ b/cpp/demo/Freeze/library/Collocated.cpp
@@ -86,8 +86,7 @@ LibraryCollocated::run(int argc, char* argv[])
//
int runParser(int, char*[], const Ice::CommunicatorPtr&);
int status = runParser(argc, argv, communicator());
- adapter->deactivate();
- adapter->waitForDeactivate();
+ adapter->destroy();
return status;
}
diff --git a/cpp/demo/Freeze/phonebook/Collocated.cpp b/cpp/demo/Freeze/phonebook/Collocated.cpp
index 3bc286cfa32..6dba2555651 100644
--- a/cpp/demo/Freeze/phonebook/Collocated.cpp
+++ b/cpp/demo/Freeze/phonebook/Collocated.cpp
@@ -103,8 +103,7 @@ PhoneBookCollocated::run(int argc, char* argv[])
//
int runParser(int, char*[], const Ice::CommunicatorPtr&);
int status = runParser(argc, argv, communicator());
- adapter->deactivate();
- adapter->waitForDeactivate();
+ adapter->destroy();
return status;
}
diff --git a/cpp/demo/IceBox/hello/HelloServiceI.cpp b/cpp/demo/IceBox/hello/HelloServiceI.cpp
index af0408d3bcd..135bd4a8384 100644
--- a/cpp/demo/IceBox/hello/HelloServiceI.cpp
+++ b/cpp/demo/IceBox/hello/HelloServiceI.cpp
@@ -46,6 +46,5 @@ HelloServiceI::start(const string& name, const Ice::CommunicatorPtr& communicato
void
HelloServiceI::stop()
{
- _adapter->deactivate();
- _adapter->waitForDeactivate();
+ _adapter->destroy();
}
diff --git a/cpp/slice/Ice/Communicator.ice b/cpp/slice/Ice/Communicator.ice
index 1c92ee6dba0..35cf5abc5b1 100644
--- a/cpp/slice/Ice/Communicator.ice
+++ b/cpp/slice/Ice/Communicator.ice
@@ -52,10 +52,11 @@ local interface Communicator
*
* Destroy the communicator. This operation calls [shutdown]
* implicitly. Calling [destroy] cleans up memory, and shuts down
- * this communicator's client functionality. Subsequent calls to
- * [destroy] are ignored.
+ * this communicator's client functionality and destroys all object
+ * adapters. Subsequent calls to [destroy] are ignored.
*
* @see shutdown
+ * @see ObjectAdapter::destroy
*
**/
void destroy();
diff --git a/cpp/slice/Ice/ObjectAdapter.ice b/cpp/slice/Ice/ObjectAdapter.ice
index f4cd44d459b..247986b44da 100644
--- a/cpp/slice/Ice/ObjectAdapter.ice
+++ b/cpp/slice/Ice/ObjectAdapter.ice
@@ -128,7 +128,7 @@ local interface ObjectAdapter
* Wait until the object adapter has deactivated. Calling
* [deactivate] initiates object adapter deactivation, and
* [waitForDeactivate] only returns when deactivation has
- * been completed. Once waitForDeactivate has returned it
+ * been completed. Once [waitForDeactivate] has returned it
* is possible to recreate an object adapter with the
* same name.
*
@@ -141,6 +141,22 @@ local interface ObjectAdapter
/**
*
+ * Destroys the object adapter and cleans up all resources
+ * held by the object adapter. If object adapter has not yet
+ * been deactivated, [destroy] implicitly initiates the
+ * deactivation and waits for it to finish. Once [destroy] has
+ * returned it is possible to recreate an object adapter with
+ * the same name. Subsequent calls to [destroy] are ignored.
+ *
+ * @see deactivate
+ * @see waitForDeactivate
+ * @see Communicator::destroy
+ *
+ **/
+ void destroy();
+
+ /**
+ *
* Add a servant to this object adapter's Active Servant Map. Note
* that one servant can implement several Ice objects by
* registering the servant with multiple identities. Adding a
diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp
index 7ad6fd88321..9cc8aeabac9 100644
--- a/cpp/src/Ice/Instance.cpp
+++ b/cpp/src/Ice/Instance.cpp
@@ -851,7 +851,7 @@ IceInternal::Instance::destroy()
if(_objectAdapterFactory)
{
- _objectAdapterFactory->waitForShutdown();
+ _objectAdapterFactory->destroy();
}
if(_outgoingConnectionFactory)
diff --git a/cpp/src/Ice/ObjectAdapterFactory.cpp b/cpp/src/Ice/ObjectAdapterFactory.cpp
index 03ca3d518c5..bbd67ffd6eb 100644
--- a/cpp/src/Ice/ObjectAdapterFactory.cpp
+++ b/cpp/src/Ice/ObjectAdapterFactory.cpp
@@ -84,11 +84,6 @@ IceInternal::ObjectAdapterFactory::waitForShutdown()
for_each(_adapters.begin(), _adapters.end(),
IceUtil::secondVoidMemFun<const string, ObjectAdapterI>(&ObjectAdapter::waitForDeactivate));
- //
- // We're done, now we can throw away the object adapters.
- //
- _adapters.clear();
-
{
IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this);
@@ -100,6 +95,30 @@ IceInternal::ObjectAdapterFactory::waitForShutdown()
}
}
+void
+IceInternal::ObjectAdapterFactory::destroy()
+{
+ //
+ // First wait for shutdown to finish.
+ //
+ waitForShutdown();
+
+ map<string, ObjectAdapterIPtr> adapters;
+
+ {
+ IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this);
+
+ adapters = _adapters;
+ _adapters.clear();
+ }
+
+ //
+ // Now we destroy each object adapter.
+ //
+ for_each(adapters.begin(), adapters.end(),
+ IceUtil::secondVoidMemFun<const string, ObjectAdapterI>(&ObjectAdapter::destroy));
+}
+
ObjectAdapterPtr
IceInternal::ObjectAdapterFactory::createObjectAdapter(const string& name, const string& endpoints,
const RouterPrx& router)
diff --git a/cpp/src/Ice/ObjectAdapterFactory.h b/cpp/src/Ice/ObjectAdapterFactory.h
index a94a5a7339d..5d35df6a568 100644
--- a/cpp/src/Ice/ObjectAdapterFactory.h
+++ b/cpp/src/Ice/ObjectAdapterFactory.h
@@ -23,6 +23,7 @@ public:
void shutdown();
void waitForShutdown();
+ void destroy();
::Ice::ObjectAdapterPtr createObjectAdapter(const std::string&, const std::string&, const Ice::RouterPrx&);
::Ice::ObjectAdapterPtr findObjectAdapter(const ::Ice::ObjectPrx&);
diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp
index 774bb1a45cc..c53b96560a8 100644
--- a/cpp/src/Ice/ObjectAdapterI.cpp
+++ b/cpp/src/Ice/ObjectAdapterI.cpp
@@ -287,14 +287,54 @@ Ice::ObjectAdapterI::waitForDeactivate()
for_each(_incomingConnectionFactories.begin(), _incomingConnectionFactories.end(),
Ice::voidMemFun(&IncomingConnectionFactory::waitUntilFinished));
+ {
+ IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this);
+
+ //
+ // Signal that waiting is complete.
+ //
+ _waitForDeactivate = false;
+ notifyAll();
+ }
+}
+
+void
+Ice::ObjectAdapterI::destroy()
+{
+ {
+ IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this);
+
+ //
+ // Another thread is in the process of destroying the object
+ // adapter. Wait for it to finish.
+ //
+ while(_destroying)
+ {
+ wait();
+ }
+
+ //
+ // Object adpater is already destroyed.
+ //
+ if(_destroyed)
+ {
+ return;
+ }
+
+ _destroying = true;
+ }
+
+ //
+ // Deactivate and wait for completion.
+ //
+ deactivate();
+ waitForDeactivate();
+
//
// Now it's also time to clean up our servants and servant
// locators.
//
- if(_instance) // Don't destroy twice.
- {
- _servantManager->destroy();
- }
+ _servantManager->destroy();
//
// Destroy the thread pool.
@@ -311,9 +351,10 @@ Ice::ObjectAdapterI::waitForDeactivate()
IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this);
//
- // Signal that waiting is complete.
+ // Signal that destroy is complete.
//
- _waitForDeactivate = false;
+ _destroying = false;
+ _destroyed = true;
notifyAll();
//
@@ -692,6 +733,8 @@ Ice::ObjectAdapterI::ObjectAdapterI(const InstancePtr& instance, const Communica
_directCount(0),
_waitForActivate(false),
_waitForDeactivate(false),
+ _destroying(false),
+ _destroyed(false),
_noConfig(noConfig)
{
if(_noConfig)
@@ -892,10 +935,10 @@ Ice::ObjectAdapterI::~ObjectAdapterI()
Warning out(_instance->initializationData().logger);
out << "object adapter `" << getName() << "' has not been deactivated";
}
- else if(_instance)
+ else if(!_destroyed)
{
Warning out(_instance->initializationData().logger);
- out << "object adapter `" << getName() << "' deactivation had not been waited for";
+ out << "object adapter `" << getName() << "' has not been destroyed";
}
else
{
diff --git a/cpp/src/Ice/ObjectAdapterI.h b/cpp/src/Ice/ObjectAdapterI.h
index c3f198d91b8..a4634d68931 100644
--- a/cpp/src/Ice/ObjectAdapterI.h
+++ b/cpp/src/Ice/ObjectAdapterI.h
@@ -49,6 +49,7 @@ public:
virtual void waitForHold();
virtual void deactivate();
virtual void waitForDeactivate();
+ virtual void destroy();
virtual ObjectPrx add(const ObjectPtr&, const Identity&);
virtual ObjectPrx addFacet(const ObjectPtr&, const Identity&, const std::string&);
@@ -117,6 +118,8 @@ private:
int _directCount; // The number of direct proxies dispatching on this object adapter.
bool _waitForActivate;
bool _waitForDeactivate;
+ bool _destroying;
+ bool _destroyed;
bool _noConfig;
static std::string _propertyPrefix;
diff --git a/cpp/test/Freeze/evictor/TestI.cpp b/cpp/test/Freeze/evictor/TestI.cpp
index 7c8fbcb90b0..be86a10f3c1 100644
--- a/cpp/test/Freeze/evictor/TestI.cpp
+++ b/cpp/test/Freeze/evictor/TestI.cpp
@@ -307,8 +307,7 @@ Test::RemoteEvictorI::saveNow(const Current& current)
void
Test::RemoteEvictorI::deactivate(const Current& current)
{
- _evictorAdapter->deactivate();
- _evictorAdapter->waitForDeactivate();
+ _evictorAdapter->destroy();
_adapter->remove(_adapter->getCommunicator()->stringToIdentity(_category));
}
diff --git a/cpp/test/Freeze/oldevictor/TestI.cpp b/cpp/test/Freeze/oldevictor/TestI.cpp
index 7c8fbcb90b0..be86a10f3c1 100644
--- a/cpp/test/Freeze/oldevictor/TestI.cpp
+++ b/cpp/test/Freeze/oldevictor/TestI.cpp
@@ -307,8 +307,7 @@ Test::RemoteEvictorI::saveNow(const Current& current)
void
Test::RemoteEvictorI::deactivate(const Current& current)
{
- _evictorAdapter->deactivate();
- _evictorAdapter->waitForDeactivate();
+ _evictorAdapter->destroy();
_adapter->remove(_adapter->getCommunicator()->stringToIdentity(_category));
}
diff --git a/cpp/test/Ice/adapterDeactivation/AllTests.cpp b/cpp/test/Ice/adapterDeactivation/AllTests.cpp
index c4a9cc5f32d..a4577f18a3a 100644
--- a/cpp/test/Ice/adapterDeactivation/AllTests.cpp
+++ b/cpp/test/Ice/adapterDeactivation/AllTests.cpp
@@ -41,14 +41,13 @@ allTests(const CommunicatorPtr& communicator)
catch(const AlreadyRegisteredException&)
{
}
- adapter->deactivate();
- adapter->waitForDeactivate();
+ adapter->destroy();
+
//
// Use a different port than the first adapter to avoid an "address already in use" error.
//
adapter = communicator->createObjectAdapterWithEndpoints("TransientTestAdapter", "default -p 9998");
- adapter->deactivate();
- adapter->waitForDeactivate();
+ adapter->destroy();
cout << "ok" << endl;
}
diff --git a/cpp/test/Ice/adapterDeactivation/TestI.cpp b/cpp/test/Ice/adapterDeactivation/TestI.cpp
index f9c33004155..d4539f12093 100644
--- a/cpp/test/Ice/adapterDeactivation/TestI.cpp
+++ b/cpp/test/Ice/adapterDeactivation/TestI.cpp
@@ -22,8 +22,7 @@ TestI::transient(const Current& current)
ObjectAdapterPtr adapter =
communicator->createObjectAdapterWithEndpoints("TransientTestAdapter", "default -p 9999");
adapter->activate();
- adapter->deactivate();
- adapter->waitForDeactivate();
+ adapter->destroy();
}
void
diff --git a/cpp/test/Ice/binding/TestI.cpp b/cpp/test/Ice/binding/TestI.cpp
index 6f67ec0bf9a..68fa9114a74 100644
--- a/cpp/test/Ice/binding/TestI.cpp
+++ b/cpp/test/Ice/binding/TestI.cpp
@@ -54,8 +54,7 @@ RemoteObjectAdapterI::deactivate(const Ice::Current&)
{
try
{
- _adapter->deactivate();
- _adapter->waitForDeactivate();
+ _adapter->destroy();
}
catch(const ObjectAdapterDeactivatedException&)
{
diff --git a/cpp/test/IceGrid/session/AllTests.cpp b/cpp/test/IceGrid/session/AllTests.cpp
index e40196c5a06..21487bd237b 100644
--- a/cpp/test/IceGrid/session/AllTests.cpp
+++ b/cpp/test/IceGrid/session/AllTests.cpp
@@ -1387,11 +1387,8 @@ allTests(const Ice::CommunicatorPtr& communicator)
}
session2->destroy();
- adpt1->deactivate();
- adpt2->deactivate();
-
- adpt1->waitForDeactivate();
- adpt2->waitForDeactivate();
+ adpt1->destroy();
+ adpt2->destroy();
//
// TODO: test session reaping?
@@ -1490,8 +1487,7 @@ allTests(const Ice::CommunicatorPtr& communicator)
}
session1->destroy();
- adpt1->deactivate();
- adpt1->waitForDeactivate();
+ adpt1->destroy();
cout << "ok" << endl;
}
@@ -1575,8 +1571,7 @@ allTests(const Ice::CommunicatorPtr& communicator)
}
session1->destroy();
- adpt1->deactivate();
- adpt1->waitForDeactivate();
+ adpt1->destroy();
cout << "ok" << endl;
}
@@ -1630,8 +1625,7 @@ allTests(const Ice::CommunicatorPtr& communicator)
}
session1->destroy();
- adpt1->deactivate();
- adpt1->waitForDeactivate();
+ adpt1->destroy();
cout << "ok" << endl;
}
@@ -1743,8 +1737,7 @@ allTests(const Ice::CommunicatorPtr& communicator)
// nodeObs1->waitForUpdate(__FILE__, __LINE__); // serverUpdate(Destroyed)
// session1->destroy();
-// adpt1->deactivate();
-// adpt1->waitForDeactivate();
+// adpt1->destroy();
// cout << "ok" << endl;
}