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 for( int i = 0; i < nodes.size(); i ++ )
161 if( nodes.get( i ).getId() == _g.getId() )
170 * Initialization of indice variable.
172 public void initIndice()
179 * Return the next computing node in the cluster,
180 * according to the indice variable.
181 * @return The next node in the cluster
183 public GNode nextGNode()
187 if( indice < nb_node )
189 ret = nodes.get( indice ) ;
198 * Remove a failed node from the cluster.
199 * @param _dead The failed node
201 public void removeGNode( GNode _dead )
203 if( _dead != null && _dead.getCluster().equals( name ) && _dead.getSite().equals( site ) )
205 for( int i = 0 ; i < nodes.size() ; i++ )
207 if( _dead.getId() == nodes.get( i ).getId() )
221 /** La programmation est un art, respectons ceux qui la pratiquent !! **/