1 4 package com.tctest.runner; 5 6 import com.tc.object.config.ConfigVisitor; 7 import com.tc.object.config.DSOApplicationConfig; 8 import com.tc.object.config.DSOClientConfigHelper; 9 import com.tc.object.config.TransparencyClassSpec; 10 import com.tc.simulator.app.Application; 11 import com.tc.simulator.app.ApplicationConfig; 12 import com.tc.simulator.app.ErrorContext; 13 import com.tc.simulator.listener.ListenerProvider; 14 15 import java.util.HashSet ; 16 import java.util.Set ; 17 18 public abstract class AbstractTransparentApp implements Application { 19 20 private TransparentAppCoordinator coordinator; 21 private int intensity; 22 private ListenerProvider listenerProvider; 23 private Set appIds = new HashSet (); 24 25 public AbstractTransparentApp() { 26 } 28 29 public AbstractTransparentApp(String appId, ApplicationConfig config, ListenerProvider listenerProvider) { 30 synchronized (appIds) { 31 if (!appIds.add(appId)) { throw new AssertionError ("You've created me with the same global ID as someone else: " 32 + appId); } 33 } 34 this.listenerProvider = listenerProvider; 35 this.intensity = config.getIntensity(); 36 this.coordinator = new TransparentAppCoordinator(appId, config.getGlobalParticipantCount()); 37 } 38 39 protected int getIntensity() { 40 return this.intensity; 41 } 42 43 protected int getParticipantCount() { 44 return coordinator.getParticipantCount(); 45 } 46 47 public String getApplicationId() { 48 return coordinator.getGlobalId(); 49 } 50 51 protected void moveToStage(int stage) { 52 coordinator.moveToStage(stage); 53 } 54 55 protected void moveToStageAndWait(int stage) { 56 coordinator.moveToStageAndWait(stage); 57 } 58 59 protected void notifyError(String msg) { 60 listenerProvider.getResultsListener().notifyError(new ErrorContext(msg, new Error ())); 61 } 62 63 protected void notifyError(ErrorContext context) { 64 listenerProvider.getResultsListener().notifyError(context); 65 } 66 67 protected void notifyError(Throwable t) { 68 listenerProvider.getResultsListener().notifyError(new ErrorContext(t)); 69 } 70 71 public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) { 72 config.addIncludePattern(AbstractTransparentApp.class.getName()); 73 config.addRoot("AbstractTransparentAppAppIds", AbstractTransparentApp.class.getName() + ".appIds"); 74 config.addWriteAutolock("* " + AbstractTransparentApp.class.getName() + ".*(..)"); 75 76 TransparencyClassSpec spec = config.getOrCreateSpec(TransparentAppCoordinator.class.getName()); 77 spec.addRoot("participants", "participants"); 78 config.addWriteAutolock("* " + TransparentAppCoordinator.class.getName() + ".*(..)"); 79 } 80 81 public static void visitDSOApplicationConfig(ConfigVisitor visitor, DSOApplicationConfig config) { 82 config.addIncludePattern(AbstractTransparentApp.class.getName()); 83 config.addRoot("AbstractTransparentAppAppIds", AbstractTransparentApp.class.getName() + ".appIds"); 84 config.addWriteAutolock("* " + AbstractTransparentApp.class.getName() + ".*(..)"); 85 86 config.addIncludePattern(TransparentAppCoordinator.class.getName()); 87 config.addRoot("participants", TransparentAppCoordinator.class.getName() + ".participants"); 88 config.addWriteAutolock("* " + TransparentAppCoordinator.class.getName() + ".*(..)"); 89 } 90 91 public void notifyResult(Boolean result) { 92 this.listenerProvider.getResultsListener().notifyResult(result); 93 } 94 95 public boolean interpretResult(Object result) { 96 return result instanceof Boolean && ((Boolean ) result).booleanValue(); 97 } 98 } | Popular Tags |