Package org.geowebcache.diskquota.storage

Examples of org.geowebcache.diskquota.storage.Quota


    }

    public void testSaveConfig() throws ConfigurationException, IOException {
        DiskQuotaConfig config = new DiskQuotaConfig();
        List<LayerQuota> quotas = new ArrayList<LayerQuota>();
        LayerQuota lq = new LayerQuota("topp:states", LRU, new Quota(10, StorageUnit.MiB));
        quotas.add(lq);
        config.addLayerQuota(lq);

        File configFile = new File(cacheDir, "geowebcache-diskquota.xml");
        if (configFile.exists()) {
View Full Code Here


        cacheInfoBuilder = new LayerCacheInfoBuilder(cacheRoot, cleanUpExecutorService,
                quotaUsageMonitor);

        for (TileLayer tileLayer : tileLayerDispatcher.getLayerList()) {
            String layerName = tileLayer.getName();
            Quota usedQuota = quotaStore.getUsedQuotaByLayerName(layerName);
            if (usedQuota.getBytes().compareTo(BigInteger.ZERO) > 0) {
                log.debug("Using saved quota information for layer " + layerName + ": "
                        + usedQuota.toNiceString());
            } else {
                log.debug(layerName + " has no saved used quota information,"
                        + "traversing layer cache to compute its disk usage.");
                cacheInfoBuilder.buildCacheInfo(tileLayer);
            }
View Full Code Here

    private void attachConfiguredLayers() throws ConfigurationException {

        final List<LayerQuota> layerQuotas = quotaConfig.getLayerQuotas();

        final ExpirationPolicy globalExpirationPolicy = quotaConfig.getGlobalExpirationPolicyName();
        final Quota globalQuota = quotaConfig.getGlobalQuota();

        int explicitConfigs = 0;

        if (layerQuotas != null) {
            for (LayerQuota layerQuota : layerQuotas) {
                final String layerName = layerQuota.getLayer();
                final ExpirationPolicy policyName = layerQuota.getExpirationPolicyName();
                if (policyName != null) {
                    final Quota quota = layerQuota.getQuota();
                    explicitConfigs++;
                    log.trace("Attaching layer " + layerName + " to quota " + quota
                            + " with expiration policy " + policyName);
                }
            }
View Full Code Here

     * @see {@link org.geowebcache.diskquota.ExpirationPolicy#expireByLayerNames}
     */
    public void expireByLayerNames(final Set<String> layerNames, final QuotaResolver quotaResolver)
            throws InterruptedException {

        Quota limit;
        Quota used;
        Quota excess;

        while (true) {
            if (shutDown || Thread.currentThread().isInterrupted()) {
                throw new InterruptedException();
            }
            // get it everytime in case the admin changed it while we're processsing
            limit = quotaResolver.getLimit();
            used = quotaResolver.getUsed();
            excess = used.difference(limit);
            if (excess.getBytes().compareTo(BigInteger.ZERO) <= 0) {
                log.info("Reached back Quota: " + limit.toNiceString() + " (" + used.toNiceString() + ") for layers "
                        + layerNames);
                return;
            }
            // same thing, check it every time
            ExpirationPolicy expirationPolicy = quotaResolver.getExpirationPolicy();
            if (null == expirationPolicy) {
                log.warn("Aborting disk quota enforcement task, no expiration policy defined for layers "
                        + layerNames);
                return;
            }

            TilePage tilePage = null;
            if (ExpirationPolicy.LFU.equals(expirationPolicy)) {
                tilePage = pageStore.getLeastFrequentlyUsedPage(layerNames);
            } else if (ExpirationPolicy.LRU.equals(expirationPolicy)) {
                tilePage = pageStore.getLeastRecentlyUsedPage(layerNames);
            } else {
                throw new IllegalStateException("Unrecognized expiration policy: "
                        + expirationPolicy);
            }

            if (tilePage == null) {
                limit = quotaResolver.getLimit();
                Quota usedQuota = quotaResolver.getUsed();
                if (excess.getBytes().compareTo(BigInteger.ZERO) > 0) {
                    log.warn("No more pages to expire, check if youd disk quota"
                            + " database is out of date with your blob store. Quota: "
                            + limit.toNiceString() + " used: " + usedQuota.toNiceString());
                }
                return;
            }
            if (log.isDebugEnabled()) {
                log.debug("Expiring tile page " + tilePage + " based on the global "
View Full Code Here

            this.layerQuota = layerQuota;
            this.store = store;
        }

        public Quota getLimit() {
            Quota limit = layerQuota.getQuota();
            if (limit == null) {
                // has the admin disabled specific quota for this layer?
                limit = new Quota(BigInteger.valueOf(Long.MAX_VALUE));
            }
            return limit;
        }
View Full Code Here

            return limit;
        }

        public Quota getUsed() throws InterruptedException {
            String layer = layerQuota.getLayer();
            Quota usedQuotaByLayerName = store.getUsedQuotaByLayerName(layer);
            return usedQuotaByLayerName;
        }
View Full Code Here

        }
        if (globalExpirationPolicyName == null) {
            globalExpirationPolicyName = DEFAULT_GLOBAL_POLICY_NAME;
        }
        if (globalQuota == null) {
            globalQuota = new Quota(500, StorageUnit.MiB);
        }
    }
View Full Code Here

     */
    public void setGlobalQuota(final Quota newQuota) {
        if (newQuota == null) {
            this.globalQuota = null;
        } else {
            this.globalQuota = new Quota(newQuota);
        }
    }
View Full Code Here

            clone = (DiskQuotaConfig) super.clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
        clone.lastCleanUpTime = lastCleanUpTime;
        clone.globalQuota = globalQuota == null ? null : new Quota(globalQuota);
        clone.layerQuotas = layerQuotas == null ? null : new ArrayList<LayerQuota>(layerQuotas);
        return clone;
    }
View Full Code Here

                continue;
            }

            final LayerQuota definedQuotaForLayer = quotaConfig.layerQuota(layerName);
            final ExpirationPolicy policy = definedQuotaForLayer.getExpirationPolicyName();
            final Quota quota = definedQuotaForLayer.getQuota();
            final Quota usedQuota = monitor.getUsedQuotaByLayerName(layerName);

            Quota excedent = usedQuota.difference(quota);
            if (excedent.getBytes().compareTo(BigInteger.ZERO) > 0) {
                log.info("Layer '" + layerName + "' exceeds its quota of " + quota.toNiceString()
                        + " by " + excedent.toNiceString() + ". Currently used: "
                        + usedQuota.toNiceString() + ". Clean up task will be performed"
                        + " using expiration policy " + policy);

                Set<String> layerNames = Collections.singleton(layerName);
                QuotaResolver quotaResolver;
                quotaResolver = monitor.newLayerQuotaResolver(layerName);

                LayerQuotaEnforcementTask task;
                task = new LayerQuotaEnforcementTask(layerNames, quotaResolver, monitor);
                Future<Object> future = this.cleanUpExecutorService.submit(task);
                perLayerRunningCleanUps.put(layerName, future);
            }
        }

        if (globallyManagedLayerNames.size() > 0) {
            ExpirationPolicy globalExpirationPolicy = quotaConfig.getGlobalExpirationPolicyName();
            if (globalExpirationPolicy == null) {
                return;
            }
            final Quota globalQuota = quotaConfig.getGlobalQuota();
            if (globalQuota == null) {
                log.info("There's not a global disk quota configured. The following layers "
                        + "will not be checked for excess of disk usage: "
                        + globallyManagedLayerNames);
                return;
            }

            if (globalCleanUpTask != null && !globalCleanUpTask.isDone()) {
                log.debug("Global cache quota enforcement task still running, avoiding issueing a new one...");
                return;
            }

            Quota globalUsedQuota = monitor.getGloballyUsedQuota();
            Quota excedent = globalUsedQuota.difference(globalQuota);

            if (excedent.getBytes().compareTo(BigInteger.ZERO) > 0) {

                log.info("Submitting global cache quota enforcement task");
                LayerQuotaEnforcementTask task;
                QuotaResolver quotaResolver = monitor.newGlobalQuotaResolver();
                task = new LayerQuotaEnforcementTask(globallyManagedLayerNames, quotaResolver,
View Full Code Here

TOP

Related Classes of org.geowebcache.diskquota.storage.Quota

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.