1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2002,2008 Oracle. All rights reserved. 5 * 6 * $Id: CacheFilePriority.java,v 12.8 2008/01/17 05:04:53 mjc Exp $ 7 */ 8 9package com.sleepycat.db; 10 11import com.sleepycat.db.internal.DbConstants; 12 13/** 14 * Priorities that can be assigned to files in the cache. 15 */ 16public final class CacheFilePriority { 17 /** 18 The default priority. 19 */ 20 public static final CacheFilePriority DEFAULT = 21 new CacheFilePriority("DEFAULT", DbConstants.DB_PRIORITY_DEFAULT); 22 /** 23 The second highest priority. 24 */ 25 public static final CacheFilePriority HIGH = 26 new CacheFilePriority("HIGH", DbConstants.DB_PRIORITY_HIGH); 27 /** 28 The second lowest priority. 29 */ 30 public static final CacheFilePriority LOW = 31 new CacheFilePriority("LOW", DbConstants.DB_PRIORITY_LOW); 32 /** 33 The highest priority: pages are the least likely to be discarded. 34 */ 35 public static final CacheFilePriority VERY_HIGH = 36 new CacheFilePriority("VERY_HIGH", DbConstants.DB_PRIORITY_VERY_HIGH); 37 /** 38 The lowest priority: pages are the most likely to be discarded. 39 */ 40 public static final CacheFilePriority VERY_LOW = 41 new CacheFilePriority("VERY_LOW", DbConstants.DB_PRIORITY_VERY_LOW); 42 43 /* package */ 44 static CacheFilePriority fromFlag(int flag) { 45 switch (flag) { 46 case 0: 47 case DbConstants.DB_PRIORITY_DEFAULT: 48 return DEFAULT; 49 case DbConstants.DB_PRIORITY_HIGH: 50 return HIGH; 51 case DbConstants.DB_PRIORITY_LOW: 52 return LOW; 53 case DbConstants.DB_PRIORITY_VERY_HIGH: 54 return VERY_HIGH; 55 case DbConstants.DB_PRIORITY_VERY_LOW: 56 return VERY_LOW; 57 default: 58 throw new IllegalArgumentException( 59 "Unknown cache priority: " + flag); 60 } 61 } 62 63 private final String priorityName; 64 private final int flag; 65 66 private CacheFilePriority(final String priorityName, final int flag) { 67 this.priorityName = priorityName; 68 this.flag = flag; 69 } 70 71 /** {@inheritDoc} */ 72 public String toString() { 73 return "CacheFilePriority." + priorityName; 74 } 75 76 /* package */ 77 int getFlag() { 78 return flag; 79 } 80} 81