1/*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2002,2008 Oracle. All rights reserved. 5 * 6 * $Id: LockDetectMode.java,v 12.7 2008/01/17 05:04:53 mjc Exp $ 7 */ 8 9package com.sleepycat.db; 10 11import com.sleepycat.db.internal.DbConstants; 12 13/** Deadlock detection modes. */ 14public final class LockDetectMode { 15 /** 16 Turn off deadlock detection. 17 */ 18 public static final LockDetectMode NONE = 19 new LockDetectMode("NONE", 0); 20 21 /** 22 Use whatever lock policy was specified when the database environment 23 was created. If no lock policy has yet been specified, set the lock 24 policy to DB_LOCK_RANDOM. 25 */ 26 public static final LockDetectMode DEFAULT = 27 new LockDetectMode("DEFAULT", DbConstants.DB_LOCK_DEFAULT); 28 29 /** 30 Reject lock requests which have timed out. No other deadlock detection 31 is performed. 32 */ 33 public static final LockDetectMode EXPIRE = 34 new LockDetectMode("EXPIRE", DbConstants.DB_LOCK_EXPIRE); 35 36 /** 37 Reject the lock request for the locker ID with the most locks. 38 */ 39 public static final LockDetectMode MAXLOCKS = 40 new LockDetectMode("MAXLOCKS", DbConstants.DB_LOCK_MAXLOCKS); 41 42 /** 43 Reject the lock request for the locker ID with the most write locks. 44 */ 45 public static final LockDetectMode MAXWRITE = 46 new LockDetectMode("MAXWRITE", DbConstants.DB_LOCK_MAXWRITE); 47 48 /** 49 Reject the lock request for the locker ID with the fewest locks. 50 */ 51 public static final LockDetectMode MINLOCKS = 52 new LockDetectMode("MINLOCKS", DbConstants.DB_LOCK_MINLOCKS); 53 54 /** 55 Reject the lock request for the locker ID with the fewest write locks. 56 */ 57 public static final LockDetectMode MINWRITE = 58 new LockDetectMode("MINWRITE", DbConstants.DB_LOCK_MINWRITE); 59 60 /** 61 Reject the lock request for the locker ID with the oldest lock. 62 */ 63 public static final LockDetectMode OLDEST = 64 new LockDetectMode("OLDEST", DbConstants.DB_LOCK_OLDEST); 65 66 /** 67 Reject the lock request for a random locker ID. 68 */ 69 public static final LockDetectMode RANDOM = 70 new LockDetectMode("RANDOM", DbConstants.DB_LOCK_RANDOM); 71 72 /** 73 Reject the lock request for the locker ID with the youngest lock. 74 */ 75 public static final LockDetectMode YOUNGEST = 76 new LockDetectMode("YOUNGEST", DbConstants.DB_LOCK_YOUNGEST); 77 78 /* package */ 79 static LockDetectMode fromFlag(int flag) { 80 switch (flag) { 81 case 0: 82 return NONE; 83 case DbConstants.DB_LOCK_DEFAULT: 84 return DEFAULT; 85 case DbConstants.DB_LOCK_EXPIRE: 86 return EXPIRE; 87 case DbConstants.DB_LOCK_MAXLOCKS: 88 return MAXLOCKS; 89 case DbConstants.DB_LOCK_MAXWRITE: 90 return MAXWRITE; 91 case DbConstants.DB_LOCK_MINLOCKS: 92 return MINLOCKS; 93 case DbConstants.DB_LOCK_MINWRITE: 94 return MINWRITE; 95 case DbConstants.DB_LOCK_OLDEST: 96 return OLDEST; 97 case DbConstants.DB_LOCK_RANDOM: 98 return RANDOM; 99 case DbConstants.DB_LOCK_YOUNGEST: 100 return YOUNGEST; 101 default: 102 throw new IllegalArgumentException( 103 "Unknown lock detect mode: " + flag); 104 } 105 } 106 107 private String modeName; 108 private int flag; 109 110 private LockDetectMode(final String modeName, final int flag) { 111 this.modeName = modeName; 112 this.flag = flag; 113 } 114 115 /* package */ 116 int getFlag() { 117 return flag; 118 } 119 120 /** {@inheritDoc} */ 121 public String toString() { 122 return "LockDetectMode." + modeName; 123 } 124} 125