1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.grinderscript.dotnet.scriptengine;
18
19 import grinderscript.net.core.IGrinderWorker;
20 import net.grinder.common.UncheckedGrinderException;
21 import net.grinder.scriptengine.ScriptEngineService.WorkerRunnable;
22 import net.grinder.scriptengine.ScriptExecutionException;
23 import net.grinder.util.Sleeper;
24
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 public class DotNetWorkerRunnable implements WorkerRunnable {
29
30 private final Logger logger = LoggerFactory
31 .getLogger(DotNetWorkerRunnable.class);
32
33 private IGrinderWorker underlying;
34
35 public DotNetWorkerRunnable(IGrinderWorker underlying)
36 throws DotNetScriptExecutionException {
37 logger.trace("ctor: Enter, underlying = {}", underlying);
38 this.underlying = underlying;
39 logger.trace("ctor: Exit");
40 }
41
42 @Override
43 public void run() throws ScriptExecutionException {
44 logger.trace("run: Enter");
45 try {
46 underlying.Run();
47 } catch (UncheckedGrinderException e) {
48 if ("Thread has been shut down".equals(e.getMessage())) {
49 throw e;
50 }
51 logger.info("run: Got an UncheckedGrinderException", e);
52 } catch (DotNetCheckedExceptionMarshall marshall) {
53 if (marshall.getCause() instanceof Sleeper.ShutdownException) {
54 throw new DotNetScriptExecutionException(
55 "Shutdown during sleep",
56 (Sleeper.ShutdownException) marshall.getCause());
57 }
58 }
59 logger.trace("run: Exit");
60 }
61
62 @Override
63 public void shutdown() throws ScriptExecutionException {
64 logger.trace("shutdown: Enter");
65 try {
66 underlying.Shutdown();
67 } finally {
68 underlying = null;
69 }
70 logger.trace("shutdown: Exit");
71 }
72
73 IGrinderWorker getUnderlying() {
74 return underlying;
75 }
76 }