00001
00002
00003
00004
00005
00006
00007 package GuiComponents.System;
00008
00009 import ipc.*;
00010 import java.util.*;
00011 import java.util.logging.*;
00012 import SctTestApi.*;
00013 import Sct_CalibrationController.*;
00014 import SubscriptionManagerModule.*;
00015 import Sct_SctApi.*;
00016 import AnalysisServiceI.*;
00017 import ArchivingServiceI.*;
00018 import sctConf.*;
00019 import FitterI.*;
00020
00021
00033 public class SystemInterface {
00034
00038 public static SystemInterface getInstance() {
00039 return instance;
00040 }
00041
00045 public void refresh() {
00046 p = null;
00047 testconfig = null;
00048 highlevel = null;
00049 subMan = null;
00050 cc = null;
00051 api = null;
00052 apiDDC = null;
00053 config = null;
00054 analysis = null;
00055 archiving = null;
00056 fitter = null;
00057 }
00058
00062 public Partition getPartition() {
00063 if (p == null) {
00064 try {
00065 p = new Partition(partitionName);
00066 } catch (PartitionNotFoundException e) {
00067 logger.info("Failed to get partition: " + partitionName + ": " + e.getMessage());
00068 }
00069 }
00070 return p;
00071 }
00072
00076 public SctTestApi.Configuration getTestConfiguration() {
00077 if (testconfig == null) {
00078 try {
00079 org.omg.CORBA.Object ob = lookup(sctConf.Configuration.class, SctTestApi.Configuration.instanceName);
00080 testconfig = SctTestApi.ConfigurationHelper.narrow(ob);
00081 if (testconfig == null) {
00082 logger.info("Failed to lookup SctTest::Configuration using: " + SctTestApi.Configuration.instanceName);
00083 }
00084 } catch (org.omg.CORBA.SystemException se) {
00085 logger.info("Failed to lookup SctTest::Configuration using: " + SctTestApi.Configuration.instanceName + ". Exception: " + se.getMessage());
00086
00087
00088 } catch (NullPointerException npe) {
00089
00090 }
00091 }
00092 return testconfig;
00093 }
00094
00098 public HighLevelApi getTestHighLevelApi() {
00099 if (highlevel == null) {
00100 try {
00101 org.omg.CORBA.Object ob = lookup(SctTestApi.HighLevelApi.class, HighLevelApi.instanceName);
00102 highlevel = HighLevelApiHelper.narrow(ob);
00103 if (highlevel == null) {
00104 logger.info("Failed to lookup SctTest::HighLevelApi using: " + HighLevelApi.instanceName);
00105 }
00106 } catch (org.omg.CORBA.SystemException se) {
00107 logger.info("Failed to lookup SctTest::HighLevelApi using: " + HighLevelApi.instanceName + ". Exception: " + se.getMessage());
00108
00109
00110 } catch (NullPointerException npe) {
00111
00112 }
00113 }
00114 return highlevel;
00115 }
00116
00117
00121 public SubscriptionManager getSubscriptionManager() {
00122 subMan=null;
00123 if (subMan == null) {
00124 try {
00125 org.omg.CORBA.Object ob = lookup(SubscriptionManagerModule.SubscriptionManager.class, SubscriptionManager.instanceName);
00126 subMan = SubscriptionManagerHelper.narrow(ob);
00127 } catch (org.omg.CORBA.SystemException se) {
00128 logger.info("Failed to lookup SubscriptionManager using: " + SubscriptionManager.instanceName + ". Exception: " + se.getMessage());
00129
00130
00131 } catch (NullPointerException npe) {
00132
00133 }
00134 }
00135 return subMan;
00136 }
00137
00141 public CalibrationController getCalibrationController() {
00142 if (cc == null) {
00143 try {
00144 org.omg.CORBA.Object ob = lookup(Sct_CalibrationController.CalibrationController.class, CalibrationController.instanceName);
00145 cc = CalibrationControllerHelper.narrow(ob);
00146 } catch (org.omg.CORBA.SystemException se) {
00147 logger.info("Failed to lookup CalibrationController using: " + CalibrationController.instanceName + ". Exception: " + se.getMessage());
00148
00149
00150 } catch (NullPointerException npe) {
00151
00152 }
00153 }
00154 return cc;
00155 }
00156
00160 public SctApiIPC getSctApi() {
00161 if (api == null) {
00162 try {
00163 org.omg.CORBA.Object ob = lookup(Sct_SctApi.SctApiIPC.class, SctApiIPC.instanceName);
00164 api = SctApiIPCHelper.narrow(ob);
00165 } catch (org.omg.CORBA.SystemException se) {
00166 logger.info("Failed to lookup SctApi using: " + SctApiIPC.instanceName + " . Exception: " + se.getMessage());
00167
00168
00169 } catch (NullPointerException npe) {
00170
00171 }
00172 }
00173 return api;
00174 }
00175
00179 public SctApiDDCServer getSctApiDDCServer() {
00180 if (apiDDC == null) {
00181 try {
00182 org.omg.CORBA.Object ob = lookup(Sct_SctApi.SctApiDDCServer.class, SctApiDDCServer.instanceName);
00183 apiDDC = SctApiDDCServerHelper.narrow(ob);
00184 } catch (org.omg.CORBA.SystemException se) {
00185 logger.info("Failed to lookup SctApiDDCServer using: " + SctApiDDCServer.instanceName + " . Exception: " + se.getMessage());
00186
00187
00188 } catch (NullPointerException npe) {
00189
00190 }
00191 }
00192 return apiDDC;
00193 }
00194
00198 public sctConf.Configuration getConfigurationService() {
00199 if (config == null) {
00200 try {
00201 org.omg.CORBA.Object ob = lookup(sctConf.Configuration.class, sctConf.Configuration.instanceName);
00202 config = sctConf.ConfigurationHelper.narrow(ob);
00203 } catch (org.omg.CORBA.SystemException se) {
00204 logger.info("Failed to lookup Configuration using: " + sctConf.Configuration.instanceName + ". Exception: " + se.getMessage());
00205
00206
00207 } catch (NullPointerException npe) {
00208
00209 }
00210 }
00211 return config;
00212 }
00213
00217 public AnalysisServiceInterface getAnalysisService() {
00218 if (analysis == null) {
00219 try {
00220 org.omg.CORBA.Object ob = lookup(AnalysisServiceI.AnalysisServiceInterface.class, AnalysisServiceInterface.instanceName);
00221 analysis = AnalysisServiceInterfaceHelper.narrow(ob);
00222 } catch (org.omg.CORBA.SystemException se) {
00223 logger.info("Failed to lookup AnalysisService using: " + AnalysisServiceInterface.instanceName + ". Exception: " + se.getMessage());
00224
00225
00226 } catch (NullPointerException npe) {
00227
00228 }
00229 }
00230 return analysis;
00231 }
00232
00236 public ArchivingServiceInterface getArchivingService() {
00237 if (archiving == null) {
00238 try {
00239 org.omg.CORBA.Object ob = lookup(ArchivingServiceI.ArchivingServiceInterface.class, ArchivingServiceInterface.instanceName);
00240 archiving = ArchivingServiceInterfaceHelper.narrow(ob);
00241 } catch (org.omg.CORBA.SystemException se) {
00242 logger.info("Failed to lookup ArchivingService using: " + ArchivingServiceInterface.instanceName + ". Exception: " + se.getMessage());
00243
00244
00245 } catch (NullPointerException npe) {
00246
00247 }
00248 }
00249 return archiving;
00250 }
00251
00252
00256 public FitterInterface getFittingService() {
00257 if (fitter == null) {
00258 try {
00259 org.omg.CORBA.Object ob = lookup(FitterI.FitterInterface.class, FitterInterface.instanceName);
00260 fitter = FitterInterfaceHelper.narrow(ob);
00261 } catch (org.omg.CORBA.SystemException se) {
00262 logger.info("Failed to lookup Fitter using: " + FitterInterface.instanceName + ". Exception: " + se.getMessage());
00263
00264
00265 } catch (NullPointerException npe) {
00266
00267 }
00268 }
00269 return fitter;
00270 }
00271
00273 private SystemInterface() {
00274 logger = Logger.getLogger("GuiComponents.System");
00275 refresh();
00276 }
00277
00279 public org.omg.CORBA.Object lookup(java.lang.Class type, String name){
00280 org.omg.CORBA.Object ob=null;
00281 getPartition();
00282 boolean valid=false;
00283 int ntries=0;
00284 while (valid==false && ntries<maxtries){
00285 if (ob==null || ob._non_existent()) {
00286 ob=p.lookup(type, name);
00287 }else{
00288 valid=true;
00289 }
00290 ntries++;
00291 }
00292 if (!valid) {
00293 String message="SystemInterface failed to look up "+name+" after "+maxtries+" attempts";
00294 logger.info(message);
00295 return null;
00296 }else{
00297 return ob;
00298 }
00299 }
00300
00301 private static SystemInterface instance = new SystemInterface();
00302 private static final String partitionName = "SCT";
00303 private Partition p;
00304 private Logger logger;
00305 private SctTestApi.Configuration testconfig;
00306 private HighLevelApi highlevel;
00307 private SubscriptionManager subMan;
00308 private CalibrationController cc;
00309 private SctApiIPC api;
00310 private SctApiDDCServer apiDDC;
00311 private sctConf.Configuration config;
00312 private AnalysisServiceInterface analysis;
00313 private ArchivingServiceInterface archiving;
00314 private FitterInterface fitter;
00315 private static int maxtries=4;
00316 }