com.alachisoft.ncache.jsr107.NCacheEntry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ncache-professional-client Show documentation
Show all versions of ncache-professional-client Show documentation
NCache Professional client for java.
package com.alachisoft.ncache.jsr107;
import com.alachisoft.ncache.client.CacheItem;
import com.alachisoft.ncache.runtime.exceptions.OperationFailedException;
import com.alachisoft.ncache.runtime.exceptions.runtime.OperationFailedRuntimeException;
import javax.cache.Cache.Entry;
public class NCacheEntry implements Entry {
private final Class keyType;
private final Class valueType;
private CacheItem cacheItem;
private K key;
/**
* @param item
* @param key
* @param keyType
* @param valueType
*/
public NCacheEntry(CacheItem item, K key, final Class keyType, final Class valueType) {
this.key = key;
this.cacheItem = item;
this.keyType = keyType;
this.valueType = valueType;
}
/**
* Returns the key corresponding to this entry.
*
* @return
*/
@Override
public K getKey() {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
return key;
}
/**
* Returns the value stored in the cache when this entry was created.
*
* @return
*/
@Override
public V getValue() {
try {
return (V) cacheItem.getValue(Object.class);
} catch (OperationFailedException e) {
throw new OperationFailedRuntimeException(e.getMessage());
}
}
/**
* Provides a standard way to access the underlying concrete cache entry implementation in order to provide access to further, proprietary features.
*
* @param type
* @return
*/
@Override
public Object unwrap(Class type) {
//throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
if (type.isAssignableFrom(getClass()))
return type.cast(this);
if (type.isAssignableFrom(CacheItem.class))
return type.cast(cacheItem);
return null;
}
}