def init(self, cfg=None): """ This method will be called twice, once with a cfg parameter and once without """ if cfg is None: HttpServlet.init(self) else: HttpServlet.init(self, cfg) # These are the things we only do once if WMS.timer is None: WMS.timer = Timer(1) # timer is a daemon # Load the Log4j configuration file file = self.getInitParameter("log4j-init-file") if file is not None: prefix = self.getServletContext().getRealPath("/") PropertyConfigurator.configure(prefix + file) WMS.logger.debug("Initialized logging system") # Initialize the cache of datasets DatasetCache.init() WMS.logger.debug("Initialized DatasetCache") # Start a timer that will clear the cache at regular intervals # so that NcML aggregations are reloaded # TODO: get the interval value from a config file intervalInMs = int(60 * 1000) # Runs once a minute WMS.cacheWiper = CacheWiper() WMS.timer.scheduleAtFixedRate(WMS.cacheWiper, intervalInMs, intervalInMs) WMS.logger.debug("Initialized NetcdfDatasetCache refresher") WMS.logger.debug("ncWMS Servlet initialized")
def getVariableMetadata(location): """ returns a dictionary of VariableMetadata objects. The keys in the dictionary are the unique ids of the variables and the values are VariableMetadata objects location = location of dataset (full file path, OPeNDAP URL etc) """ # Get the dataset from the cache return DatasetCache.getVariableMetadata(location)
def destroy(self): DatasetCache.exit() if WMS.timer is not None: WMS.timer.cancel() WMS.logger.debug("ncWMS Servlet destroyed")
def run(self): DatasetCache.clear() self.timeLastRan = time.time() self.logger.debug("Cleared cache")