diff options
Diffstat (limited to 'Solvers/Alloy-Solver2/hu.bme.mit.inf.dlsreasoner.alloy.reasoner/unused/FunctionWithTimeout.xtend_')
-rw-r--r-- | Solvers/Alloy-Solver2/hu.bme.mit.inf.dlsreasoner.alloy.reasoner/unused/FunctionWithTimeout.xtend_ | 40 |
1 files changed, 0 insertions, 40 deletions
diff --git a/Solvers/Alloy-Solver2/hu.bme.mit.inf.dlsreasoner.alloy.reasoner/unused/FunctionWithTimeout.xtend_ b/Solvers/Alloy-Solver2/hu.bme.mit.inf.dlsreasoner.alloy.reasoner/unused/FunctionWithTimeout.xtend_ deleted file mode 100644 index 4f001c72..00000000 --- a/Solvers/Alloy-Solver2/hu.bme.mit.inf.dlsreasoner.alloy.reasoner/unused/FunctionWithTimeout.xtend_ +++ /dev/null | |||
@@ -1,40 +0,0 @@ | |||
1 | package hu.bme.mit.inf.dlsreasoner.alloy.reasoner.builder | ||
2 | |||
3 | import org.eclipse.xtext.xbase.lib.Functions.Function0 | ||
4 | import java.util.concurrent.Executors | ||
5 | import java.util.concurrent.Callable | ||
6 | import java.util.concurrent.TimeUnit | ||
7 | import java.util.concurrent.TimeoutException | ||
8 | import java.util.concurrent.ExecutionException | ||
9 | |||
10 | class FunctionWithTimeout<Type> { | ||
11 | val Function0<Type> function; | ||
12 | |||
13 | new(Function0<Type> function) { | ||
14 | this.function = function | ||
15 | } | ||
16 | |||
17 | def execute(long millisecs) { | ||
18 | if(millisecs>0) { | ||
19 | val executor = Executors.newCachedThreadPool(); | ||
20 | val task = new Callable<Type>() { | ||
21 | override Type call() { function.apply } | ||
22 | }; | ||
23 | val future = executor.submit(task); | ||
24 | try { | ||
25 | val result = future.get(millisecs, TimeUnit.MILLISECONDS); | ||
26 | return result | ||
27 | } catch (TimeoutException ex) { | ||
28 | // handle the timeout | ||
29 | } catch (InterruptedException e) { | ||
30 | // handle the interrupts | ||
31 | } catch (ExecutionException e) { | ||
32 | // handle other exceptions | ||
33 | } finally { | ||
34 | future.cancel(true); // may or may not desire this | ||
35 | } | ||
36 | return null | ||
37 | } | ||
38 | else return function.apply | ||
39 | } | ||
40 | } \ No newline at end of file | ||