1 13 package org.jahia.registries.locks; 14 15 import java.util.Hashtable ; 16 17 import org.jahia.utils.JahiaConsole; 18 19 20 26 public class JahiaLocksRegistry 27 { 28 private static JahiaLocksRegistry mObject; 29 30 33 private Hashtable mRegistry; 34 35 36 39 protected JahiaLocksRegistry () { 40 mRegistry = new Hashtable (); 41 JahiaConsole.println ("JahiaLocksRegistry.constructor", 42 "=---= Lock registry has been instanciated =---="); 43 } 44 45 46 54 public static JahiaLocksRegistry getInstance() { 55 if (mObject == null) { 56 mObject = new JahiaLocksRegistry(); 57 } 58 return mObject; 59 } 60 61 74 public synchronized boolean setLock (String lockName, Hashtable lockData, 75 int timeout) 76 { 77 if (lockName == null) { 78 return false; 79 } 80 81 JahiaLock lock = (JahiaLock)mRegistry.get (lockName); 82 if (lock == null) { 83 lock = new JahiaLock (lockName, lockData, timeout); 84 mRegistry.put (lockName, lock); 85 86 } else { 87 lock.setLockData (lockData); 88 lock.resetTimeout(); 89 } 90 return true; 91 } 92 93 94 95 105 public synchronized Hashtable getLock (String lockName) 106 { 107 if (lockName != null) { 108 JahiaLock lock = (JahiaLock)mRegistry.get (lockName); 109 if (lock != null) { 110 return lock.getLockData(); 111 } 112 } 113 return null; 114 } 115 116 117 124 public synchronized void removeLock (String lockName) 125 { 126 if (lockName != null) { 127 mRegistry.remove (lockName); 128 } 129 } 130 131 132 142 public final boolean doesLockExist (String lockName) 143 { 144 return (getLock (lockName) != null); 145 } 146 147 151 public synchronized boolean isLockValid (String lockName) 152 { 153 if (lockName == null) { 154 return false; 155 } 156 157 JahiaLock lock = (JahiaLock)mRegistry.get (lockName); 158 return lock.isValid(); 159 } 160 161 165 public synchronized boolean resetLockTimeout (String lockName) 166 { 167 if (lockName == null) { 168 return false; 169 } 170 171 JahiaLock lock = (JahiaLock)mRegistry.get (lockName); 172 lock.resetTimeout(); 173 return true; 174 } 175 176 } 177 | Popular Tags |