blob: 3a3589a97946d3cc3c6587d3f6f1f4cad776d5a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
const Ice = require("../Ice/ModuleRegistry").Ice;
Ice._ModuleRegistry.require(module, ["../Ice/HashMap", "../Ice/RouterInfo", "../Ice/Router"]);
const HashMap = Ice.HashMap;
const RouterInfo = Ice.RouterInfo;
const RouterPrx = Ice.RouterPrx;
class RouterManager
{
constructor()
{
this._table = new HashMap(HashMap.compareEquals); // Map<Ice.RouterPrx, RouterInfo>
}
destroy()
{
for(const router of this._table.values())
{
router.destroy();
}
this._table.clear();
}
//
// Returns router info for a given router. Automatically creates
// the router info if it doesn't exist yet.
//
find(rtr)
{
if(rtr === null)
{
return null;
}
//
// The router cannot be routed.
//
const router = RouterPrx.uncheckedCast(rtr.ice_router(null));
let info = this._table.get(router);
if(info === undefined)
{
info = new RouterInfo(router);
this._table.set(router, info);
}
return info;
}
erase(rtr)
{
let info = null;
if(rtr !== null)
{
// The router cannot be routed.
const router = RouterPrx.uncheckedCast(rtr.ice_router(null));
info = this._table.get(router);
this._table.delete(router);
}
return info;
}
}
Ice.RouterManager = RouterManager;
module.exports.Ice = Ice;
|