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.tcsimulator;
006:
007: import org.apache.commons.lang.builder.HashCodeBuilder;
008:
009: import com.tc.net.proxy.TCPProxy;
010: import com.tc.object.config.ConfigVisitor;
011: import com.tc.object.config.DSOApplicationConfig;
012: import com.tc.objectserver.control.ServerControl;
013: import com.tc.simulator.app.ApplicationConfig;
014:
015: import java.util.HashMap;
016: import java.util.Map;
017:
018: public class ApplicationConfigImpl implements ApplicationConfig {
019:
020: private final String applicatonClassname;
021: private final int intensity;
022: private final int globalParticipantCount;
023: private final Map attributes;
024: private int hashCode;
025: private final int validatorCount;
026:
027: public static void visitDSOApplicationConfig(ConfigVisitor visitor,
028: DSOApplicationConfig config) {
029: String classname = ApplicationConfigImpl.class.getName();
030: config.addIncludePattern(classname);
031: config.addWriteAutolock("* " + classname + ".*(..)");
032: }
033:
034: public ApplicationConfigImpl(String applicatonClassname,
035: int intensity, int globalParticipantCount) {
036: this (applicatonClassname, intensity, globalParticipantCount, 0);
037: }
038:
039: public ApplicationConfigImpl(String applicatonClassname,
040: int intensity, int globalParticipantCount,
041: int validatorCount) {
042: this .applicatonClassname = applicatonClassname;
043: this .intensity = intensity;
044: this .globalParticipantCount = globalParticipantCount;
045: this .validatorCount = validatorCount;
046: attributes = new HashMap();
047: hashCode = new HashCodeBuilder(17, 37).append(
048: this .applicatonClassname).append(intensity).append(
049: globalParticipantCount).append(attributes).toHashCode();
050: }
051:
052: public String getApplicationClassname() {
053: return this .applicatonClassname;
054: }
055:
056: public int getIntensity() {
057: return intensity;
058: }
059:
060: public int getGlobalParticipantCount() {
061: return this .globalParticipantCount;
062: }
063:
064: public int getValidatorCount() {
065: return validatorCount;
066: }
067:
068: public boolean equals(ApplicationConfig appconfig) {
069: return applicatonClassname.equals(appconfig
070: .getApplicationClassname())
071: && intensity == appconfig.getIntensity()
072: && globalParticipantCount == appconfig
073: .getGlobalParticipantCount();
074: }
075:
076: public int hashCode() {
077: return hashCode;
078: }
079:
080: public void setAttribute(String key, String value) {
081: attributes.put(key, value);
082: }
083:
084: public String getAttribute(String key) {
085: return (String) attributes.get(key);
086: }
087:
088: public ApplicationConfig copy() {
089: return new ApplicationConfigImpl(applicatonClassname,
090: intensity, globalParticipantCount, validatorCount);
091: }
092:
093: public ServerControl getServerControl() {
094: throw new UnsupportedOperationException(
095: "not implemented, should not be used");
096: }
097:
098: public int getGlobalValidatorCount() {
099: throw new AssertionError("This method needs to be implemented");
100: }
101:
102: public TCPProxy[] getProxies() {
103: throw new UnsupportedOperationException(
104: "not implemented, should not be used");
105: }
106:
107: public ServerControl[] getServerControls() {
108: throw new UnsupportedOperationException(
109: "not implemented, should not be used");
110: }
111:
112: public Object getAttributeObject(String key) {
113: throw new UnsupportedOperationException(
114: "not implemented, should not be used");
115: }
116: }
|