datai/docs/reference-code/force-wsc-57.0.0/com/sforce/bulk/StreamHandler.java

74 lines
1.6 KiB
Java

package com.sforce.bulk;
import com.sforce.ws.ConnectorConfig;
import java.io.PrintStream;
public class StreamHandler {
private static final String BULK_TAG = "BULK-STREAM:";
private final ConnectorConfig config;
private boolean shutdown = false;
private int errorCount;
public StreamHandler() {
this.config = new ConnectorConfig();
}
public ConnectorConfig getConfig() {
return this.config;
}
public PrintStream getLogStream() {
return System.out;
}
public void info(String message) {
getLogStream().println("BULK-STREAM:INFO:" + message);
}
public void error(String message, Throwable e) throws StreamException {
this.errorCount++;
getLogStream().println("BULK-STREAM:ERROR:" + message);
e.printStackTrace(getLogStream());
if (this.errorCount > getMaxErrorCount()) {
String str = "Tried more than " + getMaxErrorCount() + "... gaving up ...";
info(str);
this.shutdown = true;
} else {
long waitTime = getWaitTime();
info("Error count " + this.errorCount + ". Trying again after " + waitTime);
try {
Thread.sleep(waitTime);
} catch (InterruptedException e1) {
error("Failed to sleep", e1);
}
}
}
public long getWaitTime() {
return (long)(Math.pow(2.0D, this.errorCount) * 1000.0D);
}
public void shutdown() {
this.shutdown = true;
}
public boolean shouldContinue() {
return !this.shutdown;
}
public int getMaxErrorCount() {
return 10;
}
public int getMaxRecordsInBatch() {
return 5000;
}
public long getMaxWaitTime() {
return 600000L;
}
}