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;
|
package edu.lu.uni.serval.MultipleThreadsParser;
|
||||||
|
|
||||||
|
import static java.lang.System.err;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -9,7 +17,9 @@ import org.slf4j.LoggerFactory;
|
|||||||
import akka.actor.Props;
|
import akka.actor.Props;
|
||||||
import akka.actor.UntypedActor;
|
import akka.actor.UntypedActor;
|
||||||
import akka.japi.Creator;
|
import akka.japi.Creator;
|
||||||
|
import edu.lu.uni.serval.FixPatternParser.RunnableParser;
|
||||||
import edu.lu.uni.serval.FixPatternParser.SingleStatementParser;
|
import edu.lu.uni.serval.FixPatternParser.SingleStatementParser;
|
||||||
|
import edu.lu.uni.serval.config.Configuration;
|
||||||
import edu.lu.uni.serval.utils.FileHelper;
|
import edu.lu.uni.serval.utils.FileHelper;
|
||||||
|
|
||||||
public class ParseFixPatternWorker extends UntypedActor {
|
public class ParseFixPatternWorker extends UntypedActor {
|
||||||
@@ -58,33 +68,52 @@ public class ParseFixPatternWorker extends UntypedActor {
|
|||||||
File prevFile = msgFile.getPrevFile();
|
File prevFile = msgFile.getPrevFile();
|
||||||
File diffentryFile = msgFile.getDiffEntryFile();
|
File diffentryFile = msgFile.getDiffEntryFile();
|
||||||
SingleStatementParser parser = new SingleStatementParser();
|
SingleStatementParser parser = new SingleStatementParser();
|
||||||
parser.parseFixPatterns(prevFile, revFile, diffentryFile);
|
|
||||||
editScripts.append(parser.getAstEditScripts());
|
final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
patchesSourceCode.append(parser.getPatchesSourceCode());
|
// schedule the work
|
||||||
sizes.append(parser.getSizes());
|
final Future<?> future = executor.submit(new RunnableParser(prevFile, revFile, diffentryFile, parser));
|
||||||
// buggyTrees.append(parser.getBuggyTrees());
|
try {
|
||||||
tokens.append(parser.getTokensOfSourceCode());
|
// wait for task to complete
|
||||||
counter ++;
|
future.get(Configuration.SECONDS_TO_WAIT, TimeUnit.SECONDS);
|
||||||
if (counter % 100 == 0) {
|
|
||||||
FileHelper.outputToFile(editScriptsFilePath + "edistScripts_" + id + ".list", editScripts, true);
|
editScripts.append(parser.getAstEditScripts());
|
||||||
FileHelper.outputToFile(patchesSourceCodeFilePath + "patches_" + id + ".list", patchesSourceCode, true);
|
patchesSourceCode.append(parser.getPatchesSourceCode());
|
||||||
FileHelper.outputToFile(editScriptSizesFilePath + "sizes_" + id + ".list", sizes, true);
|
sizes.append(parser.getSizes());
|
||||||
// FileHelper.outputToFile(buggyTreesFilePath + "buggyTrees_" + id + ".list", buggyTrees, true);
|
// buggyTrees.append(parser.getBuggyTrees());
|
||||||
FileHelper.outputToFile(buggyTokensFilePath + "tokens_" + id + ".list", tokens, true);
|
tokens.append(parser.getTokensOfSourceCode());
|
||||||
editScripts.setLength(0);
|
counter ++;
|
||||||
patchesSourceCode.setLength(0);
|
if (counter % 100 == 0) {
|
||||||
sizes.setLength(0);
|
FileHelper.outputToFile(editScriptsFilePath + "edistScripts_" + id + ".list", editScripts, true);
|
||||||
// buggyTrees.setLength(0);
|
FileHelper.outputToFile(patchesSourceCodeFilePath + "patches_" + id + ".list", patchesSourceCode, true);
|
||||||
tokens.setLength(0);
|
FileHelper.outputToFile(editScriptSizesFilePath + "sizes_" + id + ".list", sizes, true);
|
||||||
log.info("Worker #" + id +"Finish of parsing " + counter + " files...");
|
// 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);
|
if (sizes.length() > 0) {
|
||||||
FileHelper.outputToFile(patchesSourceCodeFilePath + "patches_" + id + ".list", patchesSourceCode, true);
|
FileHelper.outputToFile(editScriptsFilePath + "edistScripts_" + id + ".list", editScripts, true);
|
||||||
FileHelper.outputToFile(editScriptSizesFilePath + "sizes_" + id + ".list", sizes, true);
|
FileHelper.outputToFile(patchesSourceCodeFilePath + "patches_" + id + ".list", patchesSourceCode, true);
|
||||||
// FileHelper.outputToFile(buggyTreesFilePath + "buggyTrees_" + id + ".list", buggyTrees, true);
|
FileHelper.outputToFile(editScriptSizesFilePath + "sizes_" + id + ".list", sizes, true);
|
||||||
FileHelper.outputToFile(buggyTokensFilePath + "tokens_" + id + ".list", tokens, 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 +"Finish of parsing " + counter + " files...");
|
||||||
log.info("Worker #" + id + " finished the work...");
|
log.info("Worker #" + id + " finished the work...");
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package edu.lu.uni.serval.config;
|
package edu.lu.uni.serval.config;
|
||||||
|
|
||||||
public class Configuration {
|
public class Configuration {
|
||||||
|
|
||||||
|
public static final long SECONDS_TO_WAIT = 60L;
|
||||||
|
|
||||||
private static final String ROOT_PATH = "";//"../"; // The root path of all output data.
|
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.
|
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_BUGS70 = ROOT_PATH + "Bugs/bugs70.list";
|
||||||
public static final String TESTING_DATA_BUGS60 = ROOT_PATH + "Bugs/bugs60.list";
|
public static final String TESTING_DATA_BUGS60 = ROOT_PATH + "Bugs/bugs60.list";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user