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.tctest.util;
05:
06: import com.tc.object.config.ConfigVisitor;
07: import com.tc.object.config.DSOClientConfigHelper;
08: import com.tc.object.config.TransparencyClassSpec;
09: import com.tc.simulator.app.ApplicationConfig;
10: import com.tc.simulator.listener.ListenerProvider;
11: import com.tctest.runner.AbstractTransparentApp;
12:
13: import java.util.concurrent.CyclicBarrier;
14:
15: public abstract class AbstractTransparentAppMultiplexer extends
16: AbstractTransparentApp {
17: private final CyclicBarrier myBarrier;
18:
19: public AbstractTransparentAppMultiplexer(String appId,
20: ApplicationConfig cfg, ListenerProvider listenerProvider) {
21: super (appId, cfg, listenerProvider);
22: myBarrier = new CyclicBarrier(getParticipantCount());
23: }
24:
25: public void run() {
26: try {
27: int index = myBarrier.await();
28: run(myBarrier, index);
29: } catch (Throwable t) {
30: notifyError(t);
31: }
32: }
33:
34: public abstract void run(CyclicBarrier barrier, int index)
35: throws Throwable;
36:
37: public static void visitL1DSOConfig(ConfigVisitor visitor,
38: DSOClientConfigHelper config) {
39: TransparencyClassSpec spec = config
40: .getOrCreateSpec(AbstractTransparentAppMultiplexer.class
41: .getName());
42:
43: DSOConfigUtil.addWriteAutolock(config, CyclicBarrier.class);
44: DSOConfigUtil.addRoot(spec, "myBarrier");
45: }
46: }
|