summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorMatthew Newhook <matthew@zeroc.com>2005-04-27 01:17:29 +0000
committerMatthew Newhook <matthew@zeroc.com>2005-04-27 01:17:29 +0000
commit28b4ee78d72e2776443f185581f553c1f19780ae (patch)
treee532ded3c9db6cc934ebbca60c17273ea2e4277a /cpp
parentMade finalizers thread-safe. (diff)
downloadice-28b4ee78d72e2776443f185581f553c1f19780ae.tar.bz2
ice-28b4ee78d72e2776443f185581f553c1f19780ae.tar.xz
ice-28b4ee78d72e2776443f185581f553c1f19780ae.zip
removed singleton. removed friends.
Diffstat (limited to 'cpp')
-rwxr-xr-xcpp/demo/Ice/session/ReapThread.cpp22
-rwxr-xr-xcpp/demo/Ice/session/ReapThread.h14
-rw-r--r--cpp/demo/Ice/session/Server.cpp5
-rwxr-xr-xcpp/demo/Ice/session/SessionFactoryI.cpp8
-rwxr-xr-xcpp/demo/Ice/session/SessionFactoryI.h7
-rwxr-xr-xcpp/demo/Ice/session/SessionI.cpp21
-rwxr-xr-xcpp/demo/Ice/session/SessionI.h12
7 files changed, 32 insertions, 57 deletions
diff --git a/cpp/demo/Ice/session/ReapThread.cpp b/cpp/demo/Ice/session/ReapThread.cpp
index 6af813779b1..24eaf507aba 100755
--- a/cpp/demo/Ice/session/ReapThread.cpp
+++ b/cpp/demo/Ice/session/ReapThread.cpp
@@ -13,20 +13,10 @@
using namespace std;
using namespace Demo;
-ReapThreadPtr ReapThread::_instance;
-IceUtil::StaticMutex ReapThread::_instanceMutex = ICE_STATIC_MUTEX_INITIALIZER;
-
-ReapThreadPtr&
-ReapThread::instance()
+ReapThread::ReapThread() :
+ _timeout(IceUtil::Time::seconds(10)),
+ _terminated(false)
{
- IceUtil::StaticMutex::Lock sync(_instanceMutex);
-
- if(!_instance)
- {
- _instance = new ReapThread;
- }
-
- return _instance;
}
void
@@ -99,9 +89,3 @@ ReapThread::add(const SessionPrx& proxy, const SessionIPtr& session)
Lock sync(*this);
_sessions.push_back(SessionProxyPair(proxy, session));
}
-
-ReapThread::ReapThread() :
- _timeout(IceUtil::Time::seconds(10)),
- _terminated(false)
-{
-}
diff --git a/cpp/demo/Ice/session/ReapThread.h b/cpp/demo/Ice/session/ReapThread.h
index 33fdc7333d9..1c4e410ee13 100755
--- a/cpp/demo/Ice/session/ReapThread.h
+++ b/cpp/demo/Ice/session/ReapThread.h
@@ -11,30 +11,22 @@
#define REAP_THREAD_H
#include <IceUtil/Thread.h>
-#include <IceUtil/StaticMutex.h>
#include <SessionI.h>
#include <list>
-class ReapThread;
-typedef IceUtil::Handle<ReapThread> ReapThreadPtr;
-
class ReapThread : public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex>
{
public:
- static ReapThreadPtr& instance();
+ ReapThread();
virtual void run();
-
void terminate();
-
void add(const Demo::SessionPrx&, const SessionIPtr&);
private:
- ReapThread();
-
const IceUtil::Time _timeout;
bool _terminated;
struct SessionProxyPair
@@ -45,9 +37,7 @@ private:
const SessionIPtr session;
};
std::list<SessionProxyPair> _sessions;
-
- static ReapThreadPtr _instance;
- static IceUtil::StaticMutex _instanceMutex;
};
+typedef IceUtil::Handle<ReapThread> ReapThreadPtr;
#endif
diff --git a/cpp/demo/Ice/session/Server.cpp b/cpp/demo/Ice/session/Server.cpp
index 670bc3a4cc9..9b3dd714707 100644
--- a/cpp/demo/Ice/session/Server.cpp
+++ b/cpp/demo/Ice/session/Server.cpp
@@ -8,7 +8,6 @@
// **********************************************************************
#include <SessionFactoryI.h>
-#include <ReapThread.h>
using namespace std;
using namespace Demo;
@@ -32,10 +31,10 @@ SessionServer::run(int argc, char* argv[])
{
Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("SessionFactory");
- ReapThreadPtr reaper = ReapThread::instance();
+ ReapThreadPtr reaper = new ReapThread();
reaper->start();
- adapter->add(new SessionFactoryI, Ice::stringToIdentity("SessionFactory"));
+ adapter->add(new SessionFactoryI(reaper), Ice::stringToIdentity("SessionFactory"));
adapter->activate();
communicator()->waitForShutdown();
diff --git a/cpp/demo/Ice/session/SessionFactoryI.cpp b/cpp/demo/Ice/session/SessionFactoryI.cpp
index e87dc33df75..b16c6455d5e 100755
--- a/cpp/demo/Ice/session/SessionFactoryI.cpp
+++ b/cpp/demo/Ice/session/SessionFactoryI.cpp
@@ -8,17 +8,21 @@
// **********************************************************************
#include <SessionFactoryI.h>
-#include <ReapThread.h>
using namespace std;
using namespace Demo;
+SessionFactoryI::SessionFactoryI(const ReapThreadPtr& reapThread) :
+ _reaper(reapThread)
+{
+}
+
SessionPrx
SessionFactoryI::create(const string& name, const Ice::Current& c)
{
SessionIPtr session = new SessionI(name);
SessionPrx proxy = SessionPrx::uncheckedCast(c.adapter->addWithUUID(session));
- ReapThread::instance()->add(proxy, session);
+ _reaper->add(proxy, session);
return proxy;
}
diff --git a/cpp/demo/Ice/session/SessionFactoryI.h b/cpp/demo/Ice/session/SessionFactoryI.h
index 28db4215fd4..f7933edbea2 100755
--- a/cpp/demo/Ice/session/SessionFactoryI.h
+++ b/cpp/demo/Ice/session/SessionFactoryI.h
@@ -12,13 +12,20 @@
#include <Ice/Ice.h>
#include <Session.h>
+#include <ReapThread.h>
class SessionFactoryI : public Demo::SessionFactory
{
public:
+ SessionFactoryI(const ReapThreadPtr&);
+
virtual Demo::SessionPrx create(const std::string&, const Ice::Current&);
virtual void shutdown(const Ice::Current&);
+
+private:
+
+ ReapThreadPtr _reaper;
};
#endif
diff --git a/cpp/demo/Ice/session/SessionI.cpp b/cpp/demo/Ice/session/SessionI.cpp
index c21cfd7b5cc..83673decf76 100755
--- a/cpp/demo/Ice/session/SessionI.cpp
+++ b/cpp/demo/Ice/session/SessionI.cpp
@@ -40,11 +40,19 @@ private:
const int _id;
};
+SessionI::SessionI(const string& name) :
+ _name(name),
+ _timestamp(IceUtil::Time::now()),
+ _nextId(0),
+ _destroy(false)
+{
+ cout << "The session " << _name << " is now created." << endl;
+}
+
HelloPrx
SessionI::createHello(const Ice::Current& c)
{
Lock sync(*this);
-
if(_destroy)
{
throw Ice::ObjectNotExistException(__FILE__, __LINE__);
@@ -59,7 +67,6 @@ void
SessionI::refresh(const Ice::Current& c)
{
Lock sync(*this);
-
if(_destroy)
{
throw Ice::ObjectNotExistException(__FILE__, __LINE__);
@@ -72,7 +79,6 @@ string
SessionI::getName(const Ice::Current&) const
{
Lock sync(*this);
-
if(_destroy)
{
throw Ice::ObjectNotExistException(__FILE__, __LINE__);
@@ -120,12 +126,3 @@ SessionI::timestamp() const
}
return _timestamp;
}
-
-SessionI::SessionI(const string& name) :
- _name(name),
- _timestamp(IceUtil::Time::now()),
- _nextId(0),
- _destroy(false)
-{
- cout << "The session " << _name << " is now created." << endl;
-}
diff --git a/cpp/demo/Ice/session/SessionI.h b/cpp/demo/Ice/session/SessionI.h
index c3de1a1b540..f502c96ac86 100755
--- a/cpp/demo/Ice/session/SessionI.h
+++ b/cpp/demo/Ice/session/SessionI.h
@@ -18,29 +18,23 @@ class SessionI : public Demo::Session, public IceUtil::Mutex
{
public:
+ SessionI(const std::string&);
+
virtual Demo::HelloPrx createHello(const Ice::Current&);
virtual void refresh(const Ice::Current&);
virtual std::string getName(const Ice::Current&) const;
virtual void destroy(const Ice::Current&);
-private:
-
- // Only the ReapThread is interested in the timestamp.
- friend class ReapThread;
IceUtil::Time timestamp() const;
- // Only the session factory can create sessions.
- friend class SessionFactoryI;
- SessionI(const std::string&);
+private:
const std::string _name;
IceUtil::Time _timestamp; // The last time the session was refreshed.
-
int _nextId; // The per-session id of the next hello object. This is used for tracing purposes.
std::list<Demo::HelloPrx> _objs; // List of per-session allocated hello objects.
bool _destroy;
};
-
typedef IceUtil::Handle<SessionI> SessionIPtr;
#endif