ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/util/uk/org/iscream/cms/util/ReferenceManager.java
(Generate patch)

Comparing projects/cms/source/util/uk/org/iscream/cms/util/ReferenceManager.java (file contents):
Revision 1.3 by ajm, Thu Nov 30 02:38:17 2000 UTC vs.
Revision 1.8 by ajm, Wed Dec 13 13:42:50 2000 UTC

# Line 33 | Line 33 | public class ReferenceManager {
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
46     */
47    public static ReferenceManager init(String[] args, String name) throws AlreadyInitialisedException {
48        if (_instance != null) {
49            throw new AlreadyInitialisedException("init has already been called");
50        }
51        _instance = new ReferenceManager(args, name);
52        return _instance;
53    }
54    
55    /**
36       * This returns a reference to the single instance of the
37       * ReferenceManager.
38       *
39 <     * @return a reference to the ReferenceManager
39 >     * This creates the single instance of the ReferenceManager
40 >     * if it does not exist by calling the private constructor.
41       *
42 <     * @throws NotInitialisedException if the reference manager has not been initialised
42 >     * @return a reference to the ReferenceManager
43       */
44 <    public static ReferenceManager getInstance() throws NotInitialisedException {
44 >    public static ReferenceManager getInstance() {
45          if (_instance == null) {
46 <            throw new NotInitialisedException("attempt to obtain reference when not initialised");
46 >            _instance = new ReferenceManager();
47          }
48          return _instance;
49      }
# Line 72 | Line 53 | public class ReferenceManager {
53      /**
54       * This is a private constructor
55       * 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
56       */
57 <    private ReferenceManager(String[] args, String name) {
58 <        _orb = ORB.init(args, null);
81 <        _name = name;
82 <        getLogger().write(toString(), Logger.SYSINIT, "created");
57 >    private ReferenceManager() {
58 >        _orb = ORB.init(new String[] {}, null);
59      }
60  
61   //---PUBLIC METHODS---
# Line 87 | Line 63 | public class ReferenceManager {
63      /**
64       * Obtains a CORBA reference through the naming service
65       * for the named object.
66 <     * This will throw a RuntimeException if there is an error
66 >     * Calls the dieWithError() if any exceptions happen!
67       *
68       * @param name the name of the CORBA object to resolve
69       *
# Line 98 | Line 74 | public class ReferenceManager {
74          try {
75              objRef = getNS().resolve(getNS().to_name(name));
76          } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed e) {
77 <            throw new RuntimeException("\nCRITICAL:Naming Service Cannot Proceed - when resolving reference to " + name + "!\n" +
78 <                                         "         Please check with your CORBA naming service provider.");
77 >            dieWithError("\nCRITICAL:Naming Service Cannot Proceed - when resolving reference to " + name + "!\n" +
78 >                              "         Please check with your CORBA naming service provider.");
79          } catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
80 <            throw new RuntimeException("\nCRITICAL:Invalid Name - when resolving reference to " + name + "!\n" +
81 <                                         "         Please check with your CORBA naming service provider.");
80 >            dieWithError("\nCRITICAL:Invalid Name - when resolving reference to " + name + "!\n" +
81 >                              "         Please check with your CORBA naming service provider.");
82          } catch (org.omg.CosNaming.NamingContextPackage.NotFound e) {
83 <            throw new RuntimeException("\nCRITICAL:Not Found - when resolving reference to " + name + "!\n" +
84 <                                         "         Please check that this component is running.");
83 >            dieWithError("\nCRITICAL:Not Found - when resolving reference to " + name + "!\n" +
84 >                              "         Please check that this component is running.");
85          }
86          return objRef;
87      }
# Line 113 | Line 89 | public class ReferenceManager {
89      /**
90       * Binds a given servant with the given name
91       * to the naming service.
92 <     * This will throw a RuntimeException if there is an error
92 >     * Calls the dieWithError() if any exceptions happen!
93       *
94       * @param objRef a reverence to the servant object
95       * @param name the name to bind to the naming service with
# Line 122 | Line 98 | public class ReferenceManager {
98          try {
99              getNS().bind(getNS().to_name(name), getRootPOA().servant_to_reference(objRef));
100          } catch (org.omg.PortableServer.POAPackage.WrongPolicy e) {
101 <            throw new RuntimeException("\nCRITICAL:Wrong POA Policy - when binding " + name + "!\n" +
102 <                                         "         This indicates an error with your ORB.");
101 >            dieWithError("\nCRITICAL:Wrong POA Policy - when binding " + name + "!\n" +
102 >                              "         This indicates an error with your ORB.");
103          } catch (org.omg.PortableServer.POAPackage.ServantNotActive e) {
104 <            throw new RuntimeException("\nCRITICAL:ServantNotActive - when binding " + name + "!\n" +
105 <                                         "         This indicates an error with your ORB.");
104 >            dieWithError("\nCRITICAL:ServantNotActive - when binding " + name + "!\n" +
105 >                              "         This indicates an error with your ORB.");
106          } catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
107 <            throw new RuntimeException("\nCRITICAL:Invalid Name - when binding " + name + "!\n" +
108 <                                         "         Please check with your CORBA naming service provider.");
107 >            dieWithError("\nCRITICAL:Invalid Name - when binding " + name + "!\n" +
108 >                              "         Please check with your CORBA naming service provider.");
109          } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed e) {
110 <            throw new RuntimeException("\nCRITICAL:Naming Service Cannot Proceed - when binding " + name + "!\n" +
111 <                                         "         Please check with your CORBA naming service provider.");
110 >            dieWithError("\nCRITICAL:Naming Service Cannot Proceed - when binding " + name + "!\n" +
111 >                              "         Please check with your CORBA naming service provider.");
112          } catch (org.omg.CosNaming.NamingContextPackage.NotFound e) {
113 <            throw new RuntimeException("\nCRITICAL:Naming Service Not Found - when binding " + name + "!\n" +
114 <                                         "         Please check with your CORBA naming service provider.");
113 >            dieWithError("\nCRITICAL:Naming Service Not Found - when binding " + name + "!\n" +
114 >                              "         Please check with your CORBA naming service provider.");
115          } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound e) {
116 <            throw new RuntimeException("\nCRITICAL:Already Bound - when binding " + name + "!\n" +
117 <                                         "         Another component with this name is already running.");
116 >            dieWithError("\nCRITICAL:Already Bound - when binding " + name + "!\n" +
117 >                              "         Another component with this name is already running.");
118          }
119      }
120      
121      /**
122       * Activates the POA
123 <     * This will throw a RuntimeException if there is an error
123 >     * Calls the dieWithError() if any exceptions happen!
124       */
125      public void activatePOA() {
126          try {
127              getRootPOA().the_POAManager().activate();
128          } catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive e) {
129 <            throw new RuntimeException("\nCRITICAL:POA Set Inactive - when trying to activate POA!\n" +
130 <                                         "         This indicates an error with your ORB.");
129 >            dieWithError("\nCRITICAL:POA Set Inactive - when trying to activate POA!\n" +
130 >                              "         This indicates an error with your ORB.");
131          }
132      }
133      
# Line 159 | Line 135 | public class ReferenceManager {
135       * Overrides the {@link java.lang.Object#toString() Object.toString()}
136       * method to provide clean logging (every class should have this).
137       *
138 +     * This uses the uk.ac.ukc.iscream.util.NameFormat class
139 +     * to format the toString()
140 +     *
141       * @return the name of this class and its CVS revision
142       */
143      public String toString() {
144 <        return getName() + "{" + getClass().getName() + "}(" + REVISION.substring(11, REVISION.length() - 2) + ")";
144 >        return FormatName.getName(
145 >            _name,
146 >            getClass().getName(),
147 >            REVISION);
148      }
149  
150   //---PRIVATE METHODS---
151  
152 +    /**
153 +     * If there are any CORBA errors this method is called with the
154 +     * error message.
155 +     *
156 +     * Currently this prints the error, on the local err stream.  Will
157 +     * print to the logger if one is available.
158 +     *
159 +     * ANY CALLS TO THIS METHOD CAUSE
160 +     * THE SYSTEM TO EXIT WITH A NON
161 +     * ZERO CODE!
162 +     *
163 +     * @param message the error message to die with
164 +     */
165 +    private void dieWithError(String message) {
166 +        System.err.println(message);
167 +        if (_logger != null) {
168 +            _logger.write(toString(), Logger.FATAL, message);
169 +        }
170 +        System.exit(1);
171 +    }
172 +
173   //---ACCESSOR/MUTATOR METHODS---
174  
175      /**
# Line 180 | Line 183 | public class ReferenceManager {
183  
184      /**
185       * Returns a reference to the Root POA
186 <     * This will throw a RuntimeException if there is an error
186 >     * Calls the dieWithError() if any exceptions happen!
187       *
188       * @return the reference this class holds
189       */
# Line 190 | Line 193 | public class ReferenceManager {
193              try {
194                  objRef = getORB().resolve_initial_references("RootPOA");
195              } catch (org.omg.CORBA.ORBPackage.InvalidName e) {
196 <                throw new RuntimeException("\nCRITICAL:Unable to resolve reference to the RootPOA!\n" +
197 <                                             "         This indicates an error with your ORB.");
196 >                dieWithError("\nCRITICAL:Unable to resolve reference to the RootPOA!\n" +
197 >                                  "         This indicates an error with your ORB.");
198              }
199              _rootPOA = POAHelper.narrow(objRef);
200          }
# Line 200 | Line 203 | public class ReferenceManager {
203      
204      /**
205       * Returns a reference to the Naming Service
206 <     * This will throw a RuntimeException if there is an error
206 >     * Calls the dieWithError() if any exceptions happen!
207       *
208       * @return the reference this class holds
209       */
# Line 210 | Line 213 | public class ReferenceManager {
213              try {
214                  objRef = getORB().resolve_initial_references("NameService");
215              } catch (org.omg.CORBA.ORBPackage.InvalidName e) {
216 <                throw new RuntimeException("\nCRITICAL:Unable to resolve reference to the Naming Service!\n" +
217 <                                             "         Please check with your CORBA naming service provider.");
216 >                dieWithError("\nCRITICAL:Unable to resolve reference to the Naming Service!\n" +
217 >                                  "         Please check with your CORBA naming service provider.");
218              }
219              _ns = NamingContextExtHelper.narrow(objRef);
220          }
221 +        // check we managed to talk to the naming service
222 +        if (_ns == null) {
223 +            dieWithError("\nCRITICAL:Unable to resolve reference to the Naming Service!\n" +
224 +                              "         Please check with your CORBA naming service provider.");
225 +        }
226          return _ns;
227      }
228      
229      /**
230       * Returns a reference to the configuration manager
231 <     * This will throw a RuntimeException if there is an error
231 >     * Calls the dieWithError() if any exceptions happen!
232       *
233       * @return the reference this class holds
234       */
# Line 228 | Line 236 | public class ReferenceManager {
236          if (_cm == null) {
237              _cm = ConfigurationManagerHelper.narrow(getCORBARef("iscream.ConfigurationManager"));
238          }
239 +        // check we managed to talk to the configuration manager
240 +        if (_cm == null) {
241 +            dieWithError("\nCRITICAL:Unable to resolve reference to the Configuration Manager!\n" +
242 +                              "         Please check with your CORBA naming service provider.");
243 +        }
244          return _cm;
245      }
246  
247      /**
248       * Returns a reference to the logger
249 <     * This will throw a RuntimeException if there is an error
249 >     * This will throw a Error if there is an error
250       *
251       * @return the reference this class holds
252       */
# Line 244 | Line 257 | public class ReferenceManager {
257          return _logger;
258      }
259      
247    /**
248     * Returns a reference to the name
249     *
250     * @return the reference this class holds
251     */
252    public String getName() {
253        return _name;
254    }
255
260   //---ATTRIBUTES---
261      
262      /**
# Line 281 | Line 285 | public class ReferenceManager {
285      private Logger _logger;
286      
287      /**
288 <     * The name
288 >     * This is the friendly identifier of the
289 >     * component this class is running in.
290 >     * eg, a Filter may be called "filter1",
291 >     * If this class does not have an owning
292 >     * component,  a name from the configuration
293 >     * can be placed here.  This name could also
294 >     * be changed to null for utility classes.
295       */
296 <    private String _name;
296 >    private String _name = null;
297  
298   //---STATIC ATTRIBUTES---
299      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines