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 Sct_SctApi.*;
00015 import AnalysisServiceI.*;
00016 import ArchivingServiceI.*;
00017 import sctConf.*;
00018 import FitterI.*;
00019 
00020 
00032 public class SystemInterface {    
00033     
00037     public static SystemInterface getInstance() {
00038         return instance;
00039     }
00040 
00044     public void refresh() {
00045         p = null;               
00046         testconfig = null;
00047         highlevel = null;
00048         cc = null; 
00049         api = null;
00050         apiDDC = null;
00051         config = null;
00052         analysis = null;
00053         archiving = null;
00054         fitter = null;
00055     }
00056 
00060     public Partition getPartition() {
00061         if (p == null) {
00062             String partitionName = System.getProperty("TDAQ_PARTITION", defaultPartitionName);
00063             if(partitionName.equals("")) partitionName=defaultPartitionName;
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                 //} catch (ClassNotFoundException ce) {
00087                 //logger.info("Failed to lookup Class name for sctConf.Configuration!. Exception: " + ce.getMessage());
00088             } catch (NullPointerException npe) {
00089                 //Do nothing - this must have been caused by not being able to get the partition, which we've already logged
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                 //} catch (ClassNotFoundException ce) {
00109                 //logger.info("Failed to lookup Class name for HighLevelApi.HighLevelApi!. Exception: " + ce.getMessage());
00110             } catch (NullPointerException npe) {
00111                 //Do nothing - this must have been caused by not being able to get the partition, which we've already logged
00112             }
00113         }
00114         return highlevel;
00115     }
00116 
00117 
00121     public CalibrationController getCalibrationController() {
00122         if (cc == null) {
00123             try {
00124                 org.omg.CORBA.Object ob = lookup(Sct_CalibrationController.CalibrationController.class, CalibrationController.instanceName);
00125                 cc = CalibrationControllerHelper.narrow(ob);
00126             } catch (org.omg.CORBA.SystemException se) {                
00127                 logger.info("Failed to lookup CalibrationController using: " + CalibrationController.instanceName + ". Exception: " + se.getMessage());
00128                 //} catch (ClassNotFoundException ce) {
00129                 //logger.info("Failed to lookup Class name for CalibrationController.CalibrationController!. 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 cc;        
00135     }
00136     
00140     public SctApiIPC getSctApi() {
00141         if (api == null) {
00142             try {
00143                 org.omg.CORBA.Object ob = lookup(Sct_SctApi.SctApiIPC.class, SctApiIPC.instanceName);
00144                 api = SctApiIPCHelper.narrow(ob);
00145             } catch (org.omg.CORBA.SystemException se) {                
00146                 logger.info("Failed to lookup SctApi using: " + SctApiIPC.instanceName + " . Exception: " + se.getMessage());
00147                 //} catch (ClassNotFoundException ce) {
00148                 //logger.info("Failed to lookup Class name for Sct_SctApi.SctApiIPC!. 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 api;        
00154     }
00155     
00159     public SctApiDDCServer getSctApiDDCServer() {
00160         if (apiDDC == null) {
00161             try {
00162                 org.omg.CORBA.Object ob = lookup(Sct_SctApi.SctApiDDCServer.class, SctApiDDCServer.instanceName);
00163                 apiDDC = SctApiDDCServerHelper.narrow(ob);
00164             } catch (org.omg.CORBA.SystemException se) {                
00165                 logger.info("Failed to lookup SctApiDDCServer using: " + SctApiDDCServer.instanceName + " . Exception: " + se.getMessage());
00166                 //} catch (ClassNotFoundException ce) {
00167                 //logger.info("Failed to lookup Class name for Sct_SctApi.SctApiDDCServer!. 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 apiDDC;        
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=(org.omg.CORBA.Object)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 defaultPartitionName = "SCT";
00283     private Partition p;
00284     private Logger logger;    
00285     private SctTestApi.Configuration testconfig;
00286     private HighLevelApi highlevel;
00287     private CalibrationController cc;
00288     private SctApiIPC api;
00289     private SctApiDDCServer apiDDC;
00290     private sctConf.Configuration config;
00291     private AnalysisServiceInterface analysis;
00292     private ArchivingServiceInterface archiving;
00293     private FitterInterface fitter;
00294     private static int maxtries=4;
00295 }

Generated on Mon Feb 6 14:12:20 2006 for SCT DAQ/DCS Software - Java by  doxygen 1.4.6