1 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 appId; 15 16 public SimpleApplication(String appId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 17 this.appId = appId; 18 this.cfg = cfg; 19 this.listenerProvider = listenerProvider; 20 } 21 22 public String 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 e) { 33 e.printStackTrace(); 34 } 35 if (Boolean.getBoolean(this.cfg.getAttribute("throwException"))) { throw new RuntimeException ( 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 o) { 44 return (o instanceof Boolean ) && ((Boolean ) o).booleanValue(); 45 } 46 47 } | Popular Tags |