4 import java.io.Serializable;
5 import java.util.ArrayList;
9 * Class representing a computing nodes cluster
10 * @author Sébastien Miquée
13 public class Cluster implements Serializable
15 private static final long serialVersionUID = 1L;
19 private ArrayList<GNode> nodes ;
25 * Default constructor.
31 nodes = new ArrayList<GNode>() ;
39 * @param _nb The amount of computing nodes in the cluster
41 public Cluster( int _nb )
45 nodes = new ArrayList<GNode>() ;
50 for( int i = 0 ; i < nb_node ; i++ )
52 nodes.add( new GNode() ) ;
59 * @param _nb The amount of computing nodes in the cluster
60 * @param _name Cluster's name
62 public Cluster( int _nb, String _name )
66 nodes = new ArrayList<GNode>() ;
70 for( int i = 0 ; i < nb_node ; i++ )
72 nodes.add( new GNode() ) ;
78 * Set the name of the cluster.
79 * @param _name Cluster's name
81 public void setName( String _name )
88 * Adding a computing node to the cluster.
89 * @param _n Node to be add
91 public void addGNode( GNode _n )
93 _n.setInCluster( true ) ;
101 * Return the list of computing nodes which are in the cluster.
102 * @return The list of nodes
104 public ArrayList<GNode> getGNodes()
111 * Return cluster's name.
112 * @return Cluster's name
114 public String getName()
121 * Return the amount of computing nodes in the cluster.
122 * @return The amount of nodes
124 public int getNbGNode()
131 * Set the site in which the cluster is.
132 * @param _site Site's name
134 public void setSite( String _site )
141 * Return the site's name in which the cluster is.
142 * @return The site's name
144 public String getSite()
151 * Test if a computing node is in the cluster.
152 * @param _g The node to be tested
153 * @return True is _g is in, False else
155 public boolean isIn( GNode _g )
159 if( nodes.contains( _g ) )
169 * Initialization of indice variable.
171 public void initIndice()
178 * Return the next computing node in the cluster,
179 * according to the indice variable.
180 * @return The next node in the cluster
182 public GNode nextGNode()
186 if( indice < nb_node )
188 ret = nodes.get( indice ) ;
197 * Remove a failed node from the cluster.
198 * @param _dead The failed node
200 public void removeGNode( GNode _dead )
202 if( _dead != null && _dead.getCluster().equals( name ) && _dead.getSite().equals( site ) )
204 for( int i = 0 ; i < nodes.size() ; i++ )
206 if( _dead.getId() == nodes.get( i ).getId() )
220 /** La programmation est un art, respectons ceux qui la pratiquent !! **/