Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nopol actor #10

Merged
merged 19 commits into from
Sep 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
747 changes: 387 additions & 360 deletions nopol/pom.xml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion nopol/src/main/java/fr/inria/lille/repair/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ private static void showUsage() {
System.err.println(jsap.getHelp());
}

public static boolean parseArguments(String[] args, Config config) {

private static boolean parseArguments(String[] args, Config config) {
JSAPResult jsapConfig = jsap.parse(args);
if (!jsapConfig.success()) {
System.err.println();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package fr.inria.lille.repair.actor;

import akka.actor.ActorRef;
import akka.actor.UntypedActor;
import fr.inria.lille.repair.common.config.Config;
import fr.inria.lille.repair.common.patch.Patch;
import fr.inria.lille.repair.nopol.NoPolLauncher;

import java.util.Collections;
import java.util.List;

/**
* Created by bdanglot on 9/16/16.
*/
public class InternalNopolActor extends UntypedActor {

@Override
public void onReceive(Object message) throws Exception {
if (message instanceof NoPolActor.ConfigActor) {

Config config = ((NoPolActor.ConfigActor) message).config;
ActorRef client = ((NoPolActor.ConfigActor) message).client;

if (config.getSynthesis() == Config.NopolSynthesis.SMT) {
config.setSolverPath(NoPolActor.pathToSolver);
}

List<Patch> patches = Collections.EMPTY_LIST;
try {
patches = NoPolLauncher.launch(config.buildSourceFiles(), config.buildClasspath(), config);
} catch (Exception e) {
throw new RuntimeException("Error launch NoPol", e);
} finally {
getSender().tell(NoPolActor.Message.AVAILABLE, getSelf());
}

client.tell(patches, ActorRef.noSender());


//Internal debug
if (patches.isEmpty())
System.out.println("No Patch Found!");
else
for (Patch patch : patches)
System.out.println(patch);
} else
unhandled(message);//Unsupported message type

}
}
75 changes: 75 additions & 0 deletions nopol/src/main/java/fr/inria/lille/repair/actor/NoPolActor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package fr.inria.lille.repair.actor;


import akka.actor.*;
import com.martiansoftware.jsap.JSAPException;
import com.typesafe.config.ConfigFactory;
import fr.inria.lille.repair.Main;
import fr.inria.lille.repair.common.config.Config;

import java.util.HashMap;
import java.util.Map;

/**
* Created by bdanglot on 9/12/16.
*/
public class NoPolActor extends UntypedActor {

final class ConfigActor {
final Config config;
final ActorRef client;
ConfigActor(Config config, ActorRef client) {
this.config = config;
this.client = client;
}
}

private Map<ActorRef, Boolean> pool = new HashMap<>();

public NoPolActor(ActorSystem system) {
for (int i = 0; i < 10; i++)
this.pool.put(system.actorOf(Props.create(InternalNopolActor.class), "InternalNopolActor_" + i), Boolean.TRUE);
}

@Override
public void onReceive(Object message) {
if (message instanceof Config) {
boolean taskSent = false;
//Looking for free actor
for (ActorRef actorRef : this.pool.keySet()) {
if (this.pool.get(actorRef)) {
taskSent = true;
actorRef.tell(new ConfigActor((Config) message, getSender()), getSelf());
this.pool.put(actorRef, Boolean.FALSE);
break;
}
}
if (!taskSent)
this.pool.keySet().iterator().next().tell(message, getSender());//send to the first actor of the keyset
} else if (message instanceof Message) {
switch ((Message) message) {
case AVAILABLE:
this.pool.put(getSender(), Boolean.TRUE);
break;
default:
unhandled(message);//Unsupported message type
}
} else
unhandled(message);//Unsupported message type
}

enum Message {AVAILABLE}

static String pathToSolver;// = "/home/bdanglot/workspace/nopol/nopol/lib/z3/z3_for_linux";

public static void main(String[] args) throws JSAPException {
com.typesafe.config.Config config = ConfigFactory.load("nopol");
pathToSolver = config.getString("nopol.solver.path");
String ACTOR_SYSTEM_NAME = config.getString("nopol.system.name");
String ACTOR_NAME = config.getString("nopol.actor.name");
ActorSystem system = ActorSystem.create(ACTOR_SYSTEM_NAME, config);
ActorRef actorNopol = system.actorOf(Props.create(NoPolActor.class, system), ACTOR_NAME);
System.out.println(actorNopol);
}

}