summaryrefslogtreecommitdiff
path: root/js/src/Ice/LocatorManager.js
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2014-03-19 12:45:55 -0700
committerMark Spruiell <mes@zeroc.com>2014-03-19 12:45:55 -0700
commitcdcffbcc3c3c052afdeb772ff0167e7a90b525bb (patch)
tree4f16ee41ef7d33394c44e9db81e4d6cd89908250 /js/src/Ice/LocatorManager.js
parentfixing testicedist.py for 5487 (diff)
downloadice-cdcffbcc3c3c052afdeb772ff0167e7a90b525bb.tar.bz2
ice-cdcffbcc3c3c052afdeb772ff0167e7a90b525bb.tar.xz
ice-cdcffbcc3c3c052afdeb772ff0167e7a90b525bb.zip
merging javascript branch
Diffstat (limited to 'js/src/Ice/LocatorManager.js')
-rw-r--r--js/src/Ice/LocatorManager.js88
1 files changed, 88 insertions, 0 deletions
diff --git a/js/src/Ice/LocatorManager.js b/js/src/Ice/LocatorManager.js
new file mode 100644
index 00000000000..e7389b844af
--- /dev/null
+++ b/js/src/Ice/LocatorManager.js
@@ -0,0 +1,88 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2014 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.
+//
+// **********************************************************************
+
+(function(global){
+ require("Ice/Class");
+ require("Ice/HashMap");
+ require("Ice/LocatorInfo");
+ require("Ice/LocatorTable");
+ require("Ice/Locator");
+
+ var Ice = global.Ice || {};
+
+ var HashMap = Ice.HashMap;
+ var LocatorInfo = Ice.LocatorInfo;
+ var LocatorTable = Ice.LocatorTable;
+ var LocatorPrx = Ice.LocatorPrx;
+
+ var LocatorManager = Ice.Class({
+ __init__: function(properties)
+ {
+ this._background = properties.getPropertyAsInt("Ice.BackgroundLocatorCacheUpdates") > 0;
+
+ this._table = new HashMap(); // Map<Ice.LocatorPrx, LocatorInfo>
+ this._table.keyComparator = HashMap.compareEquals;
+ this._locatorTables = new HashMap(); // Map<Ice.Identity, LocatorTable>
+ this._locatorTables.keyComparator = HashMap.compareEquals;
+ },
+ destroy: function()
+ {
+ for(var e = this._table.entries; e !== null; e = e.next)
+ {
+ e.value.destroy();
+ }
+ this._table.clear();
+ this._locatorTables.clear();
+ },
+ //
+ // Returns locator info for a given locator. Automatically creates
+ // the locator info if it doesn't exist yet.
+ //
+ find: function(loc)
+ {
+ if(loc === null)
+ {
+ return null;
+ }
+
+ //
+ // The locator can't be located.
+ //
+ var locator = LocatorPrx.uncheckedCast(loc.ice_locator(null));
+
+ //
+ // TODO: reap unused locator info objects?
+ //
+
+ var info = this._table.get(locator);
+ if(info === undefined)
+ {
+ //
+ // Rely on locator identity for the adapter table. We want to
+ // have only one table per locator (not one per locator
+ // proxy).
+ //
+ var table = this._locatorTables.get(locator.ice_getIdentity());
+ if(table === undefined)
+ {
+ table = new LocatorTable();
+ this._locatorTables.set(locator.ice_getIdentity(), table);
+ }
+
+ info = new LocatorInfo(locator, table, this._background);
+ this._table.set(locator, info);
+ }
+
+ return info;
+ }
+ });
+
+ Ice.LocatorManager = LocatorManager;
+ global.Ice = Ice;
+}(typeof (global) === "undefined" ? window : global));