1 /* Copyright (c) 2009 Peter Troshin
\r
3 * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0
\r
5 * This library is free software; you can redistribute it and/or modify it under the terms of the
\r
6 * Apache License version 2 as published by the Apache Software Foundation
\r
8 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
\r
9 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache
\r
10 * License for more details.
\r
12 * A copy of the license is in apache_license.txt. It is also available here:
\r
13 * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
\r
15 * Any republication or derived work distributed in source code form
\r
16 * must include this copyright and license notice.
\r
18 package compbio.engine;
\r
20 import java.io.IOException;
\r
21 import java.util.concurrent.TimeUnit;
\r
23 import org.apache.log4j.Logger;
\r
25 import compbio.metadata.ChunkHolder;
\r
27 public class ProgressGetter {
\r
29 private static final Logger log = Logger.getLogger(ProgressGetter.class);
\r
31 static final ChunkHolder pull(String file, long position, long delay,
\r
33 if (compbio.util.Util.isEmpty(file)) {
\r
34 throw new NullPointerException("File must be supplied!");
\r
37 FilePuller puller = PulledFileCache.get(file);
\r
38 if (puller == null) {
\r
39 puller = FilePuller.newFilePuller(file, 1024);
\r
42 puller.setDelay(delay, unit);
\r
44 PulledFileCache.put(puller);
\r
46 if (puller.isFileCreated()) {
\r
48 return puller.pull(position);
\r
49 } catch (IOException e) {
\r
50 log.error(e.getLocalizedMessage(), e.getCause());
\r
56 public final static ChunkHolder pull(String file, long position) {
\r
57 // Use default delay time
\r
59 throw new IllegalArgumentException(
\r
60 "Position must be greater then 0");
\r
62 return pull(file, position, 0, null);
\r
65 static byte getProgress(String progressFile, long delay, TimeUnit unit) {
\r
66 if (compbio.util.Util.isEmpty(progressFile)) {
\r
67 throw new NullPointerException("File must be supplied!");
\r
70 FilePuller puller = PulledFileCache.get(progressFile);
\r
71 if (puller == null) {
\r
72 puller = FilePuller.newProgressPuller(progressFile);
\r
75 puller.setDelay(delay, unit);
\r
77 PulledFileCache.put(puller);
\r
79 if (puller.isFileCreated()) {
\r
81 byte value = puller.getProgress();
\r
83 } catch (IOException e) {
\r
84 log.error(e.getLocalizedMessage(), e.getCause());
\r
90 public final static byte getProgress(String progressFile) {
\r
91 return getProgress(progressFile, 0, null);
\r