-
- log.debug("Creating active client lock file "+ this.clientlockFile.getAbsolutePath());
- if (clientlockFile.exists())
- {//should not happen, file should be deleted when the application closes or when a crashed application has been detected
- log.error("client lock file already exits");
- }
- try {
- //create the empty file
- if(! clientlockFile.createNewFile())
- {
- log.error("Unable to create active client lock file");
-
- return;
- }
- else
- log.debug("file created");
- // Get a file channel for the file
- FileChannel channel = new RandomAccessFile(clientlockFile, "rw").getChannel();
-
- // Use the file channel to create a lock on the file.
- // This method blocks until it can retrieve the lock.
- java.nio.channels.FileLock activeClientFilelock ;// = channel.lock();
-
- // Try acquiring the lock without blocking. This method returns
- // null or throws an exception if the file is already locked.
- try
- {
- activeClientFilelock = channel.tryLock();
- log.debug("Got lock");
- }
- catch (OverlappingFileLockException e)
- {
- // File is already locked in this thread or virtual machine
- log.error("Oups the file is already locked",e);
-
- }
-
- // Release the lock
- /* lock.release();
-
- // Close the file
- channel.close();*/
- } catch (Exception e) {
- log.error("Error during lock file creation",e);
- }
-
-