Add a time out into akka worker.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package edu.lu.uni.serval.FixPatternParser;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class RunnableParser implements Runnable {
|
||||
|
||||
private File prevFile;
|
||||
private File revFile;
|
||||
private File diffentryFile;
|
||||
SingleStatementParser parser;
|
||||
|
||||
public RunnableParser(File prevFile, File revFile, File diffentryFile, SingleStatementParser parser) {
|
||||
this.prevFile = prevFile;
|
||||
this.revFile = revFile;
|
||||
this.diffentryFile = diffentryFile;
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
parser.parseFixPatterns(prevFile, revFile, diffentryFile);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,15 @@
|
||||
package edu.lu.uni.serval.MultipleThreadsParser;
|
||||
|
||||
import static java.lang.System.err;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -9,7 +17,9 @@ import org.slf4j.LoggerFactory;
|
||||
import akka.actor.Props;
|
||||
import akka.actor.UntypedActor;
|
||||
import akka.japi.Creator;
|
||||
import edu.lu.uni.serval.FixPatternParser.RunnableParser;
|
||||
import edu.lu.uni.serval.FixPatternParser.SingleStatementParser;
|
||||
import edu.lu.uni.serval.config.Configuration;
|
||||
import edu.lu.uni.serval.utils.FileHelper;
|
||||
|
||||
public class ParseFixPatternWorker extends UntypedActor {
|
||||
@@ -58,33 +68,52 @@ public class ParseFixPatternWorker extends UntypedActor {
|
||||
File prevFile = msgFile.getPrevFile();
|
||||
File diffentryFile = msgFile.getDiffEntryFile();
|
||||
SingleStatementParser parser = new SingleStatementParser();
|
||||
parser.parseFixPatterns(prevFile, revFile, diffentryFile);
|
||||
editScripts.append(parser.getAstEditScripts());
|
||||
patchesSourceCode.append(parser.getPatchesSourceCode());
|
||||
sizes.append(parser.getSizes());
|
||||
// buggyTrees.append(parser.getBuggyTrees());
|
||||
tokens.append(parser.getTokensOfSourceCode());
|
||||
counter ++;
|
||||
if (counter % 100 == 0) {
|
||||
FileHelper.outputToFile(editScriptsFilePath + "edistScripts_" + id + ".list", editScripts, true);
|
||||
FileHelper.outputToFile(patchesSourceCodeFilePath + "patches_" + id + ".list", patchesSourceCode, true);
|
||||
FileHelper.outputToFile(editScriptSizesFilePath + "sizes_" + id + ".list", sizes, true);
|
||||
// FileHelper.outputToFile(buggyTreesFilePath + "buggyTrees_" + id + ".list", buggyTrees, true);
|
||||
FileHelper.outputToFile(buggyTokensFilePath + "tokens_" + id + ".list", tokens, true);
|
||||
editScripts.setLength(0);
|
||||
patchesSourceCode.setLength(0);
|
||||
sizes.setLength(0);
|
||||
// buggyTrees.setLength(0);
|
||||
tokens.setLength(0);
|
||||
log.info("Worker #" + id +"Finish of parsing " + counter + " files...");
|
||||
|
||||
final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
// schedule the work
|
||||
final Future<?> future = executor.submit(new RunnableParser(prevFile, revFile, diffentryFile, parser));
|
||||
try {
|
||||
// wait for task to complete
|
||||
future.get(Configuration.SECONDS_TO_WAIT, TimeUnit.SECONDS);
|
||||
|
||||
editScripts.append(parser.getAstEditScripts());
|
||||
patchesSourceCode.append(parser.getPatchesSourceCode());
|
||||
sizes.append(parser.getSizes());
|
||||
// buggyTrees.append(parser.getBuggyTrees());
|
||||
tokens.append(parser.getTokensOfSourceCode());
|
||||
counter ++;
|
||||
if (counter % 100 == 0) {
|
||||
FileHelper.outputToFile(editScriptsFilePath + "edistScripts_" + id + ".list", editScripts, true);
|
||||
FileHelper.outputToFile(patchesSourceCodeFilePath + "patches_" + id + ".list", patchesSourceCode, true);
|
||||
FileHelper.outputToFile(editScriptSizesFilePath + "sizes_" + id + ".list", sizes, true);
|
||||
// FileHelper.outputToFile(buggyTreesFilePath + "buggyTrees_" + id + ".list", buggyTrees, true);
|
||||
FileHelper.outputToFile(buggyTokensFilePath + "tokens_" + id + ".list", tokens, true);
|
||||
editScripts.setLength(0);
|
||||
patchesSourceCode.setLength(0);
|
||||
sizes.setLength(0);
|
||||
// buggyTrees.setLength(0);
|
||||
tokens.setLength(0);
|
||||
log.info("Worker #" + id +"Finish of parsing " + counter + " files...");
|
||||
}
|
||||
} catch (TimeoutException e) {
|
||||
err.println("task timed out");
|
||||
future.cancel(true /* mayInterruptIfRunning */ );
|
||||
} catch (InterruptedException e) {
|
||||
err.println("task interrupted");
|
||||
} catch (ExecutionException e) {
|
||||
err.println("task aborted");
|
||||
} finally {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
FileHelper.outputToFile(editScriptsFilePath + "edistScripts_" + id + ".list", editScripts, true);
|
||||
FileHelper.outputToFile(patchesSourceCodeFilePath + "patches_" + id + ".list", patchesSourceCode, true);
|
||||
FileHelper.outputToFile(editScriptSizesFilePath + "sizes_" + id + ".list", sizes, true);
|
||||
// FileHelper.outputToFile(buggyTreesFilePath + "buggyTrees_" + id + ".list", buggyTrees, true);
|
||||
FileHelper.outputToFile(buggyTokensFilePath + "tokens_" + id + ".list", tokens, true);
|
||||
if (sizes.length() > 0) {
|
||||
FileHelper.outputToFile(editScriptsFilePath + "edistScripts_" + id + ".list", editScripts, true);
|
||||
FileHelper.outputToFile(patchesSourceCodeFilePath + "patches_" + id + ".list", patchesSourceCode, true);
|
||||
FileHelper.outputToFile(editScriptSizesFilePath + "sizes_" + id + ".list", sizes, true);
|
||||
// FileHelper.outputToFile(buggyTreesFilePath + "buggyTrees_" + id + ".list", buggyTrees, true);
|
||||
FileHelper.outputToFile(buggyTokensFilePath + "tokens_" + id + ".list", tokens, true);
|
||||
}
|
||||
|
||||
log.info("Worker #" + id +"Finish of parsing " + counter + " files...");
|
||||
log.info("Worker #" + id + " finished the work...");
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package edu.lu.uni.serval.config;
|
||||
|
||||
public class Configuration {
|
||||
|
||||
public static final long SECONDS_TO_WAIT = 60L;
|
||||
|
||||
private static final String ROOT_PATH = "";//"../"; // The root path of all output data.
|
||||
|
||||
public static final int HUNK_SIZE = 7; // The limitation of source code lines of each DiffEntry, which will be selected as training data.
|
||||
@@ -84,5 +87,4 @@ public class Configuration {
|
||||
public static final String TESTING_DATA_BUGS70 = ROOT_PATH + "Bugs/bugs70.list";
|
||||
public static final String TESTING_DATA_BUGS60 = ROOT_PATH + "Bugs/bugs60.list";
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user