All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alachisoft.ncache.jsr107.NCacheEntry Maven / Gradle / Ivy

There is a newer version: 5.3.0
Show newest version
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;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy