27package jau.test.util.parallel.locks.impl;
30import java.io.IOException;
31import java.io.RandomAccessFile;
32import java.nio.channels.FileLock;
34import org.jau.lang.InterruptSource;
36import jau.test.util.parallel.locks.SingletonInstance;
40 static final String temp_file_path;
45 final File tmpFile = File.createTempFile(
"TEST",
"tst");
46 final String absTmpFile = tmpFile.getCanonicalPath();
48 s = absTmpFile.substring(0, absTmpFile.lastIndexOf(File.separator));
49 }
catch (
final IOException ex) {
56 return temp_file_path;
76 public final String
getName() {
return file.getPath(); }
78 private void setupFileCleanup() {
80 Runtime.getRuntime().addShutdownHook(
new InterruptSource.Thread() {
84 System.err.println(infoPrefix()+
" XXX "+SingletonInstanceFileLock.this.getName()+
" - Unlock @ JVM Shutdown");
94 randomAccessFile =
new RandomAccessFile(file,
"rw");
95 fileLock = randomAccessFile.getChannel().tryLock();
97 if (fileLock !=
null) {
100 }
catch (
final Exception e) {
101 System.err.println(infoPrefix()+
" III "+getName()+
" - Unable to create and/or lock file");
110 if(
null != fileLock) {
114 if(
null != randomAccessFile) {
115 randomAccessFile.close();
116 randomAccessFile =
null;
122 }
catch (
final Exception e) {
123 System.err.println(infoPrefix()+
" EEE "+getName()+
" - Unable to remove lock file");
127 randomAccessFile =
null;
132 private final File file;
133 private RandomAccessFile randomAccessFile =
null;
134 private FileLock fileLock =
null;
static String getCanonicalTempLockFilePath(final String basename)
SingletonInstanceFileLock(final long poll_ms, final String lockFileBasename)
static String getCanonicalTempPath()
SingletonInstanceFileLock(final long poll_ms, final File lockFile)