private void initialiseProjectCache(
RuntimeProjectConfiguration configuration,
RuntimeProjectBuilder builder) {
// If the project does not define its own partition then use either the
// default local, or default remote one.
PolicyCachePartitionConfiguration partition = configuration.getPolicyCachePartition();
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);