001: // serverThread.java
002: // -----------------------
003: // (C) by Michael Peter Christen; mc@anomic.de
004: // first published on http://www.yacy.net
005: // Frankfurt, Germany, 2005
006: // last major change: 14.03.2005
007: //
008: // This program is free software; you can redistribute it and/or modify
009: // it under the terms of the GNU General Public License as published by
010: // the Free Software Foundation; either version 2 of the License, or
011: // (at your option) any later version.
012: //
013: // This program is distributed in the hope that it will be useful,
014: // but WITHOUT ANY WARRANTY; without even the implied warranty of
015: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: // GNU General Public License for more details.
017: //
018: // You should have received a copy of the GNU General Public License
019: // along with this program; if not, write to the Free Software
020: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: //
022: // Using this software in any meaning (reading, learning, copying, compiling,
023: // running) means that you agree that the Author(s) is (are) not responsible
024: // for cost, loss of data or any harm that may be caused directly or indirectly
025: // by usage of this softare or this documentation. The usage of this software
026: // is on your own risk. The installation and usage (starting/running) of this
027: // software may allow other people or application to access your computer and
028: // any attached devices and is highly dependent on the configuration of the
029: // software which must be done by the user of the software; the author(s) is
030: // (are) also not responsible for proper configuration and usage of the
031: // software, even if provoked by documentation provided together with
032: // the software.
033: //
034: // Any changes to this file according to the GPL as documented in the file
035: // gpl.txt aside this file in the shipment you received can be done to the
036: // lines that follows this copyright notice here, but changes must not be
037: // done inside the copyright notive above. A re-distribution must contain
038: // the intact and unchanged copyright notice.
039: // Contributions and changes to the program code must be marked as such.
040:
041: package de.anomic.server;
042:
043: import de.anomic.server.logging.serverLog;
044:
045: public interface serverThread {
046:
047: // -------------------------------------------------------
048: // methods inherited from Thread; needed for compatibility
049: public void start();
050:
051: public boolean isAlive();
052:
053: // --------------------------------------------------------------------------
054: // these method are implemented by serverThread and do not need to be altered
055: // this includes also the run()-Method
056:
057: public void setDescription(String shortText, String longText,
058: String monitorURL);
059:
060: // sets a visible description string
061:
062: public void setStartupSleep(long milliseconds);
063:
064: // sets a sleep time before execution of the job-loop
065:
066: public long setIdleSleep(long milliseconds);
067:
068: // sets a sleep time for pauses between two jobs if the job returns false (idle)
069:
070: public long setBusySleep(long milliseconds);
071:
072: // sets a sleep time for pauses between two jobs if the job returns true (busy)
073:
074: public void setMemPreReqisite(long freeBytes);
075:
076: // sets minimum required amount of memory for the job execution
077:
078: public void setObeyIntermission(boolean obey);
079:
080: // defines if the thread should obey the intermission command
081:
082: public String getShortDescription();
083:
084: // returns short description string for online display
085:
086: public String getLongDescription();
087:
088: // returns long description string for online display
089:
090: public String getMonitorURL();
091:
092: // returns an URL that can be used to monitor the thread and it's queue
093:
094: public long getIdleCycles();
095:
096: // returns the total number of cycles of job execution with idle-result
097:
098: public long getBusyCycles();
099:
100: // returns the total number of cycles of job execution with busy-result
101:
102: public long getOutOfMemoryCycles();
103:
104: // returns the total number of cycles where
105: // a job execution was omitted because of memory shortage
106:
107: public long getBlockTime();
108:
109: // returns the total time that this thread has been blocked so far
110:
111: public long getSleepTime();
112:
113: // returns the total time that this thread has slept so far
114:
115: public long getExecTime();
116:
117: // returns the total time that this thread has worked so far
118:
119: public long getMemoryUse();
120:
121: // returns the sum of all memory usage differences before and after one busy job
122:
123: public void setLog(serverLog log);
124:
125: // defines a log where process states can be written to
126:
127: public void jobExceptionHandler(Exception e);
128:
129: // handles any action necessary during job execution
130:
131: public void intermission(long pause);
132:
133: // the thread is forced to pause for a specific time
134: // if the thread is busy meanwhile, the pause is ommitted
135:
136: public boolean shutdownInProgress();
137:
138: public void terminate(boolean waitFor);
139:
140: // after calling this method, the thread shall terminate
141: // if waitFor is true, the method waits until the process has died
142:
143: // ---------------------------------------------------------------------
144: // the following methods are supposed to be implemented by customization
145:
146: public void open();
147:
148: // this is called right before the job queue is started
149:
150: public boolean job() throws Exception;
151:
152: // performes one job procedure; this loopes until terminate() is called
153: // job returns true if it has done something
154: // it returns false if it is idle and does not expect to work on more for a longer time
155:
156: public void freemem();
157:
158: // is called when an outOfMemoryCycle is performed
159: // this method should try to free some memory, so that the job can be executed
160:
161: public int getJobCount();
162:
163: // returns how many jobs are in the queue
164: // can be used to calculate a busy-state
165:
166: public void close();
167:
168: // jobs that need to be done after termination
169: // terminate must be called before
170:
171: public void setSyncObject(Object sync);
172:
173: public Object getSyncObject();
174:
175: public void notifyThread();
176:
177: }
|