blob: c7d8a6c4c75af2b1f59dba5c5321f873bb4d63ff [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.update.internal.configurator;
import java.io.*;
import java.nio.channels.FileLock;
/**
* Internal class.
*/
public class Locker_JavaNio implements Locker {
private File lockFile;
private FileLock fileLock;
public Locker_JavaNio(File lockFile) {
this.lockFile = lockFile;
}
public synchronized boolean lock() throws IOException {
RandomAccessFile raf = new RandomAccessFile(lockFile, "rw"); //$NON-NLS-1$
fileLock = raf.getChannel().lock();
if (fileLock != null)
return true;
return false;
}
public synchronized void release() {
if (fileLock != null) {
try {
fileLock.release();
} catch (IOException e) {
//don't complain, we're making a best effort to clean up
}
fileLock = null;
}
}
}