org.apache.commons.jcs.jcache.JCSConfiguration Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Copyright 2003-2010 Terracotta, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.jcs.jcache;
import javax.cache.configuration.CacheEntryListenerConfiguration;
import javax.cache.configuration.CompleteConfiguration;
import javax.cache.configuration.Configuration;
import javax.cache.configuration.Factory;
import javax.cache.expiry.EternalExpiryPolicy;
import javax.cache.expiry.ExpiryPolicy;
import javax.cache.integration.CacheLoader;
import javax.cache.integration.CacheWriter;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public class JCSConfiguration implements CompleteConfiguration
{
private final Class keyType;
private final Class valueType;
private final boolean storeByValue;
private final boolean readThrough;
private final boolean writeThrough;
private final Factory> cacheLoaderFactory;
private final Factory> cacheWristerFactory;
private final Factory expiryPolicyFactory;
private final Set> cacheEntryListenerConfigurations;
private volatile boolean statisticsEnabled;
private volatile boolean managementEnabled;
public JCSConfiguration(final Configuration configuration, final Class keyType, final Class valueType)
{
this.keyType = keyType;
this.valueType = valueType;
if (configuration instanceof CompleteConfiguration)
{
final CompleteConfiguration cConfiguration = (CompleteConfiguration) configuration;
storeByValue = configuration.isStoreByValue();
readThrough = cConfiguration.isReadThrough();
writeThrough = cConfiguration.isWriteThrough();
statisticsEnabled = cConfiguration.isStatisticsEnabled();
managementEnabled = cConfiguration.isManagementEnabled();
cacheLoaderFactory = cConfiguration.getCacheLoaderFactory();
cacheWristerFactory = cConfiguration.getCacheWriterFactory();
this.expiryPolicyFactory = cConfiguration.getExpiryPolicyFactory();
cacheEntryListenerConfigurations = new HashSet>();
final Iterable> entryListenerConfigurations = cConfiguration
.getCacheEntryListenerConfigurations();
if (entryListenerConfigurations != null)
{
for (final CacheEntryListenerConfiguration kvCacheEntryListenerConfiguration : entryListenerConfigurations)
{
cacheEntryListenerConfigurations.add(kvCacheEntryListenerConfiguration);
}
}
}
else
{
expiryPolicyFactory = EternalExpiryPolicy.factoryOf();
storeByValue = true;
readThrough = false;
writeThrough = false;
statisticsEnabled = false;
managementEnabled = false;
cacheLoaderFactory = null;
cacheWristerFactory = null;
cacheEntryListenerConfigurations = new HashSet>();
}
}
@Override
public Class getKeyType()
{
return keyType == null ? (Class) Object.class : keyType;
}
@Override
public Class getValueType()
{
return valueType == null ? (Class) Object.class : valueType;
}
@Override
public boolean isStoreByValue()
{
return storeByValue;
}
@Override
public boolean isReadThrough()
{
return readThrough;
}
@Override
public boolean isWriteThrough()
{
return writeThrough;
}
@Override
public boolean isStatisticsEnabled()
{
return statisticsEnabled;
}
@Override
public boolean isManagementEnabled()
{
return managementEnabled;
}
@Override
public Iterable> getCacheEntryListenerConfigurations()
{
return Collections.unmodifiableSet(cacheEntryListenerConfigurations);
}
@Override
public Factory> getCacheLoaderFactory()
{
return cacheLoaderFactory;
}
@Override
public Factory> getCacheWriterFactory()
{
return cacheWristerFactory;
}
@Override
public Factory getExpiryPolicyFactory()
{
return expiryPolicyFactory;
}
public synchronized void addListener(final CacheEntryListenerConfiguration cacheEntryListenerConfiguration)
{
cacheEntryListenerConfigurations.add(cacheEntryListenerConfiguration);
}
public synchronized void removeListener(final CacheEntryListenerConfiguration cacheEntryListenerConfiguration)
{
cacheEntryListenerConfigurations.remove(cacheEntryListenerConfiguration);
}
public void statisticsEnabled()
{
statisticsEnabled = true;
}
public void managementEnabled()
{
managementEnabled = true;
}
public void statisticsDisabled()
{
statisticsEnabled = false;
}
public void managementDisabled()
{
managementEnabled = false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy