/*- * See the file LICENSE for redistribution information. * * Copyright (c) 2001, 2010 Oracle and/or its affiliates. All rights reserved. * * $Id$ */ package com.sleepycat.db; import com.sleepycat.db.internal.DbConstants; import com.sleepycat.db.internal.DbMpoolFile; /** This class allows applications to modify settings for a {@link com.sleepycat.db.Database Database} using the {@link com.sleepycat.db.Database#getCacheFile Database.getCacheFile}. */ public class CacheFile { private DbMpoolFile mpf; /* package */ CacheFile(final DbMpoolFile mpf) { this.mpf = mpf; } /** Return the cache priority for pages from the specified file.
This method may be called at any time during the life of the application.
@return The cache priority for pages from the specified file.
@throws DatabaseException if a failure occurs. */ public CacheFilePriority getPriority() throws DatabaseException { return CacheFilePriority.fromFlag(mpf.get_priority()); } /** Set the cache priority for pages from the specified file.
The priority of a page biases the replacement algorithm to be more or less likely to discard a page when space is needed in the buffer pool. The bias is temporary, and pages will eventually be discarded if they are not referenced again. Setting the priority is only advisory, and does not guarantee pages will be treated in a specific way.
This method may be called at any time during the life of the application.
@param priority The cache priority for pages from the specified file.
@throws DatabaseException if a failure occurs. */ public void setPriority(final CacheFilePriority priority) throws DatabaseException { mpf.set_priority(priority.getFlag()); } /** Return the maximum size for the file backing the database, or 0 if no maximum file size has been configured.
This method may be called at any time during the life of the application.
@return The maximum size for the file backing the database, or 0 if no maximum file size has been configured.
@throws DatabaseException if a failure occurs. */ public long getMaximumSize() throws DatabaseException { return mpf.get_maxsize(); } /** Set the maximum size for the file backing the database.
Attempts to allocate new pages in the file after the limit has been reached will fail.
This method may be called at any time during the life of the application.
@param bytes The maximum size for the file backing the database.
@throws DatabaseException if a failure occurs. */ public void setMaximumSize(final long bytes) throws DatabaseException { mpf.set_maxsize(bytes); } /** Return true if the opening of backing temporary files for in-memory databases has been disallowed.
This method may be called at any time during the life of the application.
@return True if the opening of backing temporary files for in-memory databases has been disallowed.
@throws DatabaseException if a failure occurs. */ public boolean getNoFile() throws DatabaseException { return (mpf.get_flags() & DbConstants.DB_MPOOL_NOFILE) != 0; } /** Disallow opening backing temporary files for in-memory databases, even if they expand to fill the entire cache.
Attempts to create new file pages after the cache has been filled will fail.
This method may be called at any time during the life of the application.
@param onoff If true, disallow opening backing temporary files for in-memory databases, even if they expand to fill the entire cache.
@throws DatabaseException if a failure occurs. */ public void setNoFile(final boolean onoff) throws DatabaseException { mpf.set_flags(DbConstants.DB_MPOOL_NOFILE, onoff); } /** Return true if the file will be removed when the last reference to it is closed.
This method may be called at any time during the life of the application.
@return True if the file will be removed when the last reference to it is closed.
@throws DatabaseException if a failure occurs. */ public boolean getUnlink() throws DatabaseException { return (mpf.get_flags() & DbConstants.DB_MPOOL_UNLINK) != 0; } /** Remove the file when the last reference to it is closed.
This method may be called at any time during the life of the application.
@param onoff If true, remove the file when the last reference to it is closed.
@throws DatabaseException if a failure occurs. */ public void setUnlink(boolean onoff) throws DatabaseException { mpf.set_flags(DbConstants.DB_MPOOL_UNLINK, onoff); } }