summaryrefslogtreecommitdiff
path: root/java/src/Ice/CommunicatorI.java
blob: 53d1923d900a99e3c31eff77386c53959e46ae35 (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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
// **********************************************************************
//
// Copyright (c) 2001
// Mutable Realms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************

package Ice;

class CommunicatorI extends LocalObjectImpl implements Communicator
{
    public synchronized void
    destroy()
    {
        if(!_destroyed) // Don't destroy twice.
        {
	    _destroyed = true;

            _instance.objectAdapterFactory().shutdown();
            _instance.destroy();

	    _serverThreadPool = null;
        }
    }

    public void
    shutdown()
    {
	//
	// No mutex locking here!
	//
	if(_serverThreadPool != null)
	{
	    _serverThreadPool.initiateShutdown();
	}
    }

    public void
    waitForShutdown()
    {
        //
        // No mutex locking here, otherwise the communicator is blocked
        // while waiting for shutdown.
        //
	if(_serverThreadPool != null)
	{
	    _serverThreadPool.waitUntilFinished();
	}
    }

    public synchronized Ice.ObjectPrx
    stringToProxy(String s)
    {
        if(_destroyed)
        {
            throw new CommunicatorDestroyedException();
        }
        return _instance.proxyFactory().stringToProxy(s);
    }

    public synchronized String
    proxyToString(Ice.ObjectPrx proxy)
    {
        if(_destroyed)
        {
            throw new CommunicatorDestroyedException();
        }
        return _instance.proxyFactory().proxyToString(proxy);
    }

    public synchronized ObjectAdapter
    createObjectAdapter(String name)
    {
        if(_destroyed)
        {
            throw new CommunicatorDestroyedException();
        }

	ObjectAdapter adapter;

	if(name.length() == 0)
	{
	    adapter = _instance.objectAdapterFactory().createObjectAdapter("", "", "");
	}
	else
	{
	    String id = _instance.properties().getProperty(name + ".AdapterId");

	    String endpts = _instance.properties().getProperty(name + ".Endpoints");

	    adapter = _instance.objectAdapterFactory().createObjectAdapter(name, endpts, id);

	    String router = _instance.properties().getProperty("Ice.Adapter." + name + ".Router");
	    if(router.length() > 0)
	    {
		adapter.addRouter(RouterPrxHelper.uncheckedCast(_instance.proxyFactory().stringToProxy(router)));
	    }

	    String locator = _instance.properties().getProperty("Ice.Adapter." + name + ".Locator");
	    if(locator.length() > 0)
	    {
		adapter.setLocator(LocatorPrxHelper.uncheckedCast(_instance.proxyFactory().stringToProxy(locator)));
	    }
	    else
	    {
		adapter.setLocator(_instance.referenceFactory().getDefaultLocator());
	    }
	}

	if(_serverThreadPool == null) // Lazy initialization of _serverThreadPool.
	{
	    _serverThreadPool = _instance.serverThreadPool();
	}

        return adapter;
    }

    public synchronized ObjectAdapter
    createObjectAdapterWithEndpoints(String name, String endpoints)
    {
	getProperties().setProperty(name + ".Endpoints", endpoints);
	return createObjectAdapter(name);
    }

    public synchronized void
    addObjectFactory(ObjectFactory factory, String id)
    {
        if(_destroyed)
        {
            throw new CommunicatorDestroyedException();
        }
        _instance.servantFactoryManager().add(factory, id);
    }

    public synchronized void
    removeObjectFactory(String id)
    {
        if(_destroyed)
        {
            throw new CommunicatorDestroyedException();
        }
        _instance.servantFactoryManager().remove(id);
    }

    public synchronized ObjectFactory
    findObjectFactory(String id)
    {
        if(_destroyed)
        {
            throw new CommunicatorDestroyedException();
        }
        return _instance.servantFactoryManager().find(id);
    }

    public synchronized void
    addUserExceptionFactory(UserExceptionFactory factory, String id)
    {
        if(_destroyed)
        {
            throw new CommunicatorDestroyedException();
        }
        _instance.userExceptionFactoryManager().add(factory, id);
    }

    public synchronized void
    removeUserExceptionFactory(String id)
    {
        if(_destroyed)
        {
            throw new CommunicatorDestroyedException();
        }
        _instance.userExceptionFactoryManager().remove(id);
    }

    public synchronized UserExceptionFactory
    findUserExceptionFactory(String id)
    {
        if(_destroyed)
        {
            throw new CommunicatorDestroyedException();
        }
        return _instance.userExceptionFactoryManager().find(id);
    }

    public synchronized Properties
    getProperties()
    {
        if(_destroyed)
        {
            throw new CommunicatorDestroyedException();
        }
        return _instance.properties();
    }

    public synchronized Logger
    getLogger()
    {
        if(_destroyed)
        {
            throw new CommunicatorDestroyedException();
        }
        return _instance.logger();
    }

    public synchronized void
    setLogger(Logger logger)
    {
        if(_destroyed)
        {
            throw new CommunicatorDestroyedException();
        }
        _instance.logger(logger);
    }

    public void
    setDefaultRouter(RouterPrx router)
    {
        _instance.referenceFactory().setDefaultRouter(router);
    }

    public void
    setDefaultLocator(LocatorPrx locator)
    {
        _instance.referenceFactory().setDefaultLocator(locator);
    }

    public PluginManager
    getPluginManager()
    {
        return null;
    }

    CommunicatorI(StringSeqHolder args, Properties properties)
    {
	_destroyed = false;
        _instance = new IceInternal.Instance(this, args, properties);
    }

    protected void
    finalize()
        throws Throwable
    {
        if(!_destroyed)
        {
            _instance.logger().warning("Ice::Communicator::destroy() has not been called");
        }

        super.finalize();
    }

    //
    // Certain initialization tasks need to be completed after the
    // constructor.
    //
    void
    finishSetup(StringSeqHolder args)
    {
        _instance.finishSetup(args);
    }

    //
    // For use by Util.getInstance()
    //
    IceInternal.Instance
    getInstance()
    {
        return _instance;
    }

    private boolean _destroyed;
    private IceInternal.Instance _instance;

    //
    // We need _serverThreadPool directly in CommunicatorI. That's
    // because the shutdown() operation is signal-safe, and thus must
    // not access any mutex locks or _instance. It may only access
    // _serverThreadPool->initiateShutdown(), which is signal-safe as
    // well.
    //
    private IceInternal.ThreadPool _serverThreadPool;
}