Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

SystemInterface.java

00001 /*
00002  * SCTInterface.java
00003  *
00004  * Created on 15 November 2002, 12:01
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         config = null;
00053         analysis = null;
00054         archiving = null;
00055         fitter = null;
00056     }
00057 
00061     public Partition getPartition() {
00062         if (p == null) {
00063             try {
00064                 p = new Partition(partitionName); 
00065             } catch (PartitionNotFoundException e) {
00066                 logger.info("Failed to get partition: " + partitionName + ": " + e.getMessage());
00067             }
00068         }
00069         return p;
00070     }
00071 
00075     public SctTestApi.Configuration getTestConfiguration() {
00076         if (testconfig == null) {
00077             try {
00078                 org.omg.CORBA.Object ob = lookup(sctConf.Configuration.class, SctTestApi.Configuration.instanceName);
00079                 testconfig = SctTestApi.ConfigurationHelper.narrow(ob);
00080                 if (testconfig == null) {
00081                     logger.info("Failed to lookup SctTest::Configuration using: " + SctTestApi.Configuration.instanceName);
00082                 }
00083             } catch (org.omg.CORBA.SystemException se) {
00084                 logger.info("Failed to lookup SctTest::Configuration using: " + SctTestApi.Configuration.instanceName + ". Exception: " + se.getMessage());
00085                 //} catch (ClassNotFoundException ce) {
00086                 //logger.info("Failed to lookup Class name for sctConf.Configuration!. Exception: " + ce.getMessage());
00087             } catch (NullPointerException npe) {
00088                 //Do nothing - this must have been caused by not being able to get the partition, which we've already logged
00089             }
00090         }
00091         return testconfig;
00092     }
00093 
00097     public HighLevelApi getTestHighLevelApi() {
00098         if (highlevel == null) {
00099             try {
00100                 org.omg.CORBA.Object ob = lookup(SctTestApi.HighLevelApi.class, HighLevelApi.instanceName);
00101                 highlevel = HighLevelApiHelper.narrow(ob);
00102                 if (highlevel == null) {
00103                     logger.info("Failed to lookup SctTest::HighLevelApi using: " + HighLevelApi.instanceName);
00104                 }
00105             } catch (org.omg.CORBA.SystemException se) {
00106                 logger.info("Failed to lookup SctTest::HighLevelApi using: " + HighLevelApi.instanceName + ". Exception: " + se.getMessage());
00107                 //} catch (ClassNotFoundException ce) {
00108                 //logger.info("Failed to lookup Class name for HighLevelApi.HighLevelApi!. Exception: " + ce.getMessage());
00109             } catch (NullPointerException npe) {
00110                 //Do nothing - this must have been caused by not being able to get the partition, which we've already logged
00111             }
00112         }
00113         return highlevel;
00114     }
00115 
00116 
00120     public SubscriptionManager getSubscriptionManager() {
00121         subMan=null; // I don't trust this caching!
00122         if (subMan == null) {
00123             try {
00124                 org.omg.CORBA.Object ob = lookup(SubscriptionManagerModule.SubscriptionManager.class, SubscriptionManager.instanceName);
00125                 subMan = SubscriptionManagerHelper.narrow(ob);
00126             } catch (org.omg.CORBA.SystemException se) {                
00127                 logger.info("Failed to lookup SubscriptionManager using: " + SubscriptionManager.instanceName + ". Exception: " + se.getMessage());
00128                 //} catch (ClassNotFoundException ce) {
00129                 //logger.info("Failed to lookup Class name for SubscriptionManagerModule.SubscriptionManager!. Exception: " + ce.getMessage());
00130             } catch (NullPointerException npe) {
00131                 //Do nothing - this must have been caused by not being able to get the partition, which we've already logged
00132             }
00133         }
00134         return subMan;        
00135     }
00136     
00140     public CalibrationController getCalibrationController() {
00141         if (cc == null) {
00142             try {
00143                 org.omg.CORBA.Object ob = lookup(Sct_CalibrationController.CalibrationController.class, CalibrationController.instanceName);
00144                 cc = CalibrationControllerHelper.narrow(ob);
00145             } catch (org.omg.CORBA.SystemException se) {                
00146                 logger.info("Failed to lookup CalibrationController using: " + CalibrationController.instanceName + ". Exception: " + se.getMessage());
00147                 //} catch (ClassNotFoundException ce) {
00148                 //logger.info("Failed to lookup Class name for CalibrationController.CalibrationController!. Exception: " + ce.getMessage());
00149             } catch (NullPointerException npe) {
00150                 //Do nothing - this must have been caused by not being able to get the partition, which we've already logged
00151             }
00152         }
00153         return cc;        
00154     }
00155     
00159     public SctApiIPC getSctApi() {
00160         if (api == null) {
00161             try {
00162                 org.omg.CORBA.Object ob = lookup(Sct_SctApi.SctApiIPC.class, SctApiIPC.instanceName);
00163                 api = SctApiIPCHelper.narrow(ob);
00164             } catch (org.omg.CORBA.SystemException se) {                
00165                 logger.info("Failed to lookup AnalysisService using: " + SctApiIPC.instanceName + " . Exception: " + se.getMessage());
00166                 //} catch (ClassNotFoundException ce) {
00167                 //logger.info("Failed to lookup Class name for Sct_SctApi.SctApiIPC!. Exception: " + ce.getMessage());
00168             } catch (NullPointerException npe) {
00169                 //Do nothing - this must have been caused by not being able to get the partition, which we've already logged
00170             }
00171         }
00172         return api;        
00173     }
00174     
00178     public sctConf.Configuration getConfigurationService() {
00179         if (config == null) {
00180             try {
00181                 org.omg.CORBA.Object ob = lookup(sctConf.Configuration.class, sctConf.Configuration.instanceName); 
00182                 config = sctConf.ConfigurationHelper.narrow(ob);
00183             } catch (org.omg.CORBA.SystemException se) {                
00184                 logger.info("Failed to lookup Configuration using: " + sctConf.Configuration.instanceName + ". Exception: " + se.getMessage());
00185                 //} catch (ClassNotFoundException ce) {
00186                 //logger.info("Failed to lookup Class name for sctConf.Configuration!. Exception: " + ce.getMessage());
00187             } catch (NullPointerException npe) {
00188                 //Do nothing - this must have been caused by not being able to get the partition, which we've already logged
00189             }
00190         }
00191         return config;        
00192     }
00193     
00197     public AnalysisServiceInterface getAnalysisService() {
00198         if (analysis == null) {
00199             try {
00200                 org.omg.CORBA.Object ob = lookup(AnalysisServiceI.AnalysisServiceInterface.class, AnalysisServiceInterface.instanceName);
00201                 analysis = AnalysisServiceInterfaceHelper.narrow(ob);
00202             } catch (org.omg.CORBA.SystemException se) {                
00203                 logger.info("Failed to lookup AnalysisService using: " + AnalysisServiceInterface.instanceName + ". Exception: " + se.getMessage());
00204                 //} catch (ClassNotFoundException ce) {
00205                 //logger.info("Failed to lookup Class name for AnalysisServiceI.AnalysisServiceInterface!. Exception: " + ce.getMessage());
00206             } catch (NullPointerException npe) {
00207                 //Do nothing - this must have been caused by not being able to get the partition, which we've already logged
00208             }
00209         }
00210         return analysis;                
00211     }
00212     
00216     public ArchivingServiceInterface getArchivingService() {
00217         if (archiving == null) {
00218             try {
00219                 org.omg.CORBA.Object ob = lookup(ArchivingServiceI.ArchivingServiceInterface.class, ArchivingServiceInterface.instanceName);
00220                 archiving = ArchivingServiceInterfaceHelper.narrow(ob);
00221             } catch (org.omg.CORBA.SystemException se) {
00222                 logger.info("Failed to lookup ArchivingService using: " + ArchivingServiceInterface.instanceName + ". Exception: " + se.getMessage());
00223                 //} catch (ClassNotFoundException ce) {
00224                 //logger.info("Failed to lookup Class name for ArchivingServiceInterface.ArchivingServiceInterface!. Exception: " + ce.getMessage());
00225             } catch (NullPointerException npe) {
00226                 //Do nothing - this must have been caused by not being able to get the partition, which we've already logged
00227             }
00228         }
00229         return archiving;
00230     }
00231 
00232 
00236     public FitterInterface getFittingService() {
00237         if (fitter == null) {
00238             try {
00239                 org.omg.CORBA.Object ob = lookup(FitterI.FitterInterface.class, FitterInterface.instanceName);
00240                 fitter = FitterInterfaceHelper.narrow(ob);
00241             } catch (org.omg.CORBA.SystemException se) {                
00242                 logger.info("Failed to lookup Fitter using: " + FitterInterface.instanceName + ". Exception: " + se.getMessage());
00243                 //} catch (ClassNotFoundException ce) {
00244                 //logger.info("Failed to lookup Class name for FitterI.FitterInterface!. Exception: " + ce.getMessage());
00245             } catch (NullPointerException npe) {
00246                 //Do nothing - this must have been caused by not being able to get the partition, which we've already logged
00247             }
00248         }
00249         return fitter;                
00250     }
00251     
00253     private SystemInterface() {
00254         logger = Logger.getLogger("GuiComponents.System");     
00255         refresh();
00256     }            
00257     
00259     public org.omg.CORBA.Object lookup(java.lang.Class type, String name){
00260         org.omg.CORBA.Object ob=null;
00261         getPartition();
00262         boolean valid=false;
00263         int ntries=0;
00264         while (valid==false && ntries<maxtries){
00265             if (ob==null || ob._non_existent()) {
00266                 ob=p.lookup(type, name);
00267             }else{
00268                 valid=true;
00269             }
00270             ntries++;
00271         }
00272         if (!valid) {
00273             String message="SystemInterface failed to look up "+name+" after "+maxtries+" attempts";
00274             logger.info(message);
00275             return null;
00276         }else{
00277             return ob;
00278         }
00279     }
00280 
00281     private static SystemInterface instance = new SystemInterface();
00282     private static final String partitionName = "SCT";
00283     private Partition p;
00284     private Logger logger;    
00285     private SctTestApi.Configuration testconfig;
00286     private HighLevelApi highlevel;
00287     private SubscriptionManager subMan;
00288     private CalibrationController cc;
00289     private SctApiIPC api;
00290     private sctConf.Configuration config;
00291     private AnalysisServiceInterface analysis;
00292     private ArchivingServiceInterface archiving;
00293     private FitterInterface fitter;
00294     private static int maxtries=10;
00295 }

Generated on Thu Feb 10 02:44:30 2005 for SCT DAQ/DCS Software - Java by doxygen 1.3.5