001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tcsimulator;
005:
006: import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
007:
008: import com.tc.exception.TCRuntimeException;
009: import com.tc.object.config.ConfigVisitor;
010: import com.tc.object.config.DSOApplicationConfig;
011: import com.tc.simulator.app.ApplicationBuilder;
012: import com.tc.simulator.app.DSOApplicationBuilder;
013: import com.tc.simulator.app.ErrorContext;
014: import com.tc.simulator.app.GlobalIdGenerator;
015: import com.tc.simulator.container.Container;
016: import com.tc.simulator.container.ContainerConfig;
017: import com.tc.simulator.container.ContainerStateFactory;
018: import com.tc.simulator.control.Control;
019: import com.tc.simulator.crasher.ControlProvider;
020: import com.tc.simulator.listener.ResultsListener;
021: import com.tcsimulator.container.ContainerStateFactoryObject;
022:
023: public class ContainerBuilder implements Runnable, ResultsListener {
024:
025: private static final LinkedQueue statsOutputQueue = new LinkedQueue();
026:
027: private final TestSpec testSpec;
028: private final String vmName;
029:
030: public ContainerBuilder(String vmName) {
031: this .vmName = vmName;
032: testSpec = new TestSpec();
033: }
034:
035: public static void visitDSOApplicationConfig(ConfigVisitor visitor,
036: DSOApplicationConfig cfg) {
037: cfg.addRoot("testSpec", ContainerBuilder.class.getName()
038: + ".testSpec");
039: cfg.addIncludePattern(ContainerBuilder.class.getName());
040: cfg.addWriteAutolock("* " + ContainerBuilder.class.getName()
041: + ".*(..)");
042: visitor.visitDSOApplicationConfig(cfg,
043: ControlProviderImpl.class);
044: visitor.visitDSOApplicationConfig(cfg, ControlImpl.class);
045: visitor.visitDSOApplicationConfig(cfg,
046: DistributedGlobalIdGenerator.class);
047: visitor.visitDSOApplicationConfig(cfg,
048: ContainerStateFactoryObject.class);
049: }
050:
051: private void println(Object msg) {
052: System.out.println("ContainerBuilder: " + msg);
053: }
054:
055: public void run() {
056: ContainerStateFactory containerStateFactory;
057: Control control;
058: GlobalIdGenerator globalIdGenerator;
059: ApplicationBuilder appBuilder;
060:
061: try {
062: containerStateFactory = new ContainerStateFactoryObject(
063: statsOutputQueue);
064: globalIdGenerator = new DistributedGlobalIdGenerator();
065: ControlProvider provider = new ControlProviderImpl();
066: control = provider.getOrCreateControlByName(getClass()
067: .getName(), this .testSpec.getGlobalVmCount());
068: appBuilder = new DSOApplicationBuilder(testSpec
069: .getTestConfig(), Thread.currentThread()
070: .getContextClassLoader());
071: } catch (Throwable t) {
072: throw new TCRuntimeException(t);
073: }
074: Container container = new Container(
075: new ContainerConfigObject(), containerStateFactory,
076: globalIdGenerator, control, this , appBuilder);
077: container.run();
078: }
079:
080: public static void main(String[] args) throws Exception {
081: String vmName = args[0];
082: new ContainerBuilder(vmName).run();
083: }
084:
085: private final class ContainerConfigObject implements
086: ContainerConfig {
087:
088: public int getApplicationInstanceCount() {
089: synchronized (testSpec) {
090: return testSpec.getContainerSpecFor(vmName)
091: .getExecutionCount();
092: }
093: }
094:
095: public long getContainerStartTimeout() {
096: return 5 * 60 * 1000;
097: }
098:
099: public long getApplicationStartTimeout() {
100: return 5 * 60 * 1000;
101: }
102:
103: public long getApplicationExecutionTimeout() {
104: synchronized (testSpec) {
105: return testSpec.getAppExecutionTimeout();
106: }
107: }
108:
109: public boolean dumpErrors() {
110: return true;
111: }
112:
113: public boolean dumpOutput() {
114: return true;
115: }
116:
117: public boolean aggregate() {
118: return false;
119: }
120:
121: public boolean stream() {
122: return false;
123: }
124:
125: public boolean isMaster() {
126: return false;
127: }
128:
129: }
130:
131: /*********************************************************************************************************************
132: * ResultsListener interface
133: */
134:
135: public void setGlobalId(long globalId) {
136: return;
137: }
138:
139: public void notifyStartTimeout() {
140: println("Start timeout!");
141: Thread.dumpStack();
142: }
143:
144: public void notifyExecutionTimeout() {
145: println("Execution timeout!");
146: Thread.dumpStack();
147: }
148:
149: public void notifyError(ErrorContext ectxt) {
150: ectxt.dump(System.err);
151: }
152:
153: public void notifyResult(Object result) {
154: println("Result: " + result);
155: }
156: }
|