Skip to content
Snippets Groups Projects
Commit 0675d0da authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

style: formating code

parent 0de861c8
No related branches found
No related tags found
No related merge requests found
......@@ -7,9 +7,13 @@ import cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkSPIMParameters;
class BenchmarkSPIMParametersImpl implements BenchmarkSPIMParameters{
private String userName;
private String password;
private String phone;
private String email;
private Path workingDirectory;
public BenchmarkSPIMParametersImpl(String userName, String password, String phone, String email, Path workingDirectory) {
......
......@@ -12,53 +12,46 @@ import java.nio.file.StandardOpenOption;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FileLock implements Closeable{
public class FileLock implements Closeable {
public static final Logger log = LoggerFactory.getLogger(cz.it4i.fiji.haas_spim_benchmark.commands.FileLock.class);
private FileChannel fileChannel;
private java.nio.channels.FileLock lock;
private Path filePath;
public FileLock(Path file) throws FileNotFoundException {
this.filePath = file;
}
public boolean tryLock() throws IOException {
this.fileChannel = FileChannel.open(filePath, StandardOpenOption.READ, StandardOpenOption.WRITE, StandardOpenOption.CREATE);
try {
this.lock = fileChannel.tryLock();
} catch (OverlappingFileLockException e) {
this.fileChannel.close();
return false;
}
return true;
this.fileChannel = FileChannel.open(filePath, StandardOpenOption.READ, StandardOpenOption.WRITE,
StandardOpenOption.CREATE);
try {
this.lock = fileChannel.tryLock();
} catch (OverlappingFileLockException e) {
this.fileChannel.close();
return false;
}
return true;
}
@Override
public void close() {
if(lock != null) {
if (lock != null) {
try {
lock.release();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
try {
fileChannel.close();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
try {
Files.delete(filePath);
} catch (IOException e) {
......
......@@ -36,7 +36,7 @@ public class ManageSPIMBenchmark implements Command {
private static Logger log = LoggerFactory
.getLogger(cz.it4i.fiji.haas_spim_benchmark.commands.ManageSPIMBenchmark.class);
private static String LOCK_FILE_NAME = ".lock";
private static final String LOCK_FILE_NAME = ".lock";
@Parameter
private UIService uiService;
......@@ -57,15 +57,12 @@ public class ManageSPIMBenchmark implements Command {
@Parameter(label = "Working directory", persist = true, style = FileWidget.DIRECTORY_STYLE)
private File workingDirectory;
@Override
public void run() {
try {
Path workingDirPath = Paths.get(workingDirectory.getPath());
FileLock fl = new FileLock(workingDirPath.resolve(LOCK_FILE_NAME));
if(!fl.tryLock()) {
uiService.showDialog("Working directory is already used by someone else", MessageType.ERROR_MESSAGE);
return;
......@@ -84,7 +81,6 @@ public class ManageSPIMBenchmark implements Command {
});
dialog.setVisible(true);
} catch (IOException e) {
// TODO Auto-generated catch block
log.error(e.getMessage(), e);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment