From: <to...@us...> - 2007-03-03 20:02:31
|
Revision: 104 http://techne-dev.svn.sourceforge.net/techne-dev/?rev=104&view=rev Author: tonit Date: 2007-03-03 12:02:26 -0800 (Sat, 03 Mar 2007) Log Message: ----------- implemented dynamic provisioning Modified Paths: -------------- sandbox/rickles/org.digivitality.techne.core/src/org/digivitality/techne/core/ContainerFactory.java Added Paths: ----------- sandbox/rickles/org.digivitality.techne.core/src/org/digivitality/techne/core/util/ContainerState.java Modified: sandbox/rickles/org.digivitality.techne.core/src/org/digivitality/techne/core/ContainerFactory.java =================================================================== --- sandbox/rickles/org.digivitality.techne.core/src/org/digivitality/techne/core/ContainerFactory.java 2007-03-03 20:02:20 UTC (rev 103) +++ sandbox/rickles/org.digivitality.techne.core/src/org/digivitality/techne/core/ContainerFactory.java 2007-03-03 20:02:26 UTC (rev 104) @@ -2,13 +2,13 @@ import java.util.ArrayList; import java.util.List; -import org.xml.sax.*; -import org.xml.sax.helpers.*; -import javax.xml.parsers.*; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + import org.digivitality.techne.core.util.ConfigHandler; import org.digivitality.techne.core.util.container; -import org.digivitality.techne.core.util.containertype; +import org.xml.sax.XMLReader; public class ContainerFactory { @@ -18,6 +18,7 @@ private List containerInstances = new ArrayList(); private List containerTypes = new ArrayList(); private static ContainerFactory instance; + private boolean init = false; private ContainerFactory() { @@ -33,6 +34,7 @@ synchronized (ContainerFactory.class) { if (instance == null) { instance = new ContainerFactory(); + instance.init(); } } } @@ -40,38 +42,41 @@ return instance; } - public void init() { - if (quantity == 0) { - quantity = DEFAULT_QUANTITY; + private void init() { + if (!init) { + if (quantity == 0) { + quantity = DEFAULT_QUANTITY; + } + for (int i = 0; i < quantity; i++) { + containerInstances.add(new ContainerIntanceImpl()); + } + + // parse the config file + loadContainerPolicies(); + init = true; } - for (int i = 0; i < quantity; i++) { - containerInstances.add(new ContainerIntanceImpl()); - } - - // parse the config file - getContainerPolicies(); } - public void getContainerPolicies() { + public void loadContainerPolicies() { ConfigHandler ch = null; try { - SAXParserFactory factory = SAXParserFactory.newInstance( ); - SAXParser saxParser = factory.newSAXParser( ); - XMLReader parser = saxParser.getXMLReader( ); - ch = new ConfigHandler(); - parser.setContentHandler(ch); - parser.parse( "../conf/techne.xml" ); - + SAXParserFactory factory = SAXParserFactory.newInstance(); + SAXParser saxParser = factory.newSAXParser(); + XMLReader parser = saxParser.getXMLReader(); + ch = new ConfigHandler(); + parser.setContentHandler(ch); + parser.parse("../conf/techne.xml"); + } catch (Exception e) { e.printStackTrace(); } - container c = (container)ch.getModel(); - //containertype ct = (containertype)c.getContainerTypes().get(0); - containerTypes = c.getContainerTypes(); - System.out.println("Available container types: " + containerTypes.size()); + container c = (container) ch.getModel(); + // containertype ct = (containertype)c.getContainerTypes().get(0); + containerTypes = c.getContainerTypes(); + System.out.println("Available container types: " + containerTypes); } - + public void setQuantity(int parm) { this.quantity = parm; } @@ -83,7 +88,7 @@ public List getContainerInstances() { return containerInstances; } - + public List getContainerTypes() { return containerTypes; } Added: sandbox/rickles/org.digivitality.techne.core/src/org/digivitality/techne/core/util/ContainerState.java =================================================================== --- sandbox/rickles/org.digivitality.techne.core/src/org/digivitality/techne/core/util/ContainerState.java (rev 0) +++ sandbox/rickles/org.digivitality.techne.core/src/org/digivitality/techne/core/util/ContainerState.java 2007-03-03 20:02:26 UTC (rev 104) @@ -0,0 +1,55 @@ +package org.digivitality.techne.core.util; + +import java.util.HashSet; +import java.util.Set; +import java.util.Stack; + +/** + * Its basically the memory for the installed bundles at this moment. + * + * @author tmenzel + * + */ +public class ContainerState { + private String type; + private Set idset; + Stack bundles; + + public ContainerState(String initialType) { + type = initialType; + idset = new HashSet(); + bundles = new Stack(); + } + + public String getType() { + return type; + } + + public void addInstalled(long id, String newBundleURL) { + Long lo = new Long(id); + idset.add(lo); + bundles.add(newBundleURL); + } + + public Set getIds() { + return idset; + } + + public String toString() { + return "[type is " + type + "; installed bundles: " + idset + "]"; + } + + public Stack getInstalledBundles() { + return bundles; + } + + public void remove(long bundleId, String bundleURL) { + idset.remove(new Long(bundleId)); + bundles.remove(bundleURL); + } + + public void setType(String wantType) { + type = wantType; + + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |