01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tcsimulator;
05:
06: import com.tc.simulator.app.Application;
07: import com.tc.simulator.app.ApplicationConfig;
08: import com.tc.simulator.listener.ListenerProvider;
09:
10: public class SimpleApplication implements Application {
11:
12: private final ApplicationConfig cfg;
13: private final ListenerProvider listenerProvider;
14: private final String appId;
15:
16: public SimpleApplication(String appId, ApplicationConfig cfg,
17: ListenerProvider listenerProvider) {
18: this .appId = appId;
19: this .cfg = cfg;
20: this .listenerProvider = listenerProvider;
21: }
22:
23: public String getApplicationId() {
24: return this .appId;
25: }
26:
27: public void run() {
28: boolean result = false;
29:
30: try {
31: try {
32: Thread.sleep(Long.parseLong(this .cfg
33: .getAttribute("sleepInterval")));
34: } catch (InterruptedException e) {
35: e.printStackTrace();
36: }
37: if (Boolean.getBoolean(this .cfg
38: .getAttribute("throwException"))) {
39: throw new RuntimeException("I was told to do it!");
40: }
41: result = true;
42: } finally {
43: listenerProvider.getResultsListener().notifyResult(
44: Boolean.valueOf(result));
45: }
46: }
47:
48: public boolean interpretResult(Object o) {
49: return (o instanceof Boolean) && ((Boolean) o).booleanValue();
50: }
51:
52: }
|