01: // loaderCore.java
02: // ---------------------------
03: // (C) by Michael Peter Christen; mc@anomic.de
04: // first published on http://www.anomic.de
05: // Frankfurt, Germany, 2004
06: // last major change: 29.09.2004
07: //
08: // This program is free software; you can redistribute it and/or modify
09: // it under the terms of the GNU General Public License as published by
10: // the Free Software Foundation; either version 2 of the License, or
11: // (at your option) any later version.
12: //
13: // This program is distributed in the hope that it will be useful,
14: // but WITHOUT ANY WARRANTY; without even the implied warranty of
15: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: // GNU General Public License for more details.
17: //
18: // You should have received a copy of the GNU General Public License
19: // along with this program; if not, write to the Free Software
20: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21: //
22: // Using this software in any meaning (reading, learning, copying, compiling,
23: // running) means that you agree that the Author(s) is (are) not responsible
24: // for cost, loss of data or any harm that may be caused directly or indirectly
25: // by usage of this softare or this documentation. The usage of this software
26: // is on your own risk. The installation and usage (starting/running) of this
27: // software may allow other people or application to access your computer and
28: // any attached devices and is highly dependent on the configuration of the
29: // software which must be done by the user of the software; the author(s) is
30: // (are) also not responsible for proper configuration and usage of the
31: // software, even if provoked by documentation provided together with
32: // the software.
33: //
34: // Any changes to this file according to the GPL as documented in the file
35: // gpl.txt aside this file in the shipment you received can be done to the
36: // lines that follows this copyright notice here, but changes must not be
37: // done inside the copyright notive above. A re-distribution must contain
38: // the intact and unchanged copyright notice.
39: // Contributions and changes to the program code must be marked as such.
40:
41: package de.anomic.tools;
42:
43: import java.util.Properties;
44:
45: public abstract class loaderCore implements loaderProcess {
46:
47: // status constants
48: public static final int STATUS_IDLE = -1; // not yet initialized
49: public static final int STATUS_READY = 0; // initialized, but not yet started
50: public static final int STATUS_RUNNING = 1; // started and running
51: public static final int STATUS_ABORTED = 2; // terminated before completion
52: public static final int STATUS_FAILED = 3; // failed before completion
53: public static final int STATUS_COMPLETED = 4; // completed; may run again
54: public static final int STATUS_FINALIZED = 9; // completed; may not run again
55:
56: // class variables
57: protected Exception error = null;
58: protected int status = STATUS_IDLE;
59: protected Properties result = new Properties();
60: protected boolean run = true;
61: protected int completion = 0;
62:
63: // steering methods
64: public abstract void feed(byte[] a); // returns true if process was successful; should be always synchronized
65:
66: public void terminate() {
67: // if terminated before completion, completed() shows x < 100
68: run = false;
69: }
70:
71: // feed-back methods
72: public Properties result() {
73: return result;
74: }
75:
76: public int completed() {
77: // guess of completion status. shall be 100 if totally completed.
78: return completion;
79: }
80:
81: // error control
82: public int status() {
83: // -1=idle, 0=ready, 1=running, 2=aborted, 3=failed, 4=completed, 9=finalized
84: return status;
85: }
86:
87: public boolean available() {
88: // true if it is ok to feed with feed()
89: return (status() == STATUS_READY)
90: || ((status() == STATUS_COMPLETED) && ((result == null) || (result
91: .size() == 0)));
92: }
93:
94: public Exception error() {
95: // if in error status: this returnes exception
96: return error;
97: }
98:
99: }
|