~ubuntu-branches/ubuntu/quantal/zeroc-ice/quantal

« back to all changes in this revision

Viewing changes to java/src/IceInternal/ServantManager.java

  • Committer: Bazaar Package Importer
  • Author(s): Cleto Martin Angelina
  • Date: 2011-04-25 18:44:24 UTC
  • mfrom: (6.1.14 sid)
  • Revision ID: james.westby@ubuntu.com-20110425184424-sep9i9euu434vq4c
Tags: 3.4.1-7
* Bug fix: "libdb5.1-java.jar was renamed to db.jar", thanks to Ondřej
  Surý (Closes: #623555).
* Bug fix: "causes noise in php5", thanks to Jayen Ashar (Closes:
  #623533).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// **********************************************************************
2
2
//
3
 
// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
 
3
// Copyright (c) 2003-2010 ZeroC, Inc. All rights reserved.
4
4
//
5
5
// This copy of Ice is licensed to you under the terms described in the
6
6
// ICE_LICENSE file included in this distribution.
45
45
        m.put(facet, servant);
46
46
    }
47
47
 
 
48
    public synchronized void
 
49
    addDefaultServant(Ice.Object servant, String category)
 
50
    {
 
51
        assert(_instance != null); // Must not be called after destruction
 
52
 
 
53
        Ice.Object obj = _defaultServantMap.get(category);
 
54
        if(obj != null)
 
55
        {
 
56
            Ice.AlreadyRegisteredException ex = new Ice.AlreadyRegisteredException();
 
57
            ex.kindOfObject = "default servant";
 
58
            ex.id = category;
 
59
            throw ex;
 
60
        }
 
61
 
 
62
        _defaultServantMap.put(category, servant);
 
63
    }
 
64
 
48
65
    public synchronized Ice.Object
49
66
    removeServant(Ice.Identity ident, String facet)
50
67
    {
76
93
        return obj;
77
94
    }
78
95
 
 
96
    public synchronized Ice.Object
 
97
    removeDefaultServant(String category)
 
98
    {
 
99
        assert(_instance != null); // Must not be called after destruction.
 
100
 
 
101
        Ice.Object obj = _defaultServantMap.get(category);
 
102
        if(obj == null)
 
103
        {
 
104
            Ice.NotRegisteredException ex = new Ice.NotRegisteredException();
 
105
            ex.kindOfObject = "default servant";
 
106
            ex.id = category;
 
107
            throw ex;
 
108
        }
 
109
 
 
110
        _defaultServantMap.remove(category);
 
111
        return obj;
 
112
    }
 
113
 
79
114
    public synchronized java.util.Map<String, Ice.Object>
80
115
    removeAllFacets(Ice.Identity ident)
81
116
    {
113
148
 
114
149
        java.util.Map<String, Ice.Object> m = _servantMapMap.get(ident);
115
150
        Ice.Object obj = null;
116
 
        if(m != null)
 
151
        if(m == null)
 
152
        {
 
153
            obj = _defaultServantMap.get(ident.category);
 
154
            if(obj == null)
 
155
            {
 
156
                obj = _defaultServantMap.get("");
 
157
            }
 
158
        }
 
159
        else
117
160
        {
118
161
            obj = m.get(facet);
119
162
        }
121
164
        return obj;
122
165
    }
123
166
 
 
167
    public synchronized Ice.Object
 
168
    findDefaultServant(String category)
 
169
    {
 
170
        assert(_instance != null); // Must not be called after destruction.
 
171
 
 
172
        return _defaultServantMap.get(category);
 
173
    }
 
174
 
124
175
    public synchronized java.util.Map<String, Ice.Object>
125
176
    findAllFacets(Ice.Identity ident)
126
177
    {
176
227
    }
177
228
 
178
229
    public synchronized Ice.ServantLocator
 
230
    removeServantLocator(String category)
 
231
    {
 
232
        Ice.ServantLocator l = null;
 
233
        assert(_instance != null); // Must not be called after destruction.
 
234
    
 
235
        l = _locatorMap.remove(category);
 
236
        if(l == null)
 
237
        {
 
238
            Ice.NotRegisteredException ex = new Ice.NotRegisteredException();
 
239
            ex.id = IceUtilInternal.StringUtil.escapeString(category, "");
 
240
            ex.kindOfObject = "servant locator";
 
241
            throw ex;
 
242
        }
 
243
        return l;
 
244
    }
 
245
 
 
246
    public synchronized Ice.ServantLocator
179
247
    findServantLocator(String category)
180
248
    {
181
249
        //
199
267
        _adapterName = adapterName;
200
268
    }
201
269
 
202
 
    protected void
203
 
    finalize()
204
 
        throws Throwable
205
 
    {
206
 
        //
207
 
        // Don't check whether destroy() has been called. It might have
208
 
        // not been called if the associated object adapter was not
209
 
        // properly deactivated.
210
 
        //
211
 
        //IceUtilInternal.Assert.FinalizerAssert(_instance == null);
212
 
        
213
 
        super.finalize();
214
 
    }
215
 
 
216
270
    //
217
271
    // Only for use by Ice.ObjectAdapterI.
218
272
    //
219
 
    public synchronized void
 
273
    public void
220
274
    destroy()
221
275
    {
222
 
        assert(_instance != null); // Must not be called after destruction.
 
276
        java.util.Map<String, Ice.ServantLocator> locatorMap = new java.util.HashMap<String, Ice.ServantLocator>();
 
277
        Ice.Logger logger = null;
 
278
        synchronized(this)
 
279
        {
 
280
            assert(_instance != null); // Must not be called after destruction.
 
281
            logger = _instance.initializationData().logger;
 
282
            _servantMapMap.clear();
 
283
           
 
284
            locatorMap.putAll(_locatorMap);
 
285
            _locatorMap.clear();
 
286
            _instance = null;
 
287
        }
223
288
 
224
 
        _servantMapMap.clear();
225
 
        
226
 
        java.util.Iterator<java.util.Map.Entry<String, Ice.ServantLocator> > p = _locatorMap.entrySet().iterator();
227
 
        while(p.hasNext())
 
289
        for(java.util.Map.Entry<String, Ice.ServantLocator> p : locatorMap.entrySet())
228
290
        {
229
 
            java.util.Map.Entry<String, Ice.ServantLocator> e = p.next();
230
 
            Ice.ServantLocator locator = e.getValue();
 
291
            Ice.ServantLocator locator = p.getValue();
231
292
            try
232
293
            {
233
 
                locator.deactivate(e.getKey());
 
294
                locator.deactivate(p.getKey());
234
295
            }
235
296
            catch(java.lang.Exception ex)
236
297
            {
237
 
                java.io.StringWriter sw = new java.io.StringWriter();
238
 
                java.io.PrintWriter pw = new java.io.PrintWriter(sw);
239
 
                ex.printStackTrace(pw);
240
 
                pw.flush();
241
298
                String s = "exception during locator deactivation:\n" + "object adapter: `" + _adapterName + "'\n" +
242
 
                    "locator category: `" + e.getKey() + "'\n" + sw.toString();
 
299
                    "locator category: `" + p.getKey() + "'\n" + Ex.toString(ex);
243
300
                _instance.initializationData().logger.error(s);
244
301
            }
245
302
        }
246
 
 
247
 
        _locatorMap.clear();
248
 
 
249
 
        _instance = null;
250
303
    }
251
304
 
252
305
    private Instance _instance;
253
306
    final private String _adapterName;
254
307
    private java.util.Map<Ice.Identity, java.util.Map<String, Ice.Object> > _servantMapMap =
255
308
        new java.util.HashMap<Ice.Identity, java.util.Map<String, Ice.Object> >();
 
309
    private java.util.Map<String, Ice.Object> _defaultServantMap = new java.util.HashMap<String, Ice.Object>();
256
310
    private java.util.Map<String, Ice.ServantLocator> _locatorMap = new java.util.HashMap<String, Ice.ServantLocator>();
257
311
}