/** * Guaranteed to be called by the superclass as part of the initialization. */ @Override public void refreshMetadata() { try { lock.writeLock().lock(); log.debug("Clearing metadata cache"); // Clear the caches so they get reinitialized as needed from the new data this.aliasCache = new HashMap<String, String>(); this.basicMetadataCache = new HashMap<String, EntityDescriptor>(); this.hashMetadataCache = new HashMap<byte[], EntityDescriptor>(); this.extendedMetadataCache = new HashMap<String, ExtendedMetadata>(); // Do whatever it takes to refresh the metadata super.refreshMetadata(); } finally { lock.writeLock().unlock(); } }
/** * Method must be called after provider construction. It creates the refresh timer and refreshes the metadata for * the first time. * * @throws MetadataProviderException error */ public final void afterPropertiesSet() throws MetadataProviderException { Assert.notNull(keyManager, "KeyManager must be set"); // Create timer if needed if (refreshCheckInterval > 0) { log.debug("Creating metadata reload timer with interval {}", refreshCheckInterval); this.timer = new Timer("Metadata-reload", true); this.timer.schedule(new RefreshTask(), refreshCheckInterval, refreshCheckInterval); } else { log.debug("Metadata reload timer is not created, refreshCheckInternal is {}", refreshCheckInterval); } refreshMetadata(); }
@Override public void run() { try { log.trace("Executing metadata refresh task"); // Invoking getMetadata performs a refresh in case it's needed // Potentially expensive operation, but other threads can still load existing cached data for (MetadataProvider provider : getProviders()) { provider.getMetadata(); } // Refresh the metadataManager if needed if (isRefreshRequired()) { if (isRefreshNowAndClear()) { refreshMetadata(); } } } catch (Throwable e) { log.warn("Metadata refreshing has failed", e); } }