net.sf.ehcache.constructs.nonstop.store.LocalReadsOnTimeoutStore Maven / Gradle / Ivy
/**
* Copyright 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 net.sf.ehcache.constructs.nonstop.store;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.sf.ehcache.CacheException;
import net.sf.ehcache.Element;
import net.sf.ehcache.Status;
import net.sf.ehcache.config.CacheConfiguration;
import net.sf.ehcache.config.TimeoutBehaviorConfiguration.TimeoutBehaviorType;
import net.sf.ehcache.constructs.nonstop.ClusterOperation;
import net.sf.ehcache.constructs.nonstop.NonstopActiveDelegateHolder;
import net.sf.ehcache.constructs.nonstop.NonstopTimeoutBehaviorFactory;
import net.sf.ehcache.search.Attribute;
import net.sf.ehcache.search.NullResults;
import net.sf.ehcache.search.Results;
import net.sf.ehcache.search.attribute.AttributeExtractor;
import net.sf.ehcache.store.ElementValueComparator;
import net.sf.ehcache.store.Policy;
import net.sf.ehcache.store.StoreListener;
import net.sf.ehcache.store.StoreQuery;
import net.sf.ehcache.writer.CacheWriterManager;
/**
* A {@link NonstopStore} implementation that returns the local value in the VM, if present, for get operations and no-op for put,
* remove and other operations
*
* @author Abhishek Sanoujam
*
*/
public class LocalReadsOnTimeoutStore implements NonstopStore {
/**
* The {@link NonstopTimeoutBehaviorFactory} to create {@link LocalReadsOnTimeoutStore} stores
*/
public static final NonstopTimeoutBehaviorFactory FACTORY = new NonstopTimeoutBehaviorFactory() {
public NonstopStore createNonstopTimeoutBehaviorStore(NonstopActiveDelegateHolder nonstopActiveDelegateHolder) {
return new LocalReadsOnTimeoutStore(nonstopActiveDelegateHolder);
}
};
private final NonstopActiveDelegateHolder nonstopActiveDelegateHolder;
/**
* Constructor accepting the {@link NonstopActiveDelegateHolder}
*/
public LocalReadsOnTimeoutStore(NonstopActiveDelegateHolder nonstopActiveDelegateHolder) {
this.nonstopActiveDelegateHolder = nonstopActiveDelegateHolder;
}
/**
* {@inheritDoc}
*/
public void unpinAll() {
// no-op
}
/**
* {@inheritDoc}
*/
public boolean isPinned(Object key) {
// no-op
return false;
}
/**
* {@inheritDoc}
*/
public void setPinned(Object key, boolean pinned) {
// no-op
}
/**
* {@inheritDoc}.
*
* Uses the underlying store to get the local value present in the VM
*/
public Element get(Object key) throws IllegalStateException, CacheException {
return getQuiet(key);
}
/**
* {@inheritDoc}.
*
* Uses the underlying store to get the local value present in the VM
*/
public List getKeys() throws IllegalStateException, CacheException {
return Collections.unmodifiableList(new ArrayList(getUnderlyingLocalKeys()));
}
private Set getUnderlyingLocalKeys() {
return nonstopActiveDelegateHolder.getUnderlyingTerracottaStore().getLocalKeys();
}
/**
* {@inheritDoc}.
*
* Uses the underlying store to get the local value present in the VM
*/
public Element getQuiet(Object key) throws IllegalStateException, CacheException {
return nonstopActiveDelegateHolder.getUnderlyingTerracottaStore().unsafeGetQuiet(key);
}
/**
* {@inheritDoc}
*/
public Map