summaryrefslogtreecommitdiff
path: root/cpp/src/IceGrid/AdapterCache.cpp
diff options
context:
space:
mode:
authorBenoit Foucher <benoit@zeroc.com>2005-07-08 13:47:30 +0000
committerBenoit Foucher <benoit@zeroc.com>2005-07-08 13:47:30 +0000
commit99894938dbde9a0bb10fc1998d9863cae52b8977 (patch)
tree5b68e52e9a62792f11d8a4e2c844d394cd39f496 /cpp/src/IceGrid/AdapterCache.cpp
parentFixed Ice interoperability issue (diff)
downloadice-99894938dbde9a0bb10fc1998d9863cae52b8977.tar.bz2
ice-99894938dbde9a0bb10fc1998d9863cae52b8977.tar.xz
ice-99894938dbde9a0bb10fc1998d9863cae52b8977.zip
More adapter replication changes.
Diffstat (limited to 'cpp/src/IceGrid/AdapterCache.cpp')
-rw-r--r--cpp/src/IceGrid/AdapterCache.cpp106
1 files changed, 106 insertions, 0 deletions
diff --git a/cpp/src/IceGrid/AdapterCache.cpp b/cpp/src/IceGrid/AdapterCache.cpp
new file mode 100644
index 00000000000..6622ab6c182
--- /dev/null
+++ b/cpp/src/IceGrid/AdapterCache.cpp
@@ -0,0 +1,106 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#include <IceGrid/AdapterCache.h>
+#include <IceGrid/NodeSessionI.h>
+#include <IceGrid/ServerCache.h>
+
+using namespace std;
+using namespace IceGrid;
+
+AdapterEntryPtr
+AdapterCache::get(const string& id, bool create) const
+{
+ Lock sync(*this);
+ AdapterCache& self = const_cast<AdapterCache&>(*this);
+ AdapterEntryPtr entry = self.getImpl(id, create);
+ if(!entry)
+ {
+ AdapterNotExistException ex;
+ ex.id = id;
+ throw ex;
+ }
+ return entry;
+}
+
+AdapterEntry::AdapterEntry(Cache<string, AdapterEntry>& cache, const std::string& id) :
+ _cache(cache),
+ _id(id),
+ _replicated(false)
+{
+}
+
+void
+AdapterEntry::enableReplication(LoadBalancingPolicy policy)
+{
+ Lock sync(*this);
+ _replicated = true;
+ _loadBalancing = policy;
+}
+
+void
+AdapterEntry::disableReplication()
+{
+ _replicated = false;
+}
+
+void
+AdapterEntry::addServer(const ServerEntryPtr& entry)
+{
+ Lock sync(*this);
+ assert(_replicated || _servers.empty());
+ _servers.insert(make_pair(entry->getName(), entry));
+}
+
+void
+AdapterEntry::removeServer(const ServerEntryPtr& entry)
+{
+ bool remove = false;
+ {
+ Lock sync(*this);
+ _servers.erase(entry->getName());
+ remove = _servers.empty();
+ }
+ if(remove)
+ {
+ _cache.remove(_id);
+ }
+}
+
+AdapterPrx
+AdapterEntry::getProxy(const string& serverId) const
+{
+ Lock sync(*this);
+ if(!_replicated)
+ {
+ return _servers.begin()->second->getAdapter(_id);
+ }
+ else
+ {
+ //
+ // TODO: implement load balancing strategies. This is also not really correct to use the first adapter
+ // if the server id is empty this could allow a server to always override the first server endpoints.
+ //
+ map<string, ServerEntryPtr>::const_iterator p = serverId.empty() ? _servers.begin() : _servers.find(serverId);
+ if(p == _servers.end())
+ {
+ AdapterNotExistException ex;
+ ex.id = _id;
+ throw ex;
+ }
+ return p->second->getAdapter(_id);
+ }
+}
+
+bool
+AdapterEntry::canRemove()
+{
+ Lock sync(*this);
+ return _servers.empty();
+}