java \
-cp "/opt/elasticsearch-jdbc/lib/*" \
-Dlog4j.configurationFile=/opt/elasticsearch-jdbc/bin/log4j2.xml \
org.xbib.tools.Runner \
org.xbib.tools.JDBCImporter \
/tmp/config.json
- 执行org.xbib.tools.Runner的main方法
public static void main(String[] args) {
try {
Class clazz = Class.forName(args[0]);
CommandLineInterpreter commandLineInterpreter = (CommandLineInterpreter) clazz.newInstance();
InputStream in = args.length > 1 ? new FileInputStream(args[1]) : System.in;
commandLineInterpreter.reader("args", in).run(true); 执行JDBCImporter的run(boolean bootstrap)方法
in.close();
} catch (Throwable e) {
e.printStackTrace();
System.exit(1);
}
System.exit(0);
}
prepare();
futures = schedule(settings);
if (!futures.isEmpty()) {
logger.debug("waiting for {} futures...", futures.size());
for (Future future : futures) {
try {
Object o = future.get();
logger.debug("got future {}", o);
} catch (CancellationException e) {
logger.warn("schedule canceled");
} catch (InterruptedException e) {
logger.error(e.getMessage(), e);
} catch (ExecutionException e) {
logger.error(e.getMessage(), e);
}
}
logger.debug("futures complete");
} else {
execute();
}
- execute方法实例化MetricSimplePipelineExecutor,并执行execute方法。而execute实质上执行的是JDBCImporter的call方法。
public MeterMetric call() throws Exception {
try {
metric = new MeterMetric(5L, TimeUnit.SECONDS);
Iterator<R> it = this;
while (it.hasNext()) {
R r = it.next();
requestListeners.put(null, this);
errorListeners.put(null, this);
for (PipelineRequestListener<MeterMetric, R> requestListener : requestListeners.values()) {
try {
requestListener.newRequest(this, r);
} catch (PipelineException e) {
for (PipelineErrorListener<MeterMetric, R, E> errorListener : errorListeners.values()) {
errorListener.error(this, r, (E) e);
}
}
}
metric.mark();
}
close();
} finally {
metric.stop();
}
return getMetric();
}
- JDBCImporter的process方法初始化StandardContext,并执行StandardContext的execute方法
public void execute() throws Exception {
try {
state = State.BEFORE_FETCH;
beforeFetch();
state = State.FETCH;
fetch();
} finally {
state = State.AFTER_FETCH;
afterFetch();
state = State.IDLE;
}
}