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

com.fasterxml.clustermate.service.store.StoredEntry Maven / Gradle / Ivy

There is a newer version: 0.10.5
Show newest version
package com.fasterxml.clustermate.service.store;

import com.fasterxml.clustermate.api.EntryKey;
import com.fasterxml.clustermate.api.EntryKeyConverter;
import com.fasterxml.storemate.shared.StorableKey;
import com.fasterxml.storemate.shared.compress.Compression;
import com.fasterxml.storemate.store.Storable;
import com.fasterxml.storemate.store.lastaccess.LastAccessUpdateMethod;

/**
 * POJO for storing metadata for a single file entry.
 */
public abstract class StoredEntry
    implements StorableKey.Provider
{
    /*
    /**********************************************************************
    /* Public API, field access
    /**********************************************************************
     */

    public abstract K getKey();

    @Override
    public abstract StorableKey getStorableKey();
    
    public abstract long getCreationTime();
    public abstract LastAccessUpdateMethod getLastAccessUpdateMethod();
    public abstract int getMinTTLSinceAccessSecs();
    public abstract int getMaxTTLSecs();

    /*
    /**********************************************************************
    /* Public API, derived methods
    /**********************************************************************
     */

    /**
     * Method that can be called to verify whether the entry has exceeded its
     * maximum time-to-live, and can then be expired. Note that getting a
     * 'false' does NOT necessarily mean that entry has not expired, since
     * figuring that out requires knowledge of "last-accessed" set up, if any.
     * 'True' will, however, mean that entry may be removed locally (and should
     * eventually be removed by other replicas as well).
     * 
     * @param currentTime Current system time provided by caller
     * 
     * @return True if the entry is known to have exceeded its maximum time-to-live;
     *   false if this is not known.
     */
    public abstract boolean hasExceededMaxTTL(long currentTime);

    /**
     * Method that can be used to check whether entry has exceeded the absolute
     * minimum time-to-live (regardless of last-access) or not.
     * This can be used as an optimization to avoid having to access
     * (local) last-access time.
     */
    public abstract boolean hasExceededMinTTL(long currentTime);
    
    /**
     * Method that can be called to check whether this entry uses last-access
     * timestamp for determining expiration.
     */
    public abstract boolean usesLastAccessTime();
    
    /**
     * Method that can be called to check whether entry is expired
     * with respect to local last-access.
     *

* Note: getting 'true' * * @param currentTime Current system time provided by caller * @param lastAccess Timestamp of the last local access * * @return Whether entry has exceeded its TTL based only on the local * last-access settings and information */ public abstract boolean hasExceededLastAccessTTL(long currentTime, long lastAccess); public abstract boolean insertedBefore(long timestamp); public abstract boolean createdBefore(long timestamp); public abstract int routingHashUsing(EntryKeyConverter hasher); /** * Method that calculates conservative estimation on when this entry will * be expired for sure. Typically used for expiration time for last-accessed * entries (if used) * * @since 0.9.6 */ public long calculateMaxExpirationTime() { return getCreationTime() + (1000 * getMaxTTLSecs()); } /* /********************************************************************** /* Public API, pass-through methods /********************************************************************** */ public abstract Storable getRaw(); public boolean isDeleted() { return getRaw().isDeleted(); } public boolean hasExternalData() { return getRaw().hasExternalData(); } public boolean hasInlineData() { return getRaw().hasInlineData(); } public Compression getCompression() { return getRaw().getCompression(); } public long getLastModifiedTime() { return getRaw().getLastModified(); } public long getStorageLength() { return getRaw().getStorageLength(); } public long getActualUncompressedLength() { return getRaw().getActualUncompressedLength(); } @Override public String toString() { StringBuilder sb = new StringBuilder(100); long msecAge = System.currentTimeMillis() - getCreationTime(); int ageSecs = (msecAge <= 0L) ? 0 : (int) (msecAge / 1000); sb.append("[StoredEntry: isDeleted=") .append(isDeleted()) .append(", compression=") .append(getCompression()) .append(", storageLength=") .append(getStorageLength()) .append(", uncompressedLength=") .append(getActualUncompressedLength()) .append(", ageSecs=") .append(ageSecs) .append("]") ; return sb.toString(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy