1 30 31 32 package org.hsqldb.persist; 33 34 import java.nio.channels.FileChannel ; 35 import java.nio.channels.FileLock ; 36 37 46 final class NIOLockFile extends LockFile { 47 48 static final long MAX_NFS_LOCK_REGION = (1L << 30); 55 static final long MIN_LOCK_REGION = MAGIC.length + 8; 56 57 64 private FileChannel fc; 65 66 70 private FileLock fl; 71 72 80 protected boolean lockImpl() throws Exception { 81 82 boolean isValid; 83 84 if (fl != null && fl.isValid()) { 85 return true; 86 } 87 88 trace("lockImpl(): fc = raf.getChannel()"); 89 90 fc = raf.getChannel(); 91 92 trace("lockImpl(): fl = fc.tryLock()"); 93 94 fl = null; 95 96 try { 97 fl = fc.tryLock(0, MIN_LOCK_REGION, false); 98 99 trace("lockImpl(): fl = " + fl); 100 } catch (Exception e) { 101 102 110 trace(e.toString()); 111 } 112 113 trace("lockImpl(): f.deleteOnExit()"); 141 f.deleteOnExit(); 142 143 isValid = fl != null && fl.isValid(); 144 145 trace("lockImpl():isValid(): " + isValid); 146 147 return isValid; 148 } 149 150 157 protected boolean releaseImpl() throws Exception { 158 159 trace("releaseImpl(): fl = " + fl); 162 163 if (fl != null) { 164 trace("releaseImpl(): fl.release()"); 165 fl.release(); 166 trace("tryRelease(): fl = " + fl); 167 168 fl = null; 169 } 170 171 trace("releaseImpl(): fc = " + fc); 172 173 if (fc != null) { 174 trace("releaseImpl(): fc.close()"); 175 fc.close(); 176 177 fc = null; 178 } 179 180 return true; 186 } 187 188 195 public boolean isValid() { 196 return super.isValid() && (fl != null && fl.isValid()); 197 } 198 199 203 protected String toStringImpl() { 204 return "fl =" + fl; 205 } 206 } 207 | Popular Tags |