bugfixes
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package ch.unisg.executorcomputation;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@@ -10,13 +12,15 @@ import ch.unisg.executorcomputation.executor.domain.Executor;
|
||||
@SpringBootApplication
|
||||
public class ExecutorcomputationApplication {
|
||||
|
||||
static Logger logger = Logger.getLogger(ExecutorcomputationApplication.class.getName());
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(10);
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
SpringApplication.run(ExecutorcomputationApplication.class, args);
|
||||
|
@@ -1,12 +1,20 @@
|
||||
package ch.unisg.executorcomputation.executor.domain;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import ch.unisg.executorbase.executor.domain.ExecutorBase;
|
||||
import ch.unisg.executorbase.executor.domain.ExecutorType;
|
||||
|
||||
public class Executor extends ExecutorBase {
|
||||
|
||||
private static Logger executorLogger = Logger.getLogger(Executor.class.getName());
|
||||
|
||||
private static final Executor executor = new Executor(ExecutorType.COMPUTATION);
|
||||
|
||||
public static Executor getExecutor() {
|
||||
@@ -21,43 +29,30 @@ public class Executor extends ExecutorBase {
|
||||
protected
|
||||
String execution(String inputData) {
|
||||
|
||||
String operator = "";
|
||||
if (inputData.contains("+")) {
|
||||
operator = "+";
|
||||
} else if (inputData.contains("-")) {
|
||||
operator = "-";
|
||||
} else if (inputData.contains("*")) {
|
||||
operator = "*";
|
||||
} else {
|
||||
return "invalid data";
|
||||
}
|
||||
executorLogger.info("TEST");
|
||||
executorLogger.info("Executor | Starting execution with inputData: " + inputData);
|
||||
|
||||
double result = Double.NaN;
|
||||
ScriptEngineManager mgr = new ScriptEngineManager();
|
||||
ScriptEngine engine = mgr.getEngineByName("JavaScript");
|
||||
|
||||
String result = "";
|
||||
try {
|
||||
result = engine.eval(inputData).toString();
|
||||
} catch (ScriptException e1) {
|
||||
// TODO some logic if execution fails
|
||||
executorLogger.severe(e1.getMessage());
|
||||
return result;
|
||||
}
|
||||
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(5);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
executorLogger.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
if (operator.equalsIgnoreCase("+")) {
|
||||
String[] parts = inputData.split("\\+");
|
||||
double a = Double.parseDouble(parts[0]);
|
||||
double b = Double.parseDouble(parts[1]);
|
||||
result = a + b;
|
||||
} else if (operator.equalsIgnoreCase("*")) {
|
||||
String[] parts = inputData.split("\\*");
|
||||
double a = Double.parseDouble(parts[0]);
|
||||
double b = Double.parseDouble(parts[1]);
|
||||
result = a * b;
|
||||
} else if (operator.equalsIgnoreCase("-")) {
|
||||
String[] parts = inputData.split("-");
|
||||
double a = Double.parseDouble(parts[0]);
|
||||
double b = Double.parseDouble(parts[1]);
|
||||
result = a - b;
|
||||
}
|
||||
|
||||
return Double.toString(result);
|
||||
executorLogger.info("Executor | Finish execution");
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user