diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/BenchmarkSPIMParametersImpl.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/BenchmarkSPIMParametersImpl.java index 17208296b7c4dfc9574fb23164042531bff459ee..67ee1094ed04e0cbe2be1ee9220c066439a971f0 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/BenchmarkSPIMParametersImpl.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/BenchmarkSPIMParametersImpl.java @@ -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) { diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/FileLock.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/FileLock.java index 8ed9ee4a1f8737463667386602f098ee1a00ed9f..14384ce2a456b48e2d7f6c77073c026ae7431b88 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/FileLock.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/FileLock.java @@ -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) { diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/ManageSPIMBenchmark.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/ManageSPIMBenchmark.java index 6843fab8f296d62d989cda392db9ee7fd850853c..1a5fdd210c078992515eab1fd6e29e1bdffc675f 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/ManageSPIMBenchmark.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/commands/ManageSPIMBenchmark.java @@ -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); }