1 package org.vamsas.client.simpleclient;
3 import java.io.FileNotFoundException;
4 import java.io.FileOutputStream;
5 import java.io.IOException;
6 import java.nio.channels.FileLock;
9 * transient object representing a file lock
19 * creates a valid Lock (test with <method>isLocked</method>)
20 * if a lock could be obtained for <param>lockfile</param>
23 public Lock(java.io.File lockfile) {
24 // try and get a lock.
28 if (!lockfile.exists())
29 if (!lockfile.createNewFile()) {
33 lock = new FileOutputStream(lockfile).getChannel().tryLock();
34 } catch (FileNotFoundException e) {
35 System.err.println("Error! Couldn't create a lockfile at "
36 + lockfile.getAbsolutePath());
38 } catch (IOException e) {
39 System.err.println("Error! Problems with IO when creating a lock on "
40 + lockfile.getAbsolutePath());
46 if (lock != null && lock.isValid()) {
52 /* Explicitly release lock (probably don't need to do this!)
53 * @see java.lang.Object#finalize()
55 protected void finalize() throws Throwable {