/** Stops this store service. */ public void stop() throws IOException { ResettableTimer timer = (ResettableTimer) m_timerRef.get(); if (timer != null) { if (!timer.isShutDown()) { // Shutdown and await termination... timer.shutDown(); } // Clear reference... m_timerRef.compareAndSet(timer, null); } // Write the latest version to disk... flush(); }
/** {@inheritDoc} */ public void updated(Dictionary properties) throws ConfigurationException { boolean writeDisabled = DEFAULT_WRITE_DISABLED; int writeDelayValue = DEFAULT_WRITE_DELAY_VALUE; TimeUnit writeDelayUnit = DEFAULT_WRITE_DELAY_TIMEUNIT; if (properties != null) { Object wd = properties.get(KEY_WRITE_DISABLED); if (wd == null) { throw new ConfigurationException(KEY_WRITE_DISABLED, "Missing write disabled value!"); } try { writeDisabled = Boolean.parseBoolean((String) wd); } catch (Exception e) { throw new ConfigurationException(KEY_WRITE_DISABLED, "Invalid write disabled value!"); } if (!writeDisabled) { Object wdv = properties.get(KEY_WRITE_DELAY_VALUE); if (wdv == null) { throw new ConfigurationException(KEY_WRITE_DELAY_VALUE, "Missing write delay value!"); } try { writeDelayValue = Integer.parseInt((String) wdv); } catch (Exception e) { throw new ConfigurationException(KEY_WRITE_DELAY_VALUE, "Invalid write delay value!"); } if (writeDelayValue <= 0) { throw new ConfigurationException(KEY_WRITE_DELAY_VALUE, "Invalid write delay value!"); } Object wdu = properties.get(KEY_WRITE_DELAY_TIMEUNIT); if (wdu != null) { try { writeDelayUnit = TimeUnit.valueOf(((String) wdu).toUpperCase()); } catch (Exception e) { throw new ConfigurationException(KEY_WRITE_DELAY_TIMEUNIT, "Invalid write delay unit!"); } } } } ResettableTimer timer = (ResettableTimer) m_timerRef.get(); if (timer != null) { timer.shutDown(); } m_timerRef.compareAndSet( timer, writeDisabled ? null : new ResettableTimer(this, writeDelayValue, writeDelayUnit)); }
/** * Notifies the background timer to schedule a task for storing the contents of this store to * disk. */ private void scheduleTask() { ResettableTimer timer = (ResettableTimer) m_timerRef.get(); if (timer != null && !timer.isShutDown()) { timer.schedule(); } }