Package com.volantis.shared.system

Examples of com.volantis.shared.system.SystemClock


        // create request method and configure it
        final GetMethod method = new GetMethod(url.toExternalForm());
        method.setFollowRedirects(true);

        // create cache information object
        SystemClock clock = SystemClock.getDefaultInstance();
        CachedHttpContentStateBuilder cacheBuilder = new CachedHttpContentStateBuilder();
        cacheBuilder.setMethodAccessor(
            ResponseHeaderAccessorFactory.getDefaultInstance().
                createHttpClientResponseHeaderAccessor(method));
        cacheBuilder.setRequestTime(clock.getCurrentTime());

        // save request headers to request method
        setRequestHeaders(method, headers);

        DefaultRepresentation responseInfo = null;

        // execute request
        try {
            httpClient.executeMethod(method);
        } catch (IOException e) {
            throw new ResourceRetrieverException(exceptionLocalizer.format(
                    "connection-refused", url.toString()), e);
        }

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Requested resource at: " + url.toString());
        }

        // If the get failed then return immediately.
        if (method.getStatusCode() == 200) {

            // get response caching information
            cacheBuilder.setResponseTime(clock.getCurrentTime());

            // read resource stream
            InputStream stream = method.getResponseBodyAsStream();

            // a custom closer to ensure the method releases its connection
View Full Code Here


        }
        if (enabled) {
            final CacheBuilder cacheBuilder =
                CacheFactory.getDefaultInstance().createCacheBuilder();
            cacheBuilder.setMaxCount(maxEntries);
            final SystemClock clock = SystemClock.getDefaultInstance();
            cacheBuilder.setClock(clock);
            cacheBuilder.setExpirationChecker(
                new URLContentValidationChecker());
            cache = cacheBuilder.buildCache();
        } else {
View Full Code Here

        assertFalse(async.isReady());

        CacheEntry entry = async.getEntry();
        assertNotNull(entry);

        final SystemClock clock = SystemClock.getDefaultInstance();
        ProviderResult result = new ProviderResult(new Integer(1),
            cache.getRootGroup(), true,
            new PipelineCacheState(
                clock.getCurrentTime().addPeriod(Period.inSeconds(2))));
        async.update(result);

        CacheableObjectProvider cacheableObjectProvider =
            new ExpiredObjectsRemainExpiredCacheableObjectProvider(cache.getRootGroup());
        assertNotNull("Integer object is retrievable via the cache",
View Full Code Here

import junit.framework.TestCase;

public class PipelineCacheStateTestCase extends TestCase {

    public void testLimitedTimeToLive() throws Exception {
        final SystemClock clock = SystemClock.getDefaultInstance();
        final Period period = CacheControlRule.calculateTimeToLive("2");    // 2 seconds

        final PipelineCacheState pcs = new PipelineCacheState(
            clock.getCurrentTime().addPeriod(period));

        assertFalse("Hasn't expired yet", pcs.hasExpired(clock));

        assertTrue("Has expired when we tweak the system time",
                pcs.hasExpired(new SystemClock() {

            // javadoc inherited
            public Time getCurrentTime() {
                // return now + 3 seconds
                return Time.inMilliSeconds(
                        clock.getCurrentTime().inMillis() + 3000);
            }
        }));
    }
View Full Code Here

            }
        }));
    }

    public void testNeverExpires()  throws Exception {
        final SystemClock clock = SystemClock.getDefaultInstance();

        PipelineCacheState pcs = new PipelineCacheState(Time.NEVER);

        assertFalse("Hasn't expired yet", pcs.hasExpired(clock));

        assertFalse("Hasn't expired when we tweak the system time",
                pcs.hasExpired(new SystemClock() {

            // javadoc inherited
            public Time getCurrentTime() {
                // return now + 60 seconds
                return Time.inMilliSeconds(
                        clock.getCurrentTime().inMillis() + 60 * 1000);
            }
        }));

    }
View Full Code Here

        }
        this.expirationChecker = expirationChecker;

        // Initialise the clock, if none is specified then use the default
        // instance.
        SystemClock clock = builder.getClock();
        if (clock == null) {
            clock = SystemClock.getDefaultInstance();
        }
        this.clock = clock;
View Full Code Here

                            // Get the recording from the cache.
                            recording = value.getRecording();
                            this.state =
                                CacheBodyOperationProcessState.PLAYBACK_AND_SUPPRESS;

                            final SystemClock clock =
                                SystemClock.getDefaultInstance();
                            final Time currentTime = clock.getCurrentTime();
                            final PipelineCacheState pcs =
                                new PipelineCacheState(currentTime.addPeriod(
                                    dependency.getTimeToLive()));
                            dependencyContext.addDependency(dependency);
View Full Code Here

                // Capture the recording
                recording = recorder.stopRecording();
            }

            // Update the cachable result of this operation.
            final SystemClock clock = SystemClock.getDefaultInstance();
            final DependencyContext dependencyContext =
                getPipelineContext().getDependencyContext();
            dependencyContext.popDependencyTracker();
            final Dependency dependency;
            if (fixedExpiryMode) {
                dependency = new FixedTTLDependency(
                    clock, cacheControl.getTimeToLive());
            } else {
                dependency = dependencyContext.extractDependency();
            }
            dependencyContext.addDependency(dependency);

            // Set the result to cachable based on the inErrorRecoveryMode
            // state.
            final PipelineCacheState pcs = new PipelineCacheState(
                clock.getCurrentTime().addPeriod(dependency.getTimeToLive()));
            final ProviderResult result = new ProviderResult(
                new RecordingWithDependency(recording, dependency),
                getCacheGroup(), !inErrorRecoveryMode, pcs);
            async.update(result);
View Full Code Here

                // from the spec:
                // To mark a response as "never expires," an origin server sends
                // an Expires date approximately one year from the time the
                // response is sent. HTTP/1.1 servers SHOULD NOT send Expires
                // dates more than one year in the future.
                final SystemClock clock = cachingDirectives.getClock();
                final long oneYearInSeconds = 365 * 24 * 60 * 60;
                response.addDateHeader("Expires",
                    clock.getCurrentTime().inMillis() + oneYearInSeconds * 1000);
                response.addHeader("Cache-Control", "max-age=" + oneYearInSeconds);
            }
            response.addHeader("Vary", VARY_HEADER_VALUE);
        } else {
            // disable caching
View Full Code Here

TOP

Related Classes of com.volantis.shared.system.SystemClock

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.