1 8 9 package com.sleepycat.je.latch; 10 11 import com.sleepycat.je.dbi.EnvironmentImpl; 12 13 18 public class LatchSupport { 19 20 private static String DISABLE_JAVA5_LATCHES = "je.disable.java5.latches"; 21 22 private static Class JAVA5_LATCH_CLASS = null; 23 24 private static Class JAVA5_SHARED_LATCH_CLASS = null; 25 26 static { 27 try { 28 if (System.getProperty(DISABLE_JAVA5_LATCHES) == null) { 29 Class.forName("java.util.concurrent.locks.ReentrantLock"); 30 JAVA5_LATCH_CLASS = Class.forName 31 ("com.sleepycat.je.latch.Java5LatchImpl"); 32 } 33 } catch (ClassNotFoundException CNFE) { 34 } 35 } 36 37 static { 38 try { 39 if (System.getProperty(DISABLE_JAVA5_LATCHES) == null) { 40 Class.forName 41 ("java.util.concurrent.locks.ReentrantReadWriteLock"); 42 JAVA5_SHARED_LATCH_CLASS = Class.forName 43 ("com.sleepycat.je.latch.Java5SharedLatchImpl"); 44 } 45 } catch (ClassNotFoundException CNFE) { 46 } 47 } 48 49 public static Class getJava5LatchClass() { 50 return JAVA5_LATCH_CLASS; 51 } 52 53 public static Latch makeLatch(String name, EnvironmentImpl env) { 54 if (JAVA5_LATCH_CLASS == null) { 55 return new LatchImpl(name, env); 56 } else { 57 try { 58 Latch ret = (Latch) JAVA5_LATCH_CLASS.newInstance(); 59 ret.setName(name); 60 return ret; 61 } catch (InstantiationException IE) { 62 } catch (IllegalAccessException IAE) { 63 } 64 65 66 JAVA5_LATCH_CLASS = null; 67 return new LatchImpl(name, env); 68 } 69 } 70 71 public static Latch makeLatch(EnvironmentImpl env) { 72 if (JAVA5_LATCH_CLASS == null) { 73 return new LatchImpl(env); 74 } else { 75 try { 76 return (Latch) JAVA5_LATCH_CLASS.newInstance(); 77 } catch (InstantiationException IE) { 78 } catch (IllegalAccessException IAE) { 79 } 80 81 82 JAVA5_LATCH_CLASS = null; 83 return new LatchImpl(env); 84 } 85 } 86 87 public static SharedLatch makeSharedLatch(String name, 88 EnvironmentImpl env) { 89 if (JAVA5_SHARED_LATCH_CLASS == null) { 90 return new SharedLatchImpl(name, env); 91 } else { 92 try { 93 SharedLatch ret = (SharedLatch) 94 JAVA5_SHARED_LATCH_CLASS.newInstance(); 95 ret.setName(name); 96 return ret; 97 } catch (InstantiationException IE) { 98 } catch (IllegalAccessException IAE) { 99 } 100 101 102 JAVA5_SHARED_LATCH_CLASS = null; 103 return new SharedLatchImpl(name, env); 104 } 105 } 106 107 108 static LatchTable latchTable = new LatchTable("LatchImpl"); 109 110 113 static public int countLatchesHeld() { 114 115 return latchTable.countLatchesHeld(); 116 } 117 118 static public void dumpLatchesHeld() { 119 120 System.out.println(latchesHeldToString()); 121 } 122 123 static public String latchesHeldToString() { 124 125 return latchTable.latchesHeldToString(); 126 } 127 128 static public void clearNotes() { 129 130 latchTable.clearNotes(); 131 } 132 } 133
| Popular Tags
|