Package com.volantis.cache.group

Examples of com.volantis.cache.group.Group


     * todo Maybe this should be done up front so every project has a cache group
     * set.
     */
    public Group selectGroup(final Object key, final ActivatedPolicy policy) {

        Group baseGroup = null;

        // If a policy was found then check it's project to see whether it
        // already has a cache group selected.
        if (policy != null) {
            RuntimeProject project = policy.getLogicalProject();
            baseGroup = project.getCacheGroup();
        }

        // If a group could not be found from the project then try it based on
        // the key.
        if (key instanceof ProjectSpecificKey) {
            ProjectSpecificKey projectSpecificKey = (ProjectSpecificKey) key;
            baseGroup = selectLocalProjectGroup(projectSpecificKey.getProject());
        } else if (key instanceof String) {
            String stringKey = (String) key;
            baseGroup = selectRemoteProjectGroup(stringKey);
        } else {
            throw new IllegalStateException(
                    "Key is not a String, or a ProjectSpecificKey, it is '" +
                    key + "'");
        }

        Group policyGroup = null;
        if (policy != null) {
            // Get the group specific to the policy type.
            PolicyType policyType = policy.getPolicyType();
            policyGroup = baseGroup.findGroup(policyType);
        }
View Full Code Here


     */
    private Group selectLocalProjectGroup(RuntimeProject project) {

        // If the project has its own cache group then use that, else
        // use the root project.
        Group projectGroup = project.getCacheGroup();
        if (projectGroup == null) {
            if (project.isRemote()) {
                throw new IllegalStateException("Only supports local projects");
            } else {
                projectGroup = localDefaultGroup;
View Full Code Here

     * @return The group for the quota, or the default one if the path does not
     *         match a quota.
     */
    private Group selectRemoteProjectGroup(String path) {

        Group group = getRemotePartitionGroup(path);
        if (group == null) {
            group = getRemoteDefaultGroup();
        }

        return group;
View Full Code Here

        return group;
    }

    // Javadoc inherited.
    public void flush(PolicyType policyType) {
        Group root = delegate.getRootGroup();
        root.flush(getFilter(policyType));
    }
View Full Code Here

        root.flush(getFilter(policyType));
    }

    // Javadoc inherited.
    public void flushAll() {
        Group root = delegate.getRootGroup();
        root.flush(null);
    }
View Full Code Here

        if (partition == null) {
            if (builder.isRemote()) {
                // The project is remote so use the group associated with the
                // remote partition if any, or the default remote group.
                String location = configuration.getLocation();
                Group group = policyCache.getRemotePartitionGroup(location);
                if (group == null) {
                    group = policyCache.getRemoteDefaultGroup();
                }
                builder.setCacheControlDefaultsMap(remoteConstraintsMap);
                builder.setCacheGroup(group);
            } else {
                // Use the default local partition.
                builder.setCacheControlDefaultsMap(localConstraintsMap);
                builder.setCacheGroup(policyCache.getLocalDefaultGroup());
            }
        } else {
            RemotePolicyCacheConfiguration partitionConfiguration =
                    partition.getConstraintsConfiguration();

            PolicyCachePartitionConstraints partitionConstraints;
            Group baseGroup;
            if (builder.isRemote()) {
                // The project is remote so use the group associated with the
                // remote partition if any, or the remote group.
                String location = configuration.getLocation();
                baseGroup = policyCache.getRemotePartitionGroup(location);
                if (baseGroup == null) {
                    baseGroup = policyCache.getRemoteGroup();
                }
                partitionConstraints =
                        policyCache.getRemotePartitionConstraints();
            } else {
                baseGroup = policyCache.getLocalGroup();
                partitionConstraints =
                        policyCache.getLocalPartitionConstraints();
            }

            int partitionSize = partitionConstraints.constrainPartitionSize(
                    partition.getSize());
            if (partitionSize < 1) {
                throw new IllegalStateException("Partition size must be >= 1");
            }

            CacheFactory cacheFactory = CacheFactory.getDefaultInstance();
            GroupBuilder groupBuilder = cacheFactory.createGroupBuilder();
            groupBuilder.setMaxCount(partitionSize);
            Group partitionGroup = baseGroup.addGroup(
                    configuration.getLocation(), groupBuilder);

            // Create the base constraints for the partition. These will
            // be used to derive the constraints for the type specific
            // partitions.
            CacheControlConstraints base =
                    new CacheControlConstraints(
                            partitionConstraints.getConstraints(),
                            partitionConfiguration);

            builder.setCacheControlDefaults(base.getDefaultCacheControl());

            SeparateCacheControlConstraintsMap constraintsMap =
                    new SeparateCacheControlConstraintsMap();
            for (Iterator i = PolicyType.getPolicyTypes().iterator(); i.hasNext();) {
                PolicyType policyType = (PolicyType) i.next();
                PolicyTypePartitionConfiguration typePartitionConfiguration =
                        partition.getTypePartition(policyType);
                CacheControlConstraints typeConstraints;
                groupBuilder = cacheFactory.createGroupBuilder();
                if (typePartitionConfiguration == null) {
                    typeConstraints = base;
                    groupBuilder.setMaxCount(partitionSize);
                } else {
                    RemotePolicyCacheConfiguration typeConfiguration =
                            typePartitionConfiguration.getConstraints();
                    if (typeConfiguration == null) {
                        typeConstraints = base;
                    } else {
                        typeConstraints = new CacheControlConstraints(base,
                                typeConfiguration);
                    }
                    groupBuilder.setMaxCount(typePartitionConfiguration.getSize());
                }
                partitionGroup.addGroup(policyType, groupBuilder);
                constraintsMap.addConstraints(policyType, typeConstraints);
            }

            builder.setCacheGroup(partitionGroup);
            builder.setCacheControlDefaultsMap(constraintsMap);
View Full Code Here

     *
     * @param policyType The type of policies to flush, may be null in which
     *                   case all policies of any type are flushed.
     */
    private void flushLocalPolicyCaches(PolicyType policyType) {
        Group group = policyCache.getLocalGroup();
        CacheEntryFilter filter = policyCache.getFilter(policyType);
        group.flush(filter);
    }
View Full Code Here

     *
     * @param path      with which to flush the cache
     */
    public void flushRemoteCache(String path) {

        Group group = policyCache.getRemotePartitionGroup(path);
        if (group == null) {
            // No group exists so maybe the path relates to a specific policy
            // so try and flush it.
            policyCache.flushRemotePolicy(path);
        } else {
            group.flush(null);
        }
    }
View Full Code Here

                .returns(null);

        // =====================================================================
        //   Test Expectations
        // =====================================================================
        Group group = policyCache.selectGroup("http://host/partition", null);
        assertSame(defaultRemoteGroupMock, group);
    }
View Full Code Here

        projectMock.expects.getCacheGroup().returns(null);

        // =====================================================================
        //   Test Expectations
        // =====================================================================
        Group group = policyCache.selectGroup(key, null);
        assertSame(defaultLocalGroupMock, group);
    }
View Full Code Here

TOP

Related Classes of com.volantis.cache.group.Group

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.