Changeset 2326


Ignore:
Timestamp:
Apr 7, 2014, 4:31:23 PM (9 years ago)
Author:
olle
Message:

Refs #529. Lab environment extension updated to report in the BASE window, when configuration file labenv-config.xml is missing, in which case the extension cannot start. Also, the configuration file is now reloaded every time the extension starts, even is the Tomcat server isn't restarted:

  1. Singleton class/file LabEnvironment updated with new new public method void reloadLabEnvironmentConfiguration(), for forcing a reload of the configuration file.
  2. Class/file LabEnvironmentConfiguration updated in private method void fetchConfiguration() to forward the contents of a caught exception as a RuntimeException, avoiding the need to declare that a number of methods in other classes throw exceptions.
  3. Class/file LabEnvService.java in src/net/sf/basedb/labenv/service/ updated in public method void start() to call new public method void reloadLabEnvironmentConfiguration() in class LabEnvironment, and to forward the contents of a caught exception as a RuntimeException, which doesn't violate the ServiceControllerAction Interface.
  4. Class/file LabEnvironmentServlet.java in src/net/sf/basedb/labenv/servlet/ updated in private method JSONObject createLabSensorConfigList(JSONObject json) to no longer forward exceptions thrown by the LabEnvironment instance recast as a ServletException.
  5. Class/file LabEnvironmentStatisticsServlet.java in src/net/sf/basedb/labenv/servlet/ updated in private methods JSONArray createLabEnvironmentDailyDistributionReport(JSONArray jsonStatisticsPlotArray, List<LabEnvironmentData> lthdList, Date startDate, Date endDate, String chartVariant, String viewType, String sensorName, String weekdayFilter) and String fetchChartTitle(String viewType, String variableType, Date startDate, Date endDate, String weekdayFilter) to no longer forward exceptions thrown by the LabEnvironment instance recast as a ServletException.
  6. Class/file LabEnvironmentStorageUtil.java in src/net/sf/basedb/labenv/util/ updated in public constructor LabEnvironmentStorageUtil() and public method List<LabEnvironmentData> queryLabEnvDb(Integer sensorNumber, Date startTime, Date endTime) to no longer catch exceptions thrown by the LabEnvironment instance and print its content to standard output.
Location:
extensions/net.sf.basedb.labenv/trunk/src/net/sf/basedb/labenv
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.labenv/trunk/src/net/sf/basedb/labenv/LabEnvironment.java

    r2321 r2326  
    2929
    3030  protected LabEnvironment()
    31     throws Exception
    3231  {
    3332    // Exists only to defeat instantiation
     
    4342
    4443  public static LabEnvironment getInstance()
    45     throws Exception
    4644  {
    4745    if (instance == null)
     
    5755  {
    5856    return this.labEnvironmentConfiguration;
     57  }
     58
     59  public void reloadLabEnvironmentConfiguration()
     60  {
     61    this.labEnvironmentConfiguration = new LabEnvironmentConfiguration();
    5962  }
    6063
  • extensions/net.sf.basedb.labenv/trunk/src/net/sf/basedb/labenv/LabEnvironmentConfiguration.java

    r2321 r2326  
    134134
    135135  public LabEnvironmentConfiguration()
    136     throws Exception
    137136  {
    138137    // Get configuration from configuration file
     
    146145  @SuppressWarnings("unchecked")
    147146  private void fetchConfiguration()
    148     throws Exception
    149147  {
    150148    //String logPrefix = "LabEnvironmentConfiguration:: fetchConfiguration(): ";
     
    303301        log.debug("Exception thrown when accessing configuration file labenv-config.xml: " + e);
    304302        //System.out.println(logPrefix + "Exception thrown when accessing configuration file " + confFilePath + ": " + e);
    305         throw e;
     303        throw new RuntimeException("Exception thrown when accessing configuration file labenv-config.xml: " + e.getMessage());
    306304      }
    307305  }
  • extensions/net.sf.basedb.labenv/trunk/src/net/sf/basedb/labenv/service/LabEnvService.java

    r2313 r2326  
    117117        this.labEnvironment = LabEnvironment.getInstance();
    118118      }
     119      // Force reloading configuration file when service is started again
     120      labEnvironment.reloadLabEnvironmentConfiguration();
    119121      // Set timer interval from configuration
    120122      long measurementIntervalInSeconds = getLabEnvironment().getLabEnvironmentConfiguration().getMeasurementIntervalInSeconds();
     
    142144    catch (Exception e)
    143145    {
    144       System.out.println(new Date() + " Exception thrown when trying to start service LabEnv: " + e);
     146      //System.out.println(new Date() + " Exception thrown when trying to start service LabEnv: " + e);
     147      throw new RuntimeException(e.getMessage());
    145148    }
    146149  }
     
    162165    }
    163166    running = false;
     167    System.out.println(new Date() + " Service LabEnv stopped. running = " + running);
    164168  }
    165169  // ---------------------------------------------
  • extensions/net.sf.basedb.labenv/trunk/src/net/sf/basedb/labenv/servlet/LabEnvironmentServlet.java

    r2321 r2326  
    354354    //System.out.println("\n" + logPrefix + "Start " + new Date());
    355355    // Get lab environment configuration from singleton LabEnvironment
    356     LabEnvironment labEnvironment;
    357     try
    358     {
    359       labEnvironment = LabEnvironment.getInstance();
    360     }
    361     catch (Exception e)
    362     {
    363       throw new ServletException("Exception thrown when trying to get LabEnvironment instance: " + e);
    364     }
     356    LabEnvironment labEnvironment = LabEnvironment.getInstance();
    365357    LabEnvironmentConfiguration labEnvironmentConfiguration = labEnvironment.getLabEnvironmentConfiguration();
    366358    List<LabSensorConfig> labSensorConfigList = labEnvironmentConfiguration.getLabSensorConfigList();
  • extensions/net.sf.basedb.labenv/trunk/src/net/sf/basedb/labenv/servlet/LabEnvironmentStatisticsServlet.java

    r2321 r2326  
    276276    List<String> viewTypeList = new ArrayList<String>();
    277277    // Get lab environment configuration from singleton LabEnvironment
    278     LabEnvironment labEnvironment;
    279     try
    280     {
    281       labEnvironment = LabEnvironment.getInstance();
    282     }
    283     catch (Exception e)
    284     {
    285       throw new ServletException("Exception thrown when trying to get LabEnvironment instance: " + e);
    286     }
     278    LabEnvironment labEnvironment = LabEnvironment.getInstance();
    287279    LabEnvironmentConfiguration labEnvironmentConfiguration = labEnvironment.getLabEnvironmentConfiguration();
    288280    List<LabSensorConfig> labSensorConfigList = labEnvironmentConfiguration.getLabSensorConfigList();
     
    949941      // Set report start date to earliest configured sensor start date
    950942      // Get lab environment configuration from singleton LabEnvironment
    951       LabEnvironment labEnvironment;
    952       try
    953       {
    954         labEnvironment = LabEnvironment.getInstance();
    955       }
    956       catch (Exception e)
    957       {
    958         throw new ServletException("Exception thrown when trying to get LabEnvironment instance: " + e);
    959       }
     943      LabEnvironment labEnvironment = LabEnvironment.getInstance();
    960944      LabEnvironmentConfiguration labEnvironmentConfiguration = labEnvironment.getLabEnvironmentConfiguration();
    961945      List<LabSensorConfig> labSensorConfigList = labEnvironmentConfiguration.getLabSensorConfigList();
  • extensions/net.sf.basedb.labenv/trunk/src/net/sf/basedb/labenv/util/LabEnvironmentStorageUtil.java

    r2321 r2326  
    3434import java.util.Date;
    3535import java.util.List;
    36 import javax.servlet.ServletException;
    3736
    3837import org.apache.log4j.Logger;
     
    6362    //String logPrefix = "LabEnvironmentStorageUtil:: LabEnvironmentStorageUtil(): ";
    6463    // Get lab environment configuration
    65     LabEnvironment labEnvironment = null;
    66     try
    67     {
    68       labEnvironment = LabEnvironment.getInstance();
    69     }
    70     catch (Exception e)
    71     {
    72       System.out.println(new Date() + " LabEnvironmentStorageUtil(): Exception thrown when trying to get LabEnvironment instance: " + e);
    73     }
     64    LabEnvironment labEnvironment = LabEnvironment.getInstance();
    7465    LabEnvironmentConfiguration labEnvironmentConfiguration = labEnvironment.getLabEnvironmentConfiguration();
    7566    String dbFileNameConf = labEnvironmentConfiguration.getDbFileName();
     
    287278    }
    288279    // Get lab environment configuration from singleton LabEnvironment
    289     LabEnvironment labEnvironment = null;
    290     try
    291     {
    292       labEnvironment = LabEnvironment.getInstance();
    293     }
    294     catch (Exception e)
    295     {
    296       System.out.println(new Date() + " LabEnvironmentStorageUtil(): Exception thrown when trying to get LabEnvironment instance: " + e);
    297     }
     280    LabEnvironment labEnvironment = LabEnvironment.getInstance();
    298281    LabEnvironmentConfiguration labEnvironmentConfiguration = labEnvironment.getLabEnvironmentConfiguration();
    299282    List<LabEnvironmentData> labEnvironmentDataList = new ArrayList<LabEnvironmentData>();
Note: See TracChangeset for help on using the changeset viewer.