001: /*
002: * <copyright>
003: *
004: * Copyright 2000-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.tools.csmart.experiment;
028:
029: import org.cougaar.tools.csmart.core.property.ModifiableConfigurableComponent;
030: import org.cougaar.tools.csmart.core.property.Property;
031: import org.cougaar.tools.csmart.ui.viewer.CSMART;
032: import org.cougaar.util.log.Logger;
033:
034: import java.io.IOException;
035: import java.io.ObjectInputStream;
036: import java.io.Serializable;
037: import java.util.ArrayList;
038: import java.util.List;
039:
040: /**
041: * Maintains information about a host and generates the
042: * host .ini file.
043: **/
044: public class ExperimentHost extends ModifiableConfigurableComponent
045: implements Serializable, HostComponent {
046: private static final long serialVersionUID = 9111998126122353108L;
047:
048: public static final String DEFAULT_HOST_NAME = "localhost";
049:
050: private List nodes = new ArrayList();
051: private int serverPort;
052: private int monitoringPort;
053: private transient Logger log;
054:
055: public ExperimentHost(String hostName) {
056: super (hostName);
057: createLogger();
058: }
059:
060: public boolean equals(Object o) {
061: if (this == o)
062: return true;
063: if (o instanceof ExperimentHost) {
064: return getShortName().equals(
065: ((ExperimentHost) o).getShortName());
066: } else {
067: return false;
068: }
069: }
070:
071: private void createLogger() {
072: log = CSMART.createLogger(this .getClass().getName());
073: }
074:
075: public void initProperties() {
076: addProperty("NodeNames", new ArrayList());
077: }
078:
079: private int getNodeCount() {
080: return nodes.size();
081: }
082:
083: public NodeComponent[] getNodes() {
084: return (NodeComponent[]) nodes
085: .toArray(new NodeComponent[getNodeCount()]);
086: }
087:
088: public NodeComponent addNode(NodeComponent node) {
089: Property prop = getProperty("NodeNames");
090: if (prop == null)
091: prop = addProperty("NodeNames", new ArrayList());
092: ArrayList names = (ArrayList) prop.getValue();
093: names.add(node.getShortName());
094: ExperimentNode sa = (ExperimentNode) node;
095: if (log.isDebugEnabled()) {
096: log.debug("ExperimentHost: " + getShortName()
097: + " added node: " + node.getShortName());
098: }
099: nodes.add(sa);
100: fireModification();
101: return sa;
102: }
103:
104: public NodeComponent getNode(int ix) {
105: return (NodeComponent) nodes.get(ix);
106: }
107:
108: public void removeNode(NodeComponent node) {
109: Property prop = getProperty("NodeNames");
110: if (prop != null) {
111: ArrayList names = (ArrayList) prop.getValue();
112: int index = names.indexOf(node.getShortName());
113: if (index != -1)
114: names.remove(node.getShortName());
115: }
116: if (log.isDebugEnabled()) {
117: log.debug("ExperimentHost: " + getShortName()
118: + " removed node: " + node.getShortName());
119: }
120: nodes.remove(node);
121: fireModification();
122: }
123:
124: public void dispose() {
125: nodes.clear();
126: fireModification();
127: }
128:
129: /**
130: * Get the port on which to contact the server on this host.
131: * @return the server port
132: */
133: public int getServerPort() {
134: return serverPort;
135: }
136:
137: /**
138: * Set the port on which to contact the server on this host.
139: * @param serverPort
140: */
141: public void setServerPort(int serverPort) {
142: this .serverPort = serverPort;
143: }
144:
145: /**
146: * Get the port on which to monitor nodes running on this host.
147: * @return the monitoring port
148: */
149: public int getMonitoringPort() {
150: return monitoringPort;
151: }
152:
153: /**
154: * Set the port on which to monitor nodes running on this host.
155: * @param monitoringPort on which to monitor nodes
156: */
157: public void setMonitoringPort(int monitoringPort) {
158: this .monitoringPort = monitoringPort;
159: }
160:
161: // FIXME: Add a copy method that takes avoids copying the NodeNames property
162:
163: private void readObject(ObjectInputStream ois) throws IOException,
164: ClassNotFoundException {
165: ois.defaultReadObject();
166: createLogger();
167: }
168:
169: }
|