diff options
author | 2019-10-25 04:15:39 -0400 | |
---|---|---|
committer | 2019-10-25 04:15:39 -0400 | |
commit | 25a4b1b53add70e268c3083682f8a3508c618ec2 (patch) | |
tree | 6d46e62be49cfe6c5640e2e9af80aae90da6a212 /Solvers/Alloy-Solver2/hu.bme.mit.inf.dlsreasoner.alloy.reasoner/unused/FunctionWithTimeout.xtend_ | |
parent | mid-measurement push (diff) | |
download | VIATRA-Generator-25a4b1b53add70e268c3083682f8a3508c618ec2.tar.gz VIATRA-Generator-25a4b1b53add70e268c3083682f8a3508c618ec2.tar.zst VIATRA-Generator-25a4b1b53add70e268c3083682f8a3508c618ec2.zip |
VAMPIRE: post-submission push
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, 40 insertions, 0 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_ new file mode 100644 index 00000000..4f001c72 --- /dev/null +++ b/Solvers/Alloy-Solver2/hu.bme.mit.inf.dlsreasoner.alloy.reasoner/unused/FunctionWithTimeout.xtend_ | |||
@@ -0,0 +1,40 @@ | |||
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 | ||