33 |
|
//---STATIC METHODS--- |
34 |
|
|
35 |
|
/** |
36 |
< |
* This creates the single instance of the ReferenceManager by |
37 |
< |
* calling the private constructor. If it is called twice, |
38 |
< |
* it detects an instance already exits and throws an exception. |
39 |
< |
* |
40 |
< |
* @param args the args to be passed to the ORB |
41 |
< |
* @param name the name of the component that will use this singleton |
42 |
< |
* |
43 |
< |
* @return a reference to the ReferenceManager |
44 |
< |
* |
45 |
< |
* @throws AlreadyInitialisedException if this method has already been called |
36 |
> |
* TO BE REMOVED ONCE CODE TIDY HAS COMPLETED! |
37 |
> |
* @deprecated should know 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 |
|
} |
49 |
|
* This returns a reference to the single instance of the |
50 |
|
* ReferenceManager. |
51 |
|
* |
52 |
< |
* @return a reference to the ReferenceManager |
52 |
> |
* This creates the single instance of the ReferenceManager |
53 |
> |
* if it does not exist by calling the private constructor. |
54 |
|
* |
55 |
< |
* @throws NotInitialisedException if the reference manager has not been initialised |
55 |
> |
* @return a reference to the ReferenceManager |
56 |
|
*/ |
57 |
< |
public static ReferenceManager getInstance() throws NotInitialisedException { |
57 |
> |
public static ReferenceManager getInstance() { |
58 |
|
if (_instance == null) { |
59 |
< |
throw new NotInitialisedException("attempt to obtain reference when not initialised"); |
59 |
> |
_instance = new ReferenceManager(); |
60 |
|
} |
61 |
|
return _instance; |
62 |
|
} |
66 |
|
/** |
67 |
|
* This is a private constructor |
68 |
|
* This ensures that the system performs according to a Singleton design pattern |
75 |
– |
* |
76 |
– |
* @param args the args to be passed to the ORB |
77 |
– |
* @param name the name of the component that will use this singleton |
69 |
|
*/ |
70 |
+ |
private ReferenceManager() { |
71 |
+ |
_orb = ORB.init(new String[] {}, null); |
72 |
+ |
} |
73 |
+ |
|
74 |
+ |
/** |
75 |
+ |
* TO BE REMOVED ONCE CODE TIDY HAS COMPLETED! |
76 |
+ |
* @deprecated should know 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 |
– |
getLogger().write(toString(), Logger.SYSINIT, "created"); |
82 |
|
} |
83 |
|
|
84 |
|
//---PUBLIC METHODS--- |
86 |
|
/** |
87 |
|
* Obtains a CORBA reference through the naming service |
88 |
|
* for the named object. |
89 |
< |
* This will throw a RuntimeException if there is an error |
89 |
> |
* This will throw a Error if there is an error |
90 |
|
* |
91 |
|
* @param name the name of the CORBA object to resolve |
92 |
|
* |
97 |
|
try { |
98 |
|
objRef = getNS().resolve(getNS().to_name(name)); |
99 |
|
} catch (org.omg.CosNaming.NamingContextPackage.CannotProceed e) { |
100 |
< |
throw new RuntimeException("\nCRITICAL:Naming Service Cannot Proceed - when resolving reference to " + name + "!\n" + |
101 |
< |
" Please check with your CORBA naming service provider."); |
100 |
> |
dieWithError("\nCRITICAL:Naming Service Cannot Proceed - when resolving reference to " + name + "!\n" + |
101 |
> |
" Please check with your CORBA naming service provider."); |
102 |
|
} catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) { |
103 |
< |
throw new RuntimeException("\nCRITICAL:Invalid Name - when resolving reference to " + name + "!\n" + |
104 |
< |
" Please check with your CORBA naming service provider."); |
103 |
> |
dieWithError("\nCRITICAL:Invalid Name - when resolving reference to " + name + "!\n" + |
104 |
> |
" Please check with your CORBA naming service provider."); |
105 |
|
} catch (org.omg.CosNaming.NamingContextPackage.NotFound e) { |
106 |
< |
throw new RuntimeException("\nCRITICAL:Not Found - when resolving reference to " + name + "!\n" + |
107 |
< |
" Please check that this component is running."); |
106 |
> |
dieWithError("\nCRITICAL:Not Found - when resolving reference to " + name + "!\n" + |
107 |
> |
" Please check that this component is running."); |
108 |
|
} |
109 |
|
return objRef; |
110 |
|
} |
112 |
|
/** |
113 |
|
* Binds a given servant with the given name |
114 |
|
* to the naming service. |
115 |
< |
* This will throw a RuntimeException if there is an error |
115 |
> |
* Calls the dieWithError()! |
116 |
|
* |
117 |
|
* @param objRef a reverence to the servant object |
118 |
|
* @param name the name to bind to the naming service with |
121 |
|
try { |
122 |
|
getNS().bind(getNS().to_name(name), getRootPOA().servant_to_reference(objRef)); |
123 |
|
} catch (org.omg.PortableServer.POAPackage.WrongPolicy e) { |
124 |
< |
throw new RuntimeException("\nCRITICAL:Wrong POA Policy - when binding " + name + "!\n" + |
125 |
< |
" This indicates an error with your ORB."); |
124 |
> |
dieWithError("\nCRITICAL:Wrong POA Policy - when binding " + name + "!\n" + |
125 |
> |
" This indicates an error with your ORB."); |
126 |
|
} catch (org.omg.PortableServer.POAPackage.ServantNotActive e) { |
127 |
< |
throw new RuntimeException("\nCRITICAL:ServantNotActive - when binding " + name + "!\n" + |
128 |
< |
" This indicates an error with your ORB."); |
127 |
> |
dieWithError("\nCRITICAL:ServantNotActive - when binding " + name + "!\n" + |
128 |
> |
" This indicates an error with your ORB."); |
129 |
|
} catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) { |
130 |
< |
throw new RuntimeException("\nCRITICAL:Invalid Name - when binding " + name + "!\n" + |
131 |
< |
" Please check with your CORBA naming service provider."); |
130 |
> |
dieWithError("\nCRITICAL:Invalid Name - when binding " + name + "!\n" + |
131 |
> |
" Please check with your CORBA naming service provider."); |
132 |
|
} catch (org.omg.CosNaming.NamingContextPackage.CannotProceed e) { |
133 |
< |
throw new RuntimeException("\nCRITICAL:Naming Service Cannot Proceed - when binding " + name + "!\n" + |
134 |
< |
" Please check with your CORBA naming service provider."); |
133 |
> |
dieWithError("\nCRITICAL:Naming Service Cannot Proceed - when binding " + name + "!\n" + |
134 |
> |
" Please check with your CORBA naming service provider."); |
135 |
|
} catch (org.omg.CosNaming.NamingContextPackage.NotFound e) { |
136 |
< |
throw new RuntimeException("\nCRITICAL:Naming Service Not Found - when binding " + name + "!\n" + |
137 |
< |
" Please check with your CORBA naming service provider."); |
136 |
> |
dieWithError("\nCRITICAL:Naming Service Not Found - when binding " + name + "!\n" + |
137 |
> |
" Please check with your CORBA naming service provider."); |
138 |
|
} catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound e) { |
139 |
< |
throw new RuntimeException("\nCRITICAL:Already Bound - when binding " + name + "!\n" + |
140 |
< |
" Another component with this name is already running."); |
139 |
> |
dieWithError("\nCRITICAL:Already Bound - when binding " + name + "!\n" + |
140 |
> |
" Another component with this name is already running."); |
141 |
|
} |
142 |
|
} |
143 |
|
|
144 |
|
/** |
145 |
|
* Activates the POA |
146 |
< |
* This will throw a RuntimeException if there is an error |
146 |
> |
* This will throw a Error if there is an error |
147 |
|
*/ |
148 |
|
public void activatePOA() { |
149 |
|
try { |
150 |
|
getRootPOA().the_POAManager().activate(); |
151 |
|
} catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive e) { |
152 |
< |
throw new RuntimeException("\nCRITICAL:POA Set Inactive - when trying to activate POA!\n" + |
153 |
< |
" This indicates an error with your ORB."); |
152 |
> |
dieWithError("\nCRITICAL:POA Set Inactive - when trying to activate POA!\n" + |
153 |
> |
" This indicates an error with your ORB."); |
154 |
|
} |
155 |
|
} |
156 |
|
|
158 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
159 |
|
* method to provide clean logging (every class should have this). |
160 |
|
* |
161 |
+ |
* This uses the uk.ac.ukc.iscream.util.NameFormat class |
162 |
+ |
* to format the toString() |
163 |
+ |
* |
164 |
|
* @return the name of this class and its CVS revision |
165 |
|
*/ |
166 |
|
public String toString() { |
167 |
< |
return getName() + "{" + getClass().getName() + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
167 |
> |
return FormatName.getName( |
168 |
> |
null, |
169 |
> |
this.getClass().getName(), |
170 |
> |
REVISION); |
171 |
|
} |
172 |
|
|
173 |
|
//---PRIVATE METHODS--- |
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 |
+ |
* |
182 |
+ |
* ANY CALLS TO THIS METHOD CAUSE |
183 |
+ |
* THE SYSTEM TO EXIT WITH A NON |
184 |
+ |
* ZERO CODE! |
185 |
+ |
* |
186 |
+ |
* @param message the error message to die with |
187 |
+ |
*/ |
188 |
+ |
private void dieWithError(String message) { |
189 |
+ |
System.err.println(message); |
190 |
+ |
if (_logger != null) { |
191 |
+ |
_logger.write(toString(), Logger.FATAL, message); |
192 |
+ |
} |
193 |
+ |
System.exit(1); |
194 |
+ |
} |
195 |
+ |
|
196 |
|
//---ACCESSOR/MUTATOR METHODS--- |
197 |
|
|
198 |
|
/** |
206 |
|
|
207 |
|
/** |
208 |
|
* Returns a reference to the Root POA |
209 |
< |
* This will throw a RuntimeException if there is an error |
209 |
> |
* This will throw a Error if there is an error |
210 |
|
* |
211 |
|
* @return the reference this class holds |
212 |
|
*/ |
216 |
|
try { |
217 |
|
objRef = getORB().resolve_initial_references("RootPOA"); |
218 |
|
} catch (org.omg.CORBA.ORBPackage.InvalidName e) { |
219 |
< |
throw new RuntimeException("\nCRITICAL:Unable to resolve reference to the RootPOA!\n" + |
220 |
< |
" This indicates an error with your ORB."); |
219 |
> |
dieWithError("\nCRITICAL:Unable to resolve reference to the RootPOA!\n" + |
220 |
> |
" This indicates an error with your ORB."); |
221 |
|
} |
222 |
|
_rootPOA = POAHelper.narrow(objRef); |
223 |
|
} |
226 |
|
|
227 |
|
/** |
228 |
|
* Returns a reference to the Naming Service |
229 |
< |
* This will throw a RuntimeException if there is an error |
229 |
> |
* This will throw a Error if there is an error |
230 |
|
* |
231 |
|
* @return the reference this class holds |
232 |
|
*/ |
236 |
|
try { |
237 |
|
objRef = getORB().resolve_initial_references("NameService"); |
238 |
|
} catch (org.omg.CORBA.ORBPackage.InvalidName e) { |
239 |
< |
throw new RuntimeException("\nCRITICAL:Unable to resolve reference to the Naming Service!\n" + |
240 |
< |
" Please check with your CORBA naming service provider."); |
239 |
> |
dieWithError("\nCRITICAL:Unable to resolve reference to the Naming Service!\n" + |
240 |
> |
" Please check with your CORBA naming service provider."); |
241 |
|
} |
242 |
|
_ns = NamingContextExtHelper.narrow(objRef); |
243 |
|
} |
244 |
+ |
// check we managed to talk to the naming service |
245 |
+ |
if (_ns == null) { |
246 |
+ |
dieWithError("\nCRITICAL:Unable to resolve reference to the Naming Service!\n" + |
247 |
+ |
" Please check with your CORBA naming service provider."); |
248 |
+ |
} |
249 |
|
return _ns; |
250 |
|
} |
251 |
|
|
252 |
|
/** |
253 |
|
* Returns a reference to the configuration manager |
254 |
< |
* This will throw a RuntimeException if there is an error |
254 |
> |
* This will throw a Error if there is an error |
255 |
|
* |
256 |
|
* @return the reference this class holds |
257 |
|
*/ |
259 |
|
if (_cm == null) { |
260 |
|
_cm = ConfigurationManagerHelper.narrow(getCORBARef("iscream.ConfigurationManager")); |
261 |
|
} |
262 |
+ |
// check we managed to talk to the configuration manager |
263 |
+ |
if (_cm == null) { |
264 |
+ |
dieWithError("\nCRITICAL:Unable to resolve reference to the Configuration Manager!\n" + |
265 |
+ |
" Please check with your CORBA naming service provider."); |
266 |
+ |
} |
267 |
|
return _cm; |
268 |
|
} |
269 |
|
|
270 |
|
/** |
271 |
|
* Returns a reference to the logger |
272 |
< |
* This will throw a RuntimeException if there is an error |
272 |
> |
* This will throw a Error if there is an error |
273 |
|
* |
274 |
|
* @return the reference this class holds |
275 |
|
*/ |
282 |
|
|
283 |
|
/** |
284 |
|
* Sets the reference to the name |
285 |
< |
* |
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 |
|
} |
293 |
|
|
294 |
|
/** |
295 |
|
* Returns a reference to the name |
296 |
< |
* |
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 |
|
|
331 |
|
|
332 |
|
/** |
333 |
|
* The name |
334 |
+ |
* TO BE REMOVED ONCE CODE TIDY HAS COMPLETED! |
335 |
+ |
* @deprecated not stored in the refman any more - see Template.class |
336 |
|
*/ |
337 |
|
private String _name; |
338 |
|
|