Package com.volantis.mcs.policies

Examples of com.volantis.mcs.policies.CacheControl


    // Javadoc inherited.
    public ProviderResult retrieve(
            SystemClock clock, Object key, CacheEntry entry) {

        CacheControl cacheControl;
        ActivatedPolicy policy;
        Throwable throwable = null;
        try {
            policy = retriever.retrievePolicy(project, name);

            // todo need to be able to handle the case where the policy could
            // todo not be retrieved but the project for the policy was found
            // todo and is not the same as the supplied one. i.e. when a
            // todo request is made to a remote repository which finds the
            // todo project for the policy but not the policy. The reason we
            // todo need to do that is because we need to use the actual
            // todo project for the policy to get default cache control stuff.

            if (policy == null) {
                cacheControl = cache.getDefaultCacheControl(project, key);
            } else {
                // Determine whether the policy is cacheable.
                cacheControl = policy.getCacheControl();
            }

        } catch (Throwable e) {
            // Catch all exceptions so that they will trigger the retry
            // mechanism if configured.
            if (logger.isErrorEnabled()) {
                logger.error(e);
            }

            cacheControl = cache.getDefaultCacheControl(project, key);
            policy = null;

            // Remember the throwable so that it can be returned back to the
            // cache which will place the entry into the error state.
            throwable = e;
        }

        // If this is cacheable then update the state, either the one
        // associated with the entry, or a newly created one if the entry has
        // not been supplied, or does not have one. The latter will only occur
        // if this is the first time that a policy is being retrieved for the
        // entry.
        //
        // If this is not cacheable then there is no point in updating the
        // state as while it will be stored in the entry it will not be used.
        // Therefore, in that case return null so that state based on an
        // uncacheable policy is not stored in the entry.

        final boolean cacheable = cacheControl.getCacheThisPolicy();
        CachedPolicyState state = null;
        if (cacheable) {

            ActivatedPolicy expiredPolicy = null;
View Full Code Here


    // Javadoc inherited.
    public CacheControl getDefaultCacheControl(
            RuntimeProject project, Object key) {

        CacheControl defaults = project.getCacheControlDefaults();
        if (defaults == null) {
            if (key instanceof ProjectSpecificKey) {
                // Local so return local defaults.
                defaults = localPartitionConstraints.getConstraints()
                        .getDefaultCacheControl();;
View Full Code Here

        }

        // Create the default CacheControlBuilder.
        PolicyFactory factory = PolicyFactory.getDefaultInstance();

        CacheControl baseCacheControl = base.getDefaultCacheControl();

        CacheControlBuilder builder = factory.createCacheControlBuilder();
        builder.setCacheThisPolicy(getBoolean(
                configuration.getDefaultCacheThisPolicy(),
                baseCacheControl.getCacheThisPolicy()));
        builder.setRetainDuringRetry(getBoolean(
                configuration.getDefaultRetainDuringRetry(),
                baseCacheControl.getRetainDuringRetry()));
        builder.setRetryFailedRetrieval(getBoolean(
                configuration.getDefaultRetryFailedRetrieval(),
                baseCacheControl.getRetryFailedRetrieval()));
        builder.setRetryInterval(getInteger(
                configuration.getDefaultRetryInterval(),
                baseCacheControl.getRetryInterval()));
        builder.setRetryMaxCount(getInteger(
                configuration.getDefaultRetryMaxCount(),
                baseCacheControl.getRetryMaxCount()));
        builder.setTimeToLive(getInteger(configuration.getDefaultTimeToLive(),
                baseCacheControl.getTimeToLive()));

        // Force the defaults to adhere to restrictions.
        applyConstraints(builder);

        // Force the builder to create the cache control so that it can be
View Full Code Here

        RemotePolicyCacheConfiguration configuration =
                new RemotePolicyCacheConfiguration();
        configuration.setMinRetryInterval(new Integer(100));
        configuration.setDefaultRetryInterval(new Integer(50));
        CacheControlConstraints constraints = new CacheControlConstraints(configuration);
        CacheControl cacheControl = constraints.getDefaultCacheControl();

        assertEquals(100, cacheControl.getRetryInterval());
    }
View Full Code Here

        RemotePolicyCacheConfiguration configuration =
                new RemotePolicyCacheConfiguration();
        configuration.setMinRetryInterval(new Integer(100));
        configuration.setDefaultRetryInterval(new Integer(150));
        CacheControlConstraints constraints = new CacheControlConstraints(configuration);
        CacheControl cacheControl = constraints.getDefaultCacheControl();

        assertEquals(150, cacheControl.getRetryInterval());
    }
View Full Code Here

        CacheControlConstraints constraints = new CacheControlConstraints(configuration);
        CacheControlBuilder builder = policyFactory.createCacheControlBuilder();
        builder.setRetryInterval(50);
        constraints.applyConstraints(builder);

        CacheControl cacheControl = builder.getCacheControl();
        assertEquals(100, cacheControl.getRetryInterval());
    }
View Full Code Here

        CacheControlConstraints constraints = new CacheControlConstraints(configuration);
        CacheControlBuilder builder = policyFactory.createCacheControlBuilder();
        builder.setRetryInterval(150);
        constraints.applyConstraints(builder);

        CacheControl cacheControl = builder.getCacheControl();
        assertEquals(150, cacheControl.getRetryInterval());
    }
View Full Code Here

        RemotePolicyCacheConfiguration configuration =
                new RemotePolicyCacheConfiguration();
        configuration.setMaxRetryMaxCount(new Integer(100));
        configuration.setDefaultRetryMaxCount(new Integer(150));
        CacheControlConstraints constraints = new CacheControlConstraints(configuration);
        CacheControl cacheControl = constraints.getDefaultCacheControl();

        assertEquals(100, cacheControl.getRetryMaxCount());
    }
View Full Code Here

        RemotePolicyCacheConfiguration configuration =
                new RemotePolicyCacheConfiguration();
        configuration.setMaxRetryMaxCount(new Integer(100));
        configuration.setDefaultRetryMaxCount(new Integer(50));
        CacheControlConstraints constraints = new CacheControlConstraints(configuration);
        CacheControl cacheControl = constraints.getDefaultCacheControl();

        assertEquals(50, cacheControl.getRetryMaxCount());
    }
View Full Code Here

        CacheControlConstraints constraints = new CacheControlConstraints(configuration);
        CacheControlBuilder builder = policyFactory.createCacheControlBuilder();
        builder.setRetryMaxCount(150);
        constraints.applyConstraints(builder);

        CacheControl cacheControl = builder.getCacheControl();
        assertEquals(100, cacheControl.getRetryMaxCount());
    }
View Full Code Here

TOP

Related Classes of com.volantis.mcs.policies.CacheControl

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.