KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ve > luz > ica > jackass > daemon > SingleHostNodeDeployerManager


1 /*
2  * Copyright (c) 2003 by The Jackass Team
3  * Licensed under the Open Software License version 2.0
4  */

5 package ve.luz.ica.jackass.daemon;
6
7 import java.util.HashMap JavaDoc;
8 import java.util.Map JavaDoc;
9 import java.util.Iterator JavaDoc;
10
11 import ve.luz.ica.jackass.deploy.daemon.NodeDeployer;
12
13 /**
14  * This provides a NodeDeployerManager implementation suitable to nonclustered environments.
15  * This is, a String (that identifies an item) is associated with only one NodeDeployer.
16  * @author Carlos Arévalo, Guido Urdaneta
17  */

18 public final class SingleHostNodeDeployerManager implements NodeDeployerManager
19 {
20     private static final String JavaDoc NULL_ARGS = "Null Arguments";
21     private static final NullPointerException JavaDoc NULL_ARGS_EXCEPTION = new NullPointerException JavaDoc(NULL_ARGS);
22
23     private Map JavaDoc nodeDeployerMap; //Map<String, NodeDeployer>
24

25     /**
26      * Constructs a SingleHostNodeDeployerManager.
27      */

28     public SingleHostNodeDeployerManager()
29     {
30         nodeDeployerMap = new HashMap JavaDoc();
31     }
32
33     /**
34      * @see ve.luz.ica.jackass.daemon.NodeDeployerManager#getNodeDeployers(String)
35      */

36     public NodeDeployer[] getNodeDeployers(String JavaDoc itemName)
37     {
38         NodeDeployer nd = getNodeDeployer(itemName);
39         return new NodeDeployer[] {nd};
40     }
41
42     /**
43      * @see ve.luz.ica.jackass.daemon.NodeDeployerManager#addNodeDeployer(String, NodeDeployer)
44      */

45     public void addNodeDeployer(String JavaDoc itemName, NodeDeployer nodeDeployer)
46     {
47         if (itemName == null || nodeDeployer == null)
48         {
49             throw NULL_ARGS_EXCEPTION;
50         }
51
52         nodeDeployerMap.put(itemName, nodeDeployer);
53     }
54
55     /**
56      * @see ve.luz.ica.jackass.daemon.NodeDeployerManager#removeNodeDeployer(String, NodeDeployer)
57      */

58     public void removeNodeDeployer(String JavaDoc itemName, NodeDeployer nodeDeployer)
59     {
60         NodeDeployer nd = getNodeDeployer(itemName);
61         if (nd.equals(nodeDeployer))
62         {
63             nodeDeployerMap.remove(itemName);
64         }
65     }
66
67     /**
68      * @see ve.luz.ica.jackass.daemon.NodeDeployerManager#removeNodeDeployer(NodeDeployer)
69      */

70     public void removeNodeDeployer(NodeDeployer nodeDeployer)
71     {
72         for (Iterator JavaDoc i = nodeDeployerMap.values().iterator(); i.hasNext();)
73         {
74             NodeDeployer nd = (NodeDeployer) i.next();
75             if (nd.equals(nodeDeployer))
76             {
77                 i.remove();
78             }
79         }
80     }
81
82     /**
83      * @see ve.luz.ica.jackass.daemon.NodeDeployerManager#removeItem(String)
84      */

85     public void removeItem(String JavaDoc itemName)
86     {
87         nodeDeployerMap.remove(itemName);
88     }
89
90     /**
91      * Removes a node deployer from the map
92      * @param itemName the name of the item to be removed
93      */

94     public void removeNodeDeployer(String JavaDoc itemName)
95     {
96         if (itemName == null)
97         {
98             throw NULL_ARGS_EXCEPTION;
99         }
100
101         nodeDeployerMap.remove(itemName);
102     }
103
104     /**
105      * Gets the only node deployer associated with a specified item.
106      * @param itemName the item name.
107      * @return A NodeDeployer if the item exists, null if the item does not exist.
108      */

109     private NodeDeployer getNodeDeployer(String JavaDoc itemName)
110     {
111         if (itemName == null)
112         {
113             throw NULL_ARGS_EXCEPTION;
114         }
115         NodeDeployer nodeDeployer = (NodeDeployer) nodeDeployerMap.get(itemName);
116         if (nodeDeployer == null)
117         {
118             return null;
119         }
120         return nodeDeployer;
121     }
122 }
123
Popular Tags