1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.util; |
2 |
> |
package uk.org.iscream.cms.server.componentmanager; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
|
import org.omg.CORBA.ORB; |
6 |
|
import org.omg.CosNaming.*; |
7 |
|
import org.omg.PortableServer.*; |
8 |
< |
import uk.ac.ukc.iscream.core.*; |
8 |
> |
import uk.org.iscream.cms.server.core.*; |
9 |
> |
import uk.org.iscream.cms.server.util.*; |
10 |
|
|
11 |
|
/** |
12 |
|
* This class returns references for global system objects. |
34 |
|
//---STATIC METHODS--- |
35 |
|
|
36 |
|
/** |
36 |
– |
* TO BE REMOVED ONCE CODE TIDY HAS COMPLETED! |
37 |
– |
* @deprecated should no longer use this method to construct a refman |
38 |
– |
*/ |
39 |
– |
public static ReferenceManager init(String[] args, String name) throws AlreadyInitialisedException { |
40 |
– |
System.out.println("LEGACY CALL - SORT THIS OUT! name=" + name); |
41 |
– |
if (_instance != null) { |
42 |
– |
throw new AlreadyInitialisedException("init has already been called"); |
43 |
– |
} |
44 |
– |
_instance = new ReferenceManager(args, name); |
45 |
– |
return _instance; |
46 |
– |
} |
47 |
– |
|
48 |
– |
/** |
37 |
|
* This returns a reference to the single instance of the |
38 |
|
* ReferenceManager. |
39 |
|
* |
42 |
|
* |
43 |
|
* @return a reference to the ReferenceManager |
44 |
|
*/ |
45 |
< |
public static ReferenceManager getInstance() { |
45 |
> |
public synchronized static ReferenceManager getInstance() { |
46 |
|
if (_instance == null) { |
47 |
|
_instance = new ReferenceManager(); |
48 |
|
} |
58 |
|
private ReferenceManager() { |
59 |
|
_orb = ORB.init(new String[] {}, null); |
60 |
|
} |
73 |
– |
|
74 |
– |
/** |
75 |
– |
* TO BE REMOVED ONCE CODE TIDY HAS COMPLETED! |
76 |
– |
* @deprecated should no longer use this method to construct a refman |
77 |
– |
*/ |
78 |
– |
private ReferenceManager(String[] args, String name) { |
79 |
– |
System.out.println("LEGACY CALL - SORT THIS OUT! name=" + name); |
80 |
– |
_orb = ORB.init(args, null); |
81 |
– |
_name = name; |
82 |
– |
} |
61 |
|
|
62 |
|
//---PUBLIC METHODS--- |
63 |
|
|
81 |
|
dieWithError("\nCRITICAL:Invalid Name - when resolving reference to " + name + "!\n" + |
82 |
|
" Please check with your CORBA naming service provider."); |
83 |
|
} catch (org.omg.CosNaming.NamingContextPackage.NotFound e) { |
84 |
< |
dieWithError("\nCRITICAL:Not Found - when resolving reference to " + name + "!\n" + |
84 |
> |
recoverWithError("\nCRITICAL:Not Found - when resolving reference to " + name + "!\n" + |
85 |
|
" Please check that this component is running."); |
86 |
|
} |
87 |
|
return objRef; |
111 |
|
dieWithError("\nCRITICAL:Naming Service Cannot Proceed - when binding " + name + "!\n" + |
112 |
|
" Please check with your CORBA naming service provider."); |
113 |
|
} catch (org.omg.CosNaming.NamingContextPackage.NotFound e) { |
114 |
< |
dieWithError("\nCRITICAL:Naming Service Not Found - when binding " + name + "!\n" + |
114 |
> |
recoverWithError("\nCRITICAL:Naming Service Not Found - when binding " + name + "!\n" + |
115 |
|
" Please check with your CORBA naming service provider."); |
116 |
|
} catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound e) { |
117 |
|
dieWithError("\nCRITICAL:Already Bound - when binding " + name + "!\n" + |
136 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
137 |
|
* method to provide clean logging (every class should have this). |
138 |
|
* |
139 |
< |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
139 |
> |
* This uses the uk.org.iscream.cms.server.util.NameFormat class |
140 |
|
* to format the toString() |
141 |
|
* |
142 |
|
* @return the name of this class and its CVS revision |
154 |
|
* If there are any CORBA errors this method is called with the |
155 |
|
* error message. |
156 |
|
* |
157 |
+ |
* The exception this throws is generic to CORBA communication |
158 |
+ |
* problems, this is a Runtime exception and is typically only |
159 |
+ |
* explicitly caught in the ComponentManager for the current VM |
160 |
+ |
* The ComponentManager can then decide what course of action to |
161 |
+ |
* take. |
162 |
+ |
* |
163 |
+ |
* Also, if it can, it will log the message with the logger. |
164 |
+ |
* |
165 |
+ |
* @param message the error message to die with |
166 |
+ |
*/ |
167 |
+ |
private void recoverWithError(String message) throws ComponentCORBAException { |
168 |
+ |
if (_logger != null) { |
169 |
+ |
_logger.write(toString(), Logger.WARNING, "component CORBA error - " + message); |
170 |
+ |
} |
171 |
+ |
throw new ComponentCORBAException(message); |
172 |
+ |
} |
173 |
+ |
|
174 |
+ |
|
175 |
+ |
/** |
176 |
+ |
* If there are any CORBA errors this method is called with the |
177 |
+ |
* error message. |
178 |
+ |
* |
179 |
|
* Currently this prints the error, on the local err stream. Will |
180 |
|
* print to the logger if one is available. |
181 |
|
* |
193 |
|
System.exit(1); |
194 |
|
} |
195 |
|
|
196 |
+ |
|
197 |
+ |
|
198 |
|
//---ACCESSOR/MUTATOR METHODS--- |
199 |
|
|
200 |
|
/** |
281 |
|
} |
282 |
|
return _logger; |
283 |
|
} |
282 |
– |
|
283 |
– |
/** |
284 |
– |
* Sets the reference to the name |
285 |
– |
* TO BE REMOVED ONCE CODE TIDY HAS COMPLETED! |
286 |
– |
* @deprecated not stored in the refman any more - see Template.class |
287 |
– |
* @param the new name |
288 |
– |
*/ |
289 |
– |
public void setName(String name) { |
290 |
– |
System.out.println("LEGACY CALL - SORT THIS OUT! name=" + name); |
291 |
– |
_name = name; |
292 |
– |
} |
284 |
|
|
294 |
– |
/** |
295 |
– |
* Returns a reference to the name |
296 |
– |
* TO BE REMOVED ONCE CODE TIDY HAS COMPLETED! |
297 |
– |
* @deprecated not stored in the refman any more - see Template.class |
298 |
– |
* @return the reference this class holds |
299 |
– |
*/ |
300 |
– |
public String getName() { |
301 |
– |
System.out.println("LEGACY CALL - SORT THIS OUT! name=" + _name); |
302 |
– |
return _name; |
303 |
– |
} |
304 |
– |
|
285 |
|
//---ATTRIBUTES--- |
286 |
|
|
287 |
|
/** |
325 |
|
/** |
326 |
|
* A reference to the single instance of this class |
327 |
|
*/ |
328 |
< |
private static ReferenceManager _instance; |
328 |
> |
private static ReferenceManager _instance = null; |
329 |
|
} |