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.1 by ajm, Thu Nov 30 00:54:27 2000 UTC vs.
Revision 1.2 by ajm, Thu Nov 30 02:19:31 2000 UTC

# Line 11 | Line 11 | import uk.ac.ukc.iscream.core.*;
11   * This class returns references for global system objects.
12   * This class is used to create and return references to objects
13   * that are required throughout the system.  Most of which
14 < * are CORBA based.  It also handles ORB initialisation.
14 > * are CORBA based.  It also manages the ORB for the component.
15   *
16   * It is a singleton object with a static method to obtain a
17   * reference to it.  This removes the need for passing
# Line 33 | Line 33 | public class ReferenceManager {
33   //---STATIC METHODS---
34  
35      /**
36     * This essentially formats the toString() source for an
37     * object wanting to make a log entry.
38     *
39     * @param source the source of the call
40     * @param rev the CVS revision number of the caller
41     *
42     * @return the formatted string
43    
44    public static String logString(Object source, String rev) {
45        if (_instance == null) {
46            return "unamed{" + source.getClass().getName() + "}(" + rev.substring(11, rev.length() - 2) + ")";
47        }
48        return getInstance().getName() + "{" + source.getClass().getName() + "}(" + rev.substring(11, rev.length() - 2) + ")";
49    }
50 `    */
51
52    /**
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.
# Line 102 | Line 85 | public class ReferenceManager {
85   //---PUBLIC METHODS---
86  
87      /**
88 +     * Obtains a CORBA reference through the naming service
89 +     * for the named object.
90 +     * This will throw a RuntimeException if there is an error
91 +     *
92 +     * @param name the name of the CORBA object to resolve
93 +     *
94 +     * @return a reference to the object
95 +     */
96 +    public org.omg.CORBA.Object getCORBARef(String name) {
97 +        org.omg.CORBA.Object objRef = null;
98 +        try {
99 +            objRef = getNS().resolve(getNS().to_name(name));
100 +        } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed e) {
101 +            throw new RuntimeException("\nCRITICAL:Naming Service Cannot Proceed - when resolving reference to " + name + "!\n" +
102 +                                         "         Please check with your CORBA naming service provider.");
103 +        } catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
104 +            throw new RuntimeException("\nCRITICAL:Invalid Name - when resolving reference to " + name + "!\n" +
105 +                                         "         Please check with your CORBA naming service provider.");
106 +        } catch (org.omg.CosNaming.NamingContextPackage.NotFound e) {
107 +            throw new RuntimeException("\nCRITICAL:Not Found - when resolving reference to " + name + "!\n" +
108 +                                         "         Please check that this component is running.");
109 +        }
110 +        return objRef;
111 +    }
112 +
113 +    /**
114 +     * Binds a given servant with the given name
115 +     * to the naming service.
116 +     * This will throw a RuntimeException if there is an error
117 +     *
118 +     * @param objRef a reverence to the servant object
119 +     * @param name the name to bind to the naming service with
120 +     */
121 +    public void bindToOrb(org.omg.PortableServer.Servant objRef, String name) {
122 +        try {
123 +            getNS().bind(getNS().to_name(name), getRootPOA().servant_to_reference(objRef));
124 +        } catch (org.omg.PortableServer.POAPackage.WrongPolicy e) {
125 +            throw new RuntimeException("\nCRITICAL:Wrong POA Policy - when binding " + name + "!\n" +
126 +                                         "         This indicates an error with your ORB.");
127 +        } catch (org.omg.PortableServer.POAPackage.ServantNotActive e) {
128 +            throw new RuntimeException("\nCRITICAL:ServantNotActive - when binding " + name + "!\n" +
129 +                                         "         This indicates an error with your ORB.");
130 +        } catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
131 +            throw new RuntimeException("\nCRITICAL:Invalid Name - when binding " + name + "!\n" +
132 +                                         "         Please check with your CORBA naming service provider.");
133 +        } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed e) {
134 +            throw new RuntimeException("\nCRITICAL:Naming Service Cannot Proceed - when binding " + name + "!\n" +
135 +                                         "         Please check with your CORBA naming service provider.");
136 +        } catch (org.omg.CosNaming.NamingContextPackage.NotFound e) {
137 +            throw new RuntimeException("\nCRITICAL:Naming Service Not Found - when binding " + name + "!\n" +
138 +                                         "         Please check with your CORBA naming service provider.");
139 +        } catch (org.omg.CosNaming.NamingContextPackage.AlreadyBound e) {
140 +            throw new RuntimeException("\nCRITICAL:Already Bound - when binding " + name + "!\n" +
141 +                                         "         Another component with this name is already running.");
142 +        }
143 +    }
144 +    
145 +    /**
146 +     * Activates the POA
147 +     * This will throw a RuntimeException if there is an error
148 +     */
149 +    public void activatePOA() {
150 +        try {
151 +            getRootPOA().the_POAManager().activate();
152 +        } catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive e) {
153 +            throw new RuntimeException("\nCRITICAL:POA Set Inactive - when trying to activate POA!\n" +
154 +                                         "         This indicates an error with your ORB.");
155 +        }
156 +    }
157 +    
158 +    /**
159       * Overrides the {@link java.lang.Object#toString() Object.toString()}
160       * method to provide clean logging (every class should have this).
161       *
# Line 136 | Line 190 | public class ReferenceManager {
190              try {
191                  objRef = getORB().resolve_initial_references("RootPOA");
192              } catch (org.omg.CORBA.ORBPackage.InvalidName e) {
193 <                throw new RuntimeException("CRITICAL:Unable to resolve reference to the RootPOA!\n" +
194 <                                           "         This indicates an error with your ORB.");
193 >                throw new RuntimeException("\nCRITICAL:Unable to resolve reference to the RootPOA!\n" +
194 >                                             "         This indicates an error with your ORB.");
195              }
196              _rootPOA = POAHelper.narrow(objRef);
197          }
# Line 156 | Line 210 | public class ReferenceManager {
210              try {
211                  objRef = getORB().resolve_initial_references("NameService");
212              } catch (org.omg.CORBA.ORBPackage.InvalidName e) {
213 <                throw new RuntimeException("CRITICAL:Unable to resolve reference to the Naming Service!\n" +
214 <                                           "         Please check with your CORBA naming service provider.");
213 >                throw new RuntimeException("\nCRITICAL:Unable to resolve reference to the Naming Service!\n" +
214 >                                             "         Please check with your CORBA naming service provider.");
215              }
216              _ns = NamingContextExtHelper.narrow(objRef);
217          }
# Line 172 | Line 226 | public class ReferenceManager {
226       */
227      public ConfigurationManager getCM() {
228          if (_cm == null) {
229 <            org.omg.CORBA.Object objRef = null;
176 <            try {
177 <                objRef = getNS().resolve(getNS().to_name("iscream.ConfigurationManager"));
178 <            } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed e) {
179 <                throw new RuntimeException("CRITICAL:Cannot Proceed - when resolving reference to iscream.ConfigurationManager!\n" +
180 <                                           "         This indicates an error with your ORB.");
181 <            } catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
182 <                throw new RuntimeException("CRITICAL:Invalid Name - when resolving reference to iscream.ConfigurationManager!\n" +
183 <                                           "         This indicates an error with your ORB.");
184 <            } catch (org.omg.CosNaming.NamingContextPackage.NotFound e) {
185 <                throw new RuntimeException("CRITICAL:Not Found - when resolving reference to iscream.ConfigurationManager!\n" +
186 <                                           "         Please check that this component is running.");
187 <            }
188 <            _cm = ConfigurationManagerHelper.narrow(objRef);
229 >            _cm = ConfigurationManagerHelper.narrow(getCORBARef("iscream.ConfigurationManager"));
230          }
231          return _cm;
232      }
# Line 198 | Line 239 | public class ReferenceManager {
239       */
240      public Logger getLogger() {
241          if (_logger == null) {
242 <            org.omg.CORBA.Object objRef = null;
202 <            try {
203 <                objRef = getNS().resolve(getNS().to_name("iscream.Logger"));
204 <            } catch (org.omg.CosNaming.NamingContextPackage.CannotProceed e) {
205 <                throw new RuntimeException("CRITICAL:Cannot Proceed - when resolving reference to iscream.Logger!\n" +
206 <                                           "         This indicates an error with your ORB.");
207 <            } catch (org.omg.CosNaming.NamingContextPackage.InvalidName e) {
208 <                throw new RuntimeException("CRITICAL:Invalid Name - when resolving reference to iscream.Logger!\n" +
209 <                                           "         This indicates an error with your ORB.");
210 <            } catch (org.omg.CosNaming.NamingContextPackage.NotFound e) {
211 <                throw new RuntimeException("CRITICAL:Not Found - when resolving reference to iscream.Logger!\n" +
212 <                                           "         Please check that this component is running.");
213 <            }
214 <            _logger = LoggerHelper.narrow(objRef);
242 >            _logger = LoggerHelper.narrow(getCORBARef("iscream.Logger"));
243          }
244          return _logger;
245      }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines