package edu.hawaii.ics.yucheng; import java.util.ArrayList; import java.util.Properties; /** * An immutable class that contains the configuration information for a cluster * of nodes and a catalog. They are parsed from the 'clustercfg' file, and works * specifically as the configuration for creating and droping tables on this * distributed system. * * @author Cheng Jade * @assignment ICS 421 Project * @date Mar 22, 2010 * @bugs None */ public class CreateOrDropConfiguration { final public ConfigurationNode catalog; final public int nodeNumber; final public ArrayList<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>(); /** * return a string with class data. */ @Override public String toString() { final StringBuilder builder = new StringBuilder(); builder.append("- catalog:\n" + this.catalog); builder.append("\n- node number: " + this.nodeNumber); builder.append("\n- relevant nodes:"); for (final ConfigurationNode node : this.nodes) builder.append("\n node: \n" + node); return builder.toString(); } /** * initialize a instance of this object */ public CreateOrDropConfiguration(final Properties properties, final ConfigurationNode catalog) throws ProgramException { this.catalog = catalog; try { this.nodeNumber = Integer.parseInt(properties.getProperty("numnodes")); for (int i = 1; i <= this.nodeNumber; i++) { final String name = "node" + i; this.nodes.add(new ConfigurationNode(properties, name)); } } catch (final Exception e) { throw new ProgramException("Invalid Configuration, " + e.getMessage()); } } }