KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tcsimulator > SimpleApplication


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tcsimulator;
5
6 import com.tc.simulator.app.Application;
7 import com.tc.simulator.app.ApplicationConfig;
8 import com.tc.simulator.listener.ListenerProvider;
9
10 public class SimpleApplication implements Application {
11
12   private final ApplicationConfig cfg;
13   private final ListenerProvider listenerProvider;
14   private final String JavaDoc appId;
15
16   public SimpleApplication(String JavaDoc appId, ApplicationConfig cfg, ListenerProvider listenerProvider) {
17     this.appId = appId;
18     this.cfg = cfg;
19     this.listenerProvider = listenerProvider;
20   }
21
22   public String JavaDoc getApplicationId() {
23     return this.appId;
24   }
25
26   public void run() {
27     boolean result = false;
28
29     try {
30       try {
31         Thread.sleep(Long.parseLong(this.cfg.getAttribute("sleepInterval")));
32       } catch (InterruptedException JavaDoc e) {
33         e.printStackTrace();
34       }
35       if (Boolean.getBoolean(this.cfg.getAttribute("throwException"))) { throw new RuntimeException JavaDoc(
36                                                                                                     "I was told to do it!"); }
37       result = true;
38     } finally {
39       listenerProvider.getResultsListener().notifyResult(Boolean.valueOf(result));
40     }
41   }
42
43   public boolean interpretResult(Object JavaDoc o) {
44     return (o instanceof Boolean JavaDoc) && ((Boolean JavaDoc) o).booleanValue();
45   }
46
47 }
Popular Tags