mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-21 00:00:13 +02:00
1a8a134e0c
The result should be a less usage of new String() and less memory usage (since a String-encapsulated byte[] has 40 bytes overhead) git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6815 6c8d7289-2bf4-0310-a012-ef5d649a1542
110 lines
3.1 KiB
Java
110 lines
3.1 KiB
Java
package de.anomic.crawler;
|
|
|
|
import net.yacy.kelondro.logging.Log;
|
|
|
|
public abstract class AbstractImporter extends Thread implements Importer {
|
|
|
|
private int jobID = -1;
|
|
private String jobType;
|
|
private Log log;
|
|
private boolean stopped = false;
|
|
private boolean paused = false;
|
|
private long globalStart = System.currentTimeMillis();
|
|
protected long globalEnd;
|
|
private long globalPauseLast;
|
|
private long globalPauseDuration;
|
|
private String error;
|
|
|
|
public AbstractImporter(final String theJobType) {
|
|
this.jobType = theJobType;
|
|
|
|
// initializing the logger and setting a more verbose thread name
|
|
this.log = new Log("IMPORT_" + this.jobType + "_" + this.jobID);
|
|
this.setName("IMPORT_" + this.jobType + "_" + this.jobID);
|
|
}
|
|
|
|
public String getError() {
|
|
return this.error;
|
|
}
|
|
|
|
public void startIt() {
|
|
this.start();
|
|
}
|
|
|
|
public void stopIt() throws InterruptedException {
|
|
this.stopped = true;
|
|
this.continueIt();
|
|
this.join();
|
|
}
|
|
|
|
public void pauseIt() {
|
|
synchronized(this) {
|
|
this.globalPauseLast = System.currentTimeMillis();
|
|
this.paused = true;
|
|
}
|
|
}
|
|
|
|
public void continueIt() {
|
|
synchronized(this) {
|
|
if (this.paused) {
|
|
this.globalPauseDuration += System.currentTimeMillis()-this.globalPauseLast;
|
|
this.paused = false;
|
|
this.notifyAll();
|
|
}
|
|
}
|
|
}
|
|
|
|
public boolean isPaused() {
|
|
synchronized(this) {
|
|
return this.paused;
|
|
}
|
|
}
|
|
|
|
protected boolean isAborted() {
|
|
synchronized(this) {
|
|
if (this.paused) {
|
|
try {
|
|
this.wait();
|
|
}
|
|
catch (final InterruptedException e){}
|
|
}
|
|
}
|
|
|
|
return (this.stopped) || Thread.currentThread().isInterrupted();
|
|
}
|
|
|
|
public boolean isStopped() {
|
|
return !this.isAlive();
|
|
}
|
|
|
|
public int getJobID() {
|
|
return this.jobID;
|
|
}
|
|
|
|
public void setJobID(final int id) {
|
|
if (this.jobID != -1) throw new IllegalStateException("job ID already assigned");
|
|
this.jobID = id;
|
|
}
|
|
|
|
public long getTotalRuntime() {
|
|
return (this.globalEnd == 0)?System.currentTimeMillis()-(this.globalStart+this.globalPauseDuration):this.globalEnd-(this.globalStart+this.globalPauseDuration);
|
|
}
|
|
|
|
public long getElapsedTime() {
|
|
if(this.paused) {
|
|
this.globalPauseDuration += System.currentTimeMillis()-this.globalPauseLast;
|
|
this.globalPauseLast = System.currentTimeMillis();
|
|
}
|
|
return isStopped()?this.globalEnd-(this.globalStart+this.globalPauseDuration):System.currentTimeMillis()-(this.globalStart+this.globalPauseDuration);
|
|
}
|
|
|
|
public String getJobType() {
|
|
return this.jobType;
|
|
}
|
|
|
|
public abstract long getEstimatedTime();
|
|
public abstract String getJobName();
|
|
public abstract int getProcessingStatusPercent();
|
|
|
|
}
|