This commit is contained in:
Gianpaolo Coro 2012-05-24 10:53:20 +00:00
parent cf2b74436a
commit a02f727d43
1 changed files with 32 additions and 22 deletions

View File

@ -43,6 +43,8 @@ public class LocalSplitGenerator implements Generator {
private int processedRecordsCounter;
private float status;
private int chunksize;
private Timer writerScheduler;
ConcurrentLinkedQueue<String> probabilityBuffer;
String probabilityInsertionStatement = "insert into %1$s (speciesid,csquarecode,probability %ADDEDINFORMATION%) VALUES %2$s";
@ -51,10 +53,10 @@ public class LocalSplitGenerator implements Generator {
setConfiguration(config);
init();
}
public LocalSplitGenerator() {
}
@Override
public float getStatus() {
return status;
@ -125,7 +127,7 @@ public class LocalSplitGenerator implements Generator {
if (!distributionModel.isSynchronousProbabilityWrite()) {
AnalysisLogger.getLogger().trace("init()->insertion scheduler initialized");
// inizialize the scheduler for the insertions
Timer writerScheduler = new Timer();
writerScheduler = new Timer();
writerScheduler.schedule(new DatabaseWriter(), 0, AlgorithmConfiguration.refreshResourcesTime);
}
}
@ -161,12 +163,12 @@ public class LocalSplitGenerator implements Generator {
try {
if ((config != null) && (config.getConfigPath() != null)) {
String defaultDatabaseFile = config.getConfigPath() + AlgorithmConfiguration.defaultConnectionFile;
config.setDatabaseDriver(config.getParam("DatabaseDriver"));
config.setDatabaseUserName(config.getParam("DatabaseUserName"));
config.setDatabasePassword(config.getParam("DatabasePassword"));
config.setDatabaseURL(config.getParam("DatabaseURL"));
dbHibConnection = DatabaseFactory.initDBConnection(defaultDatabaseFile, config);
}
} catch (Exception e) {
@ -177,18 +179,18 @@ public class LocalSplitGenerator implements Generator {
}
private void createTable() throws Exception {
if (config.getParam("CreateTable")!=null && config.getParam("CreateTable").equalsIgnoreCase("true")) {
if (config.getParam("CreateTable") != null && config.getParam("CreateTable").equalsIgnoreCase("true")) {
try {
AnalysisLogger.getLogger().trace("recreating table: "+"drop table " + config.getParam("DistributionTable"));
AnalysisLogger.getLogger().trace("recreating table: " + "drop table " + config.getParam("DistributionTable"));
DatabaseFactory.executeSQLUpdate("drop table " + config.getParam("DistributionTable"), dbHibConnection);
AnalysisLogger.getLogger().trace("recreating table->OK");
} catch (Exception e) {
AnalysisLogger.getLogger().trace("recreating table->"+e.getLocalizedMessage());
AnalysisLogger.getLogger().trace("recreating table->" + e.getLocalizedMessage());
}
// DatabaseFactory.executeUpdateNoTransaction(distributionModel.getDistributionTableStatement(), config.getParam("DatabaseDriver"), config.getParam("DatabaseUserName"), config.getParam("DatabasePassword"), config.getParam("DatabaseURL"), true);
// DatabaseFactory.executeUpdateNoTransaction(distributionModel.getDistributionTableStatement(), config.getParam("DatabaseDriver"), config.getParam("DatabaseUserName"), config.getParam("DatabasePassword"), config.getParam("DatabaseURL"), true);
DatabaseFactory.executeUpdateNoTransaction(distributionModel.getDistributionTableStatement(), config.getDatabaseDriver(), config.getDatabaseUserName(), config.getDatabasePassword(), config.getDatabaseURL(), true);
AnalysisLogger.getLogger().trace("createTable()->OK!");
}
}
@ -196,6 +198,13 @@ public class LocalSplitGenerator implements Generator {
public void shutdown() {
// shutdown threads
executorService.shutdown();
if (writerScheduler != null) {
try {
writerScheduler.cancel();
// writerScheduler.purge();
} catch (Exception e) {
}
}
// shutdown connection
stopInterrupt = true;
if (!distributionModel.isSynchronousProbabilityWrite()) {
@ -232,8 +241,8 @@ public class LocalSplitGenerator implements Generator {
// INITIALIZATION
long tstart = System.currentTimeMillis();
try {
AnalysisLogger.getLogger().trace("generate->Using algorithm "+distributionModel.getName());
AnalysisLogger.getLogger().trace("generate->Using algorithm " + distributionModel.getName());
AnalysisLogger.getLogger().trace("generate->Check for table creation");
createTable();
AnalysisLogger.getLogger().trace("generate->Take area reference");
@ -336,12 +345,13 @@ public class LocalSplitGenerator implements Generator {
AnalysisLogger.getLogger().error(e);
throw e;
} finally {
try{
// REPORT OVERALL ELAPSED TIME
distributionModel.postProcess();
// shutdown all
shutdown();
}catch(Exception e){}
try {
// REPORT OVERALL ELAPSED TIME
distributionModel.postProcess();
// shutdown all
shutdown();
} catch (Exception e) {
}
long tend = System.currentTimeMillis();
long ttotal = tend - tstart;
AnalysisLogger.getLogger().warn("generate->Distribution Generator->Algorithm finished in: " + ((double) ttotal / (double) 60000) + " min\n");
@ -469,7 +479,7 @@ public class LocalSplitGenerator implements Generator {
@Override
public ALG_PROPS[] getSupportedAlgorithms() {
ALG_PROPS[] p = {ALG_PROPS.SPECIES_VS_CSQUARE_FROM_DATABASE};
ALG_PROPS[] p = { ALG_PROPS.SPECIES_VS_CSQUARE_FROM_DATABASE };
return p;
}
@ -477,7 +487,7 @@ public class LocalSplitGenerator implements Generator {
public WEIGHT getWeight() {
return WEIGHT.LOWEST;
}
@Override
public HashMap<String, VarCouple> getInputParameters() {
return distributionModel.getInputParameters();
@ -492,5 +502,5 @@ public class LocalSplitGenerator implements Generator {
public Object getContent() {
return config.getParam("DistributionTable");
}
}