summaryrefslogtreecommitdiff
path: root/js/src/Ice/Communicator.js
blob: a4f172d9a641f5be74a78802781b16050745ee13 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// **********************************************************************
//
// Copyright (c) 2003-2016 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.
//
// **********************************************************************

var Ice = require("../Ice/ModuleRegistry").Ice;
Ice.__M.require(module,
    [
        "../Ice/Class",
        "../Ice/Instance",
        "../Ice/Promise",
        "../Ice/UUID",
        "../Ice/AsyncResultBase"
    ]);

var Instance = Ice.Instance;
var Promise = Ice.Promise;

//
// Ice.Communicator
//
var Communicator = Ice.Class({
    __init__: function(initData)
    {
        this._instance = new Instance(initData);
    },
    //
    // Certain initialization tasks need to be completed after the
    // constructor.
    //
    finishSetup: function(promise)
    {
        this._instance.finishSetup(this, promise);
    },
    destroy: function()
    {
        return this._instance.destroy();
    },
    shutdown: function()
    {
        this._instance.objectAdapterFactory().shutdown();
    },
    waitForShutdown: function()
    {
        return this._instance.objectAdapterFactory().waitForShutdown();
    },
    isShutdown: function()
    {
        return this._instance.objectAdapterFactory().isShutdown();
    },
    stringToProxy: function(s)
    {
        return this._instance.proxyFactory().stringToProxy(s);
    },
    proxyToString: function(proxy)
    {
        return this._instance.proxyFactory().proxyToString(proxy);
    },
    propertyToProxy: function(s)
    {
        return this._instance.proxyFactory().propertyToProxy(s);
    },
    proxyToProperty: function(proxy, prefix)
    {
        return this._instance.proxyFactory().proxyToProperty(proxy, prefix);
    },
    stringToIdentity: function(s)
    {
        return this._instance.stringToIdentity(s);
    },
    identityToString: function(ident)
    {
        return this._instance.identityToString(ident);
    },
    createObjectAdapter: function(name)
    {
        var promise = new Ice.AsyncResultBase(this, "createObjectAdapter", this, null, null);
        this._instance.objectAdapterFactory().createObjectAdapter(name, null, promise);
        return promise;
    },
    createObjectAdapterWithEndpoints: function(name, endpoints)
    {
        if(name.length === 0)
        {
            name = Ice.generateUUID();
        }

        this.getProperties().setProperty(name + ".Endpoints", endpoints);
        var promise = new Ice.AsyncResultBase(this, "createObjectAdapterWithEndpoints", this, null, null);
        this._instance.objectAdapterFactory().createObjectAdapter(name, null, promise);
        return promise;
    },
    createObjectAdapterWithRouter: function(name, router)
    {
        if(name.length === 0)
        {
            name = Ice.generateUUID();
        }

        var promise = new Ice.AsyncResultBase(this, "createObjectAdapterWithRouter", this, null, null);

        //
        // We set the proxy properties here, although we still use the proxy supplied.
        //
        var properties = this.proxyToProperty(router, name + ".Router");
        for(var e = properties.entries; e !== null; e = e.next)
        {
            this.getProperties().setProperty(e.key, e.value);
        }

        this._instance.objectAdapterFactory().createObjectAdapter(name, router, promise);
        return promise;
    },
    addObjectFactory: function(factory, id)
    {
        this._instance.servantFactoryManager().add(factory, id);
    },
    findObjectFactory: function(id)
    {
        return this._instance.servantFactoryManager().find(id);
    },
    getImplicitContext: function()
    {
        return this._instance.getImplicitContext();
    },
    getProperties: function()
    {
        return this._instance.initializationData().properties;
    },
    getLogger: function()
    {
        return this._instance.initializationData().logger;
    },
    getDefaultRouter: function()
    {
        return this._instance.referenceFactory().getDefaultRouter();
    },
    setDefaultRouter: function(router)
    {
        this._instance.setDefaultRouter(router);
    },
    getDefaultLocator: function()
    {
        return this._instance.referenceFactory().getDefaultLocator();
    },
    setDefaultLocator: function(locator)
    {
        this._instance.setDefaultLocator(locator);
    },
    flushBatchRequests: function()
    {
        return this._instance.outgoingConnectionFactory().flushAsyncBatchRequests();
    }
});

Object.defineProperty(Communicator.prototype, "instance", {
    get: function() { return this._instance; }
});

Ice.Communicator = Communicator;
module.exports.Ice = Ice;