1 // **********************************************************************
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
8 // **********************************************************************
12 public final class ServantManager
14 public synchronized void
15 addServant(Ice
.Object servant
, Ice
.Identity ident
, String facet
)
17 assert(_instance
!= null); // Must not be called after destruction.
24 java
.util
.Map
<String
, Ice
.Object
> m
= _servantMapMap
.get(ident
);
27 m
= new java
.util
.HashMap
<String
, Ice
.Object
>();
28 _servantMapMap
.put(ident
, m
);
32 if(m
.containsKey(facet
))
34 Ice
.AlreadyRegisteredException ex
= new Ice
.AlreadyRegisteredException();
35 ex
.id
= _instance
.identityToString(ident
);
36 ex
.kindOfObject
= "servant";
37 if(facet
.length() > 0)
39 ex
.id
+= " -f " + IceUtilInternal
.StringUtil
.escapeString(facet
, "");
45 m
.put(facet
, servant
);
48 public synchronized void
49 addDefaultServant(Ice
.Object servant
, String category
)
51 assert(_instance
!= null); // Must not be called after destruction
53 Ice
.Object obj
= _defaultServantMap
.get(category
);
56 Ice
.AlreadyRegisteredException ex
= new Ice
.AlreadyRegisteredException();
57 ex
.kindOfObject
= "default servant";
62 _defaultServantMap
.put(category
, servant
);
65 public synchronized Ice
.Object
66 removeServant(Ice
.Identity ident
, String facet
)
68 assert(_instance
!= null); // Must not be called after destruction.
75 java
.util
.Map
<String
, Ice
.Object
> m
= _servantMapMap
.get(ident
);
76 Ice
.Object obj
= null;
77 if(m
== null || (obj
= m
.remove(facet
)) == null)
79 Ice
.NotRegisteredException ex
= new Ice
.NotRegisteredException();
80 ex
.id
= _instance
.identityToString(ident
);
81 ex
.kindOfObject
= "servant";
82 if(facet
.length() > 0)
84 ex
.id
+= " -f " + IceUtilInternal
.StringUtil
.escapeString(facet
, "");
91 _servantMapMap
.remove(ident
);
96 public synchronized Ice
.Object
97 removeDefaultServant(String category
)
99 assert(_instance
!= null); // Must not be called after destruction.
101 Ice
.Object obj
= _defaultServantMap
.get(category
);
104 Ice
.NotRegisteredException ex
= new Ice
.NotRegisteredException();
105 ex
.kindOfObject
= "default servant";
110 _defaultServantMap
.remove(category
);
114 public synchronized java
.util
.Map
<String
, Ice
.Object
>
115 removeAllFacets(Ice
.Identity ident
)
117 assert(_instance
!= null); // Must not be called after destruction.
119 java
.util
.Map
<String
, Ice
.Object
> m
= _servantMapMap
.get(ident
);
122 Ice
.NotRegisteredException ex
= new Ice
.NotRegisteredException();
123 ex
.id
= _instance
.identityToString(ident
);
124 ex
.kindOfObject
= "servant";
128 _servantMapMap
.remove(ident
);
133 public synchronized Ice
.Object
134 findServant(Ice
.Identity ident
, String facet
)
137 // This assert is not valid if the adapter dispatch incoming
138 // requests from bidir connections. This method might be called if
139 // requests are received over the bidir connection after the
140 // adapter was deactivated.
142 //assert(_instance != null); // Must not be called after destruction.
149 java
.util
.Map
<String
, Ice
.Object
> m
= _servantMapMap
.get(ident
);
150 Ice
.Object obj
= null;
153 obj
= _defaultServantMap
.get(ident
.category
);
156 obj
= _defaultServantMap
.get("");
167 public synchronized Ice
.Object
168 findDefaultServant(String category
)
170 assert(_instance
!= null); // Must not be called after destruction.
172 return _defaultServantMap
.get(category
);
175 public synchronized java
.util
.Map
<String
, Ice
.Object
>
176 findAllFacets(Ice
.Identity ident
)
178 assert(_instance
!= null); // Must not be called after destruction.
180 java
.util
.Map
<String
, Ice
.Object
> m
= _servantMapMap
.get(ident
);
183 return new java
.util
.HashMap
<String
, Ice
.Object
>(m
);
186 return new java
.util
.HashMap
<String
, Ice
.Object
>();
189 public synchronized boolean
190 hasServant(Ice
.Identity ident
)
193 // This assert is not valid if the adapter dispatch incoming
194 // requests from bidir connections. This method might be called if
195 // requests are received over the bidir connection after the
196 // adapter was deactivated.
198 //assert(_instance != null); // Must not be called after destruction.
200 java
.util
.Map
<String
, Ice
.Object
> m
= _servantMapMap
.get(ident
);
207 assert(!m
.isEmpty());
212 public synchronized void
213 addServantLocator(Ice
.ServantLocator locator
, String category
)
215 assert(_instance
!= null); // Must not be called after destruction.
217 Ice
.ServantLocator l
= _locatorMap
.get(category
);
220 Ice
.AlreadyRegisteredException ex
= new Ice
.AlreadyRegisteredException();
221 ex
.id
= IceUtilInternal
.StringUtil
.escapeString(category
, "");
222 ex
.kindOfObject
= "servant locator";
226 _locatorMap
.put(category
, locator
);
229 public synchronized Ice
.ServantLocator
230 removeServantLocator(String category
)
232 Ice
.ServantLocator l
= null;
233 assert(_instance
!= null); // Must not be called after destruction.
235 l
= _locatorMap
.remove(category
);
238 Ice
.NotRegisteredException ex
= new Ice
.NotRegisteredException();
239 ex
.id
= IceUtilInternal
.StringUtil
.escapeString(category
, "");
240 ex
.kindOfObject
= "servant locator";
246 public synchronized Ice
.ServantLocator
247 findServantLocator(String category
)
250 // This assert is not valid if the adapter dispatch incoming
251 // requests from bidir connections. This method might be called if
252 // requests are received over the bidir connection after the
253 // adapter was deactivated.
255 //assert(_instance != null); // Must not be called after destruction.
257 return _locatorMap
.get(category
);
261 // Only for use by Ice.ObjectAdatperI.
264 ServantManager(Instance instance
, String adapterName
)
266 _instance
= instance
;
267 _adapterName
= adapterName
;
271 // Only for use by Ice.ObjectAdapterI.
276 java
.util
.Map
<String
, Ice
.ServantLocator
> locatorMap
= new java
.util
.HashMap
<String
, Ice
.ServantLocator
>();
277 Ice
.Logger logger
= null;
280 assert(_instance
!= null); // Must not be called after destruction.
281 logger
= _instance
.initializationData().logger
;
282 _servantMapMap
.clear();
284 locatorMap
.putAll(_locatorMap
);
289 for(java
.util
.Map
.Entry
<String
, Ice
.ServantLocator
> p
: locatorMap
.entrySet())
291 Ice
.ServantLocator locator
= p
.getValue();
294 locator
.deactivate(p
.getKey());
296 catch(java
.lang
.Exception ex
)
298 String s
= "exception during locator deactivation:\n" + "object adapter: `" + _adapterName
+ "'\n" +
299 "locator category: `" + p
.getKey() + "'\n" + Ex
.toString(ex
);
305 private Instance _instance
;
306 final private String _adapterName
;
307 private java
.util
.Map
<Ice
.Identity
, java
.util
.Map
<String
, Ice
.Object
> > _servantMapMap
=
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
>();
310 private java
.util
.Map
<String
, Ice
.ServantLocator
> _locatorMap
= new java
.util
.HashMap
<String
, Ice
.ServantLocator
>();