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

JetWebConfig.java

Go to the documentation of this file.
00001 package cedar.jetweb;
00002 
00003 import cedar.jetweb.db.DBConfig;
00004 import cedar.jetweb.db.DBObjectManager;
00005 import cedar.jetweb.db.DBConnectionManager;
00006 
00007 import cedar.jetweb.batch.*;
00008 
00009 import cedar.jetweb.util.ThreadPool;
00010 import cedar.jetweb.model.RunSeries;
00011 import cedar.jetweb.model.PDF;
00012 import cedar.jetweb.model.plots.PlotSwitch;
00013 import cedar.jetweb.model.fit.Fit;
00014 
00015 import java.io.PrintWriter;
00016 import java.awt.Color;
00017 import javax.swing.ImageIcon;
00018 import java.awt.Component;
00019 import java.util.Hashtable;
00020 import java.util.HashMap;
00021 import java.util.List;
00022 import java.util.Date;
00023 import java.util.Random;
00024 import java.util.Enumeration;
00025 import java.text.SimpleDateFormat;
00026 import java.text.DecimalFormat;
00027 
00036 public abstract class JetWebConfig {
00037 
00038     // rather than have abstract utility classes, I prefer to have static
00039     // instances of the objects that provide the utility here.
00040     // 
00041     
00042     //public static DBObjectManager dbObjectManager = new DBObjectManager();
00043 
00044     public static DBConnectionManager dbConnectionManager;
00045 
00046     private static final String JETWEB_PROPERTIES="jetweb";
00047 
00049     public static String graphicsType = "png";
00050 
00052     public static SimpleDateFormat timeStamp = new SimpleDateFormat("yyyyMMddhhmmss");
00053 
00055     public static boolean writePlots;
00056 
00058     public static ThreadPool graphicsThreadPool;
00059 
00061     public static  String serverName;
00063     public static  String rootDirectory;
00065     public static  String storeDirName;
00067     public static  String jobOutDirName;
00069     public static  String jobInDirName;
00071     private static  String scriptDirName;
00073     public static  String plotCacheDirName;
00075     public static  String templateDirName;
00077     public static  String spoolDirName;
00078 
00080     public static final String MAINTAINER="Maintainer";
00082     public static final String SEARCHER="Searcher";
00084     public static  String mainServletPath;
00086     public static  String searchServletPath;
00088     public static  String uploadServletPath;
00090     public static  String execs;
00092     public static String spiresURL;
00093 
00094     public static boolean isServlet = true;
00095 
00097     public static String getScriptDirName(){
00098     return rootDirectory+"/"+scriptDirName;
00099     }
00100 
00101     public static Random random;
00102 
00103     private static DecimalFormat form = new DecimalFormat("0.###E0");
00108     public static DecimalFormat getFormat(){return form;}
00109 
00111     public static ImageIcon logo;
00112 
00114     public static Hashtable template = new Hashtable();
00115 
00117     private static Hashtable<String,List<? extends Object>> resultLists = new Hashtable<String,List<? extends Object>>();
00121     public static final int LISTCHECKINTERVAL=600000;
00123     public static final int RESULTKEEPTIME=600000;
00124 
00125     private static  Thread listMonitor = null;
00126 
00128     public static final PDF defaultPhotonPDF = new PDF("GRV-G HO DIS NLO");
00130     public static final PDF defaultProtonPDF = new PDF("MRST2004nnlo");
00131 
00133     public static final double SMALLDOUBLE = 0.00001;
00134 
00136     public static boolean SERVLET_MODE_ON;
00137 
00139     public static Component CONTROLSCREEN;
00140 
00141     private static PrintWriter out;
00143     public static void setPrintWriter(PrintWriter out){JetWebConfig.out = out;}
00145     public static PrintWriter getPrintWriter(){return out;}
00146 
00147     private static String HTMLRoot;
00148     public static String getHTMLRoot(){return HTMLRoot;}
00149 
00151     public static double lowScale  = 0.5;
00153     public static double highScale = 2.0;
00155     public static double scaleIncrement = 0.05;
00156 
00157     private static boolean initialised = false;
00158 
00159     private static void loadProperties(){
00160 
00161       java.util.ResourceBundle bundle =  
00162       java.util.ResourceBundle.getBundle(JETWEB_PROPERTIES);
00163 
00164       java.util.Enumeration propNames = bundle.getKeys();
00165       while (propNames.hasMoreElements()){
00166       String name = (String)propNames.nextElement();
00167       //System.out.println("Property "+name+":"+bundle.getString(name));
00168 
00169       if(name.length()!=0){
00170           System.setProperty(name,bundle.getString(name));
00171       }
00172       //System.out.println("System Property "+name+":"+System.getProperty(name));
00173       }
00174     }
00181     public static void init(){
00182     
00183     if (initialised) {return;}
00184     
00185     isServlet = true;
00186 
00187     // Initialise random number generator (uses time as the seed).
00188     random = new Random();
00189     
00190     loadProperties();
00191     
00192     HTMLRoot = System.getProperty("htmlRoot");
00193 
00194     spiresURL = System.getProperty("spiresURL");
00195     
00196     rootDirectory = System.getProperty("home");
00197      
00198     
00199     if (rootDirectory==null){
00200         System.out.println("WARNING: JETWEB_HOME has not been set");
00201     } else {
00202         System.out.println("JETWEB_HOME set to "+rootDirectory);
00203         System.out.println("htmlRoot set to "+HTMLRoot);
00204     }
00205     
00206     jobOutDirName  = System.getProperty("outputJobCache");
00207     
00208     jobInDirName  = System.getProperty("inputJobCache");
00209     
00210     scriptDirName  = "scripts";
00211     
00212     serverName = System.getProperty("jwserver");
00213     plotCacheDirName = serverName+"-plots";
00214 
00215     templateDirName = System.getProperty("templateDir");
00216     spoolDirName = System.getProperty("spoolDir");
00217     
00218     mainServletPath  = HTMLRoot+"/"+serverName+"/"
00219         +System.getProperty("mainServlet");
00220     searchServletPath= HTMLRoot+"/"+serverName+"/"
00221         +System.getProperty("searchServlet");
00222     uploadServletPath= HTMLRoot+"/"+serverName+"/"
00223         +System.getProperty("uploadServlet");
00224 
00225     storeDirName=System.getProperty("storeDirectory");
00226 
00227     execs = System.getProperty("execs");
00228 
00229     // Initialise the database configuration
00230     DBConfig.init();
00231 
00232     //add the hepdata DB to the list of known databases:
00233     //not implemented for now
00234     //dbConnectionManager = 
00235     //  DBConfig.getDBConnectionManager().init("hepdata");
00236 
00237     //dbObjectManager.passDBConnection(dbConnectionManager);
00238 
00239     // Initialise the plot switching
00240     PlotSwitch.initializeParameterList();
00241 
00242     if (System.getProperty("writePlots").equalsIgnoreCase("false")){
00243         writePlots = false;
00244     } else {
00245         writePlots = true;
00246     }
00247 
00248     graphicsThreadPool = new ThreadPool("writeGraphics threads",4,30000);
00249     graphicsThreadPool.start();
00250 
00251     SubmitScriptHandler.setBatchFacility(System.getProperty("batchFacility"));
00252 
00253     SERVLET_MODE_ON = true;
00254 
00255 
00256     System.setProperty("javax.xml.parsers.SAXParserFactory",
00257                "org.apache.xerces.jaxp.SAXParserFactoryImpl");
00258 
00259 
00260     startListMonitor();
00261 
00262 
00263 
00264 
00265     initialised = true;
00266 
00267 
00268 
00269     }
00270     
00276     public static void startListMonitor(){
00277     
00278     
00279     listMonitor = new Thread(new Runnable(){
00280         public void run(){ 
00281             // HTMLWriter.writeBib(JetWebConfig.getHTMLRoot()); }
00282             Thread myThread = Thread.currentThread();
00283             while (listMonitor == myThread) {
00284             //System.out.println("Checking ResultLists");
00285             checkLists();
00286             try {
00287                 Thread.sleep(LISTCHECKINTERVAL);
00288             } catch (InterruptedException e){
00289                 // the VM doesn't want us to sleep anymore,
00290                 // so get back to work
00291             }
00292             }
00293         }
00294         });
00295     listMonitor.start();
00296     
00297     }
00298     
00299     
00300     private static void checkLists(){
00301 
00302     Enumeration<String> keys = resultLists.keys();
00303     //if (resultLists.isEmpty()) System.out.println("result lists are empty");
00304     Date now = new Date();
00305     long nowValue = now.getTime();
00306     while (keys.hasMoreElements()){
00307         try {
00308         String key = (String)keys.nextElement();
00309         long keyValue = (new Long(key)).longValue();
00310         System.out.println("ListTime:"+keyValue+"NowTime"+nowValue);
00311         long diff = nowValue-keyValue;
00312         System.out.println("NowTime-ListTime"+diff);
00313             if (diff>RESULTKEEPTIME){
00314             resultLists.remove(key);
00315             System.out.println("ListRemoved");
00316         }
00317         
00318         } catch (Exception e){
00319         }
00320     }
00321     
00322     
00323     }
00324  
00328     public static String cacheList(List<? extends Object> resultList){
00329     System.out.println("List Cached");
00330     String newKey=generateResultListKey();
00331     resultLists.put(newKey,resultList);
00332     return newKey;
00333     }
00337     private static String generateResultListKey(){
00338 
00339     Date now = new Date();
00340     return Long.toString(now.getTime());
00341     
00342 
00343     
00344     }
00348     public synchronized static List<? extends Object> getResultList(String listKey){
00349     List<? extends Object> test = resultLists.get(listKey);
00350     if (test!=null)
00351         return test;
00352     return null;
00353     }
00354 
00359     public static String stripRoot(String root, String path){
00360 
00361     System.out.println("Stripping "+root+" from "+path);
00362     if (path.startsWith(root)){
00363         String relPath = path.substring(root.length()+1);
00364         System.out.println(relPath);
00365         return relPath;
00366     } else {
00367         System.out.println(path);
00368         return path;
00369     }
00370     }
00371 }
00372 
00373 
00374 
00375 
00376 
00377 
00378 
00379 
00380 
00381 
00382 
00383 
00384 
00385 

Generated Wed Jan 17 09:14:27 GMT 2007