From 47ec1dca5aa43dda026b1582cc9a9fc506e93a63 Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Sat, 29 Feb 2020 22:22:37 +0100 Subject: [PATCH] modified: src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyTaskModel.java new file: src/main/java/de/dhbwstuttgart/typeinference/unify/controlCancel.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit controlCancel.java kann durch IProgressMonitor aus Eclipse implementiert werden. So lässt sich das Cancel-Problem des Eclipse-Plugins loesen. --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 16 +++++++++-- .../typeinference/unify/TypeUnify.java | 16 +++++------ .../typeinference/unify/TypeUnify2Task.java | 4 +-- .../typeinference/unify/TypeUnifyTask.java | 28 +++++++++++++------ .../typeinference/unify/UnifyTaskModel.java | 4 +++ .../typeinference/unify/controlCancel.java | 5 ++++ 6 files changed, 52 insertions(+), 21 deletions(-) create mode 100644 src/main/java/de/dhbwstuttgart/typeinference/unify/controlCancel.java diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index d44ac77f..13f9d0af 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -35,6 +35,7 @@ import de.dhbwstuttgart.typeinference.unify.UnifyResultListener; import de.dhbwstuttgart.typeinference.unify.UnifyResultListenerImpl; import de.dhbwstuttgart.typeinference.unify.UnifyResultModel; import de.dhbwstuttgart.typeinference.unify.UnifyTaskModel; +import de.dhbwstuttgart.typeinference.unify.controlCancel; import java.io.File; import java.io.FileOutputStream; @@ -54,6 +55,15 @@ public class JavaTXCompiler { public final Map sourceFiles = new HashMap<>(); Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll? public volatile UnifyTaskModel usedTasks = new UnifyTaskModel(); + public controlCancel cC = () -> false; //kann z.B. durche eine Implementierung + //von dem Eclipse Interface IProgressMonitor + //instanziert werden. + + public JavaTXCompiler(File sourceFile, controlCancel cC) throws IOException, ClassNotFoundException { + this(Arrays.asList(sourceFile)); + this.cC = cC; + INSTANCE = this; + } public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException { this(Arrays.asList(sourceFile)); @@ -436,7 +446,7 @@ public class JavaTXCompiler { return ret; }).collect(Collectors.toCollection(ArrayList::new)); unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, - usedTasks); + usedTasks, cC); } catch (IOException e) { System.err.println("kein LogFile"); } @@ -607,7 +617,7 @@ public class JavaTXCompiler { UnifyResultListenerImpl li = new UnifyResultListenerImpl(); urm.addUnifyResultListener(li); unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, - usedTasks); + usedTasks, cC); System.out.println("RESULT Final: " + li.getResults()); logFile.write("RES_FINAL: " + li.getResults().toString() + "\n"); logFile.flush(); @@ -619,7 +629,7 @@ public class JavaTXCompiler { // oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, // finiteClosure)); Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, - finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure), usedTasks); + finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure), usedTasks, cC); System.out.println("RESULT: " + result); logFile.write("RES: " + result.toString() + "\n"); logFile.flush(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index 6b045547..79c7dc2d 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -28,8 +28,8 @@ public class TypeUnify { * @param cons * @return */ - public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); + public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks, controlCancel cC) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks, cC); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); @@ -54,8 +54,8 @@ public class TypeUnify { * @param ret * @return */ - public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); + public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks, controlCancel cC) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks, cC); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); return ret; @@ -72,8 +72,8 @@ public class TypeUnify { * @param ret * @return */ - public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); + public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks, controlCancel cC) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks, cC); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); @@ -105,8 +105,8 @@ public class TypeUnify { * @param cons * @return */ - public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret, usedTasks); + public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks, controlCancel cC) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret, usedTasks, cC); Set> res = unifyTask.compute(); try { logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n"); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 54c3fb99..5920dd84 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -18,8 +18,8 @@ public class TypeUnify2Task extends TypeUnifyTask { Set> setToFlatten; - public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) { - super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, controlCancel cC) { + super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, cC); this.setToFlatten = setToFlatten; this.nextSetElement = nextSetElement; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 8e940d70..22409031 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -122,10 +122,16 @@ public class TypeUnifyTask extends RecursiveTask>> { static Integer noShortendElements = 0; + /* Field wird nicht mehr benutzt + * Der cancel-Mechanismus wird durch die Implementierung von controlCancel + * erledigt. Boolean myIsCanceled = false; + */ volatile UnifyTaskModel usedTasks; + volatile controlCancel cC; + public TypeUnifyTask() { rules = new RuleSet(); } @@ -145,7 +151,7 @@ public class TypeUnifyTask extends RecursiveTask>> { */ - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) { + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, controlCancel cC) { synchronized (this) { this.eq = eq; //this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); @@ -165,6 +171,7 @@ public class TypeUnifyTask extends RecursiveTask>> { this.parallel = parallel; this.logFile = logFile; this.log = log; + this.cC = cC; noOfThread++; totalnoOfThread++; @@ -228,12 +235,17 @@ public class TypeUnifyTask extends RecursiveTask>> { } } */ + /* Methode wird nicht mehr benutzt + * Der cancel-Mechanismus wird durch die Implementierung von controlCancel + * erledigt. void myCancel(Boolean b) { myIsCanceled = true; } + */ public boolean myIsCancelled() { - return myIsCanceled; + //return myIsCanceled; + return cC.isCanceled(); } protected Set> compute() { @@ -839,7 +851,7 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, cC); //forks.add(forkOrig); synchronized(usedTasks) { if (this.myIsCancelled()) { @@ -891,7 +903,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, cC); forks.add(fork); synchronized(usedTasks) { if (this.myIsCancelled()) { @@ -945,7 +957,7 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, cC); //forks.add(forkOrig); synchronized(usedTasks) { if (this.myIsCancelled()) { @@ -997,7 +1009,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, cC); forks.add(fork); synchronized(usedTasks) { if (this.myIsCancelled()) { @@ -1052,7 +1064,7 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, cC); //forks.add(forkOrig); synchronized(usedTasks) { if (this.myIsCancelled()) { @@ -1073,7 +1085,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, cC); forks.add(fork); synchronized(usedTasks) { if (this.myIsCancelled()) { diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyTaskModel.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyTaskModel.java index e60054f0..a385b974 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyTaskModel.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyTaskModel.java @@ -10,9 +10,13 @@ public class UnifyTaskModel { usedTasks.add(t); } + /* Methode wird nicht mehr benutzt + * Der cancel-Mechanismus wird durch die Implementierung von controlCancel + * erledigt. public synchronized void cancel() { for(TypeUnifyTask t : usedTasks) { t.myCancel(true); } } + */ } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/controlCancel.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/controlCancel.java new file mode 100644 index 00000000..1f9835c2 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/controlCancel.java @@ -0,0 +1,5 @@ +package de.dhbwstuttgart.typeinference.unify; + +public interface controlCancel { + public Boolean isCanceled(); +}