001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tctest.runner;
006:
007: import com.tc.net.proxy.TCPProxy;
008: import com.tc.object.config.DSOClientConfigHelper;
009: import com.tc.objectserver.control.ServerControl;
010: import com.tc.simulator.app.ApplicationConfig;
011: import com.tc.simulator.app.ApplicationConfigBuilder;
012: import com.tc.simulator.app.GlobalIdGenerator;
013:
014: import java.util.HashMap;
015: import java.util.Map;
016:
017: public class TransparentAppConfig implements ApplicationConfig,
018: ApplicationConfigBuilder {
019: public static final String adapterMapKey = "adapterMap";
020: public static final String PROXY_CONNECT_MGR = "PROXY_CONNECT_MGR";
021:
022: private final String applicationClassname;
023: private final GlobalIdGenerator idGenerator;
024: private final Map extraConfigAttributes = new HashMap();
025: private final ServerControl serverControl;
026: private ServerControl[] serverControls;
027: private TCPProxy[] proxies;
028: private int intensity;
029: private int clientCount;
030: private int applicationInstancePerClientCount = 1;
031: private int validatorCount;
032: private int adaptedMutatorCount;
033: private int adaptedValidatorCount;
034:
035: public TransparentAppConfig(String applicationClassname,
036: GlobalIdGenerator idGenerator, int clientCount,
037: int intensity, ServerControl[] serverControls,
038: TCPProxy[] proxies) {
039: this (applicationClassname, idGenerator, clientCount, intensity,
040: null, 0, 0, 0);
041: this .serverControls = serverControls;
042: this .proxies = proxies;
043: }
044:
045: public TransparentAppConfig(String applicationClassname,
046: GlobalIdGenerator idGenerator, int clientCount,
047: int intensity, ServerControl serverControl) {
048: this (applicationClassname, idGenerator, clientCount, intensity,
049: serverControl, 0, 0, 0);
050: }
051:
052: public TransparentAppConfig(String applicationClassname,
053: GlobalIdGenerator idGenerator, int clientCount,
054: int intensity, ServerControl serverControl,
055: int validatorCount, int adaptedMutatorCount,
056: int adaptedValidatorCount) {
057: this .applicationClassname = applicationClassname;
058: this .idGenerator = idGenerator;
059: if (clientCount < 1)
060: throw new AssertionError(
061: "Client count must be greater than 0");
062: this .clientCount = clientCount;
063: this .intensity = intensity;
064: this .serverControl = serverControl;
065: this .validatorCount = validatorCount;
066: this .adaptedMutatorCount = adaptedMutatorCount;
067: isLessThanOrEqualTo(adaptedMutatorCount, clientCount,
068: "adaptedMutatorCount");
069: this .adaptedValidatorCount = adaptedValidatorCount;
070: isLessThanOrEqualTo(adaptedValidatorCount, validatorCount,
071: "adaptedValidatorCount");
072: }
073:
074: public int getAdaptedMutatorCount() {
075: return adaptedMutatorCount;
076: }
077:
078: public int getAdaptedValidatorCount() {
079: return adaptedValidatorCount;
080: }
081:
082: public void setAttribute(String key, String value) {
083: extraConfigAttributes.put(key, value);
084: }
085:
086: public void setAttribute(String key, Object value) {
087: extraConfigAttributes.put(key, value);
088: }
089:
090: public String getAttribute(String key) {
091: return (String) extraConfigAttributes.get(key);
092: }
093:
094: public Object getAttributeObject(String key) {
095: return extraConfigAttributes.get(key);
096: }
097:
098: public int nextGlobalId() {
099: return (int) idGenerator.nextId();
100: }
101:
102: public int getGlobalParticipantCount() {
103: return this .clientCount
104: * this .applicationInstancePerClientCount;
105: }
106:
107: public TransparentAppConfig setApplicationInstancePerClientCount(
108: int applicationInstanceCount) {
109: this .applicationInstancePerClientCount = applicationInstanceCount;
110: return this ;
111: }
112:
113: public int getApplicationInstancePerClientCount() {
114: return this .applicationInstancePerClientCount;
115: }
116:
117: public int getClientCount() {
118: return this .clientCount;
119: }
120:
121: public TransparentAppConfig setClientCount(int i) {
122: this .clientCount = i;
123: return this ;
124: }
125:
126: public int getIntensity() {
127: return this .intensity;
128: }
129:
130: public TransparentAppConfig setIntensity(int i) {
131: this .intensity = i;
132: return this ;
133: }
134:
135: public String getApplicationClassname() {
136: return this .applicationClassname;
137: }
138:
139: public int getGlobalValidatorCount() {
140: return (clientCount + validatorCount)
141: * applicationInstancePerClientCount;
142: }
143:
144: public int getValidatorCount() {
145: return this .validatorCount;
146: }
147:
148: public TransparentAppConfig setValidatorCount(int count) {
149: validatorCount = count;
150: return this ;
151: }
152:
153: public TransparentAppConfig setAdaptedMutatorCount(int count) {
154: adaptedMutatorCount = count;
155: isLessThanOrEqualTo(adaptedMutatorCount, clientCount,
156: "adaptedMutatorCount");
157: return this ;
158: }
159:
160: public TransparentAppConfig setAdaptedValidatorCount(int count) {
161: adaptedValidatorCount = count;
162: isLessThanOrEqualTo(adaptedValidatorCount, validatorCount,
163: "adaptedValidatorCount");
164: return this ;
165: }
166:
167: private void isLessThanOrEqualTo(int a, int b, String description) {
168: if (a > b) {
169: throw new AssertionError(description + " is too big!");
170: }
171: }
172:
173: // ApplicationConfigBuilder interface...
174:
175: public void visitClassLoaderConfig(DSOClientConfigHelper config) {
176: return;
177: }
178:
179: public ApplicationConfig newApplicationConfig() {
180: return this ;
181: }
182:
183: public ApplicationConfig copy() {
184: throw new AssertionError();
185: }
186:
187: public ServerControl getServerControl() {
188: return serverControl;
189: }
190:
191: public ServerControl[] getServerControls() {
192: return serverControls;
193: }
194:
195: public TCPProxy[] getProxies() {
196: return proxies;
197: }
198: }
|