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;
18 private ArrayList<GNode> nodes ;
19 private ArrayList<GNode> freenodes ;
21 private int moreNode ;
25 * Default constructor.
30 nodes = new ArrayList<GNode>() ;
31 freenodes = new ArrayList<GNode>() ;
38 * Set the name of the cluster.
39 * @param _name Cluster's name
41 public void setName( String _name )
48 * Adding a computing node to the cluster.
49 * @param _n Node to be add
51 public void addGNode( GNode _n )
55 _n.setInCluster( true ) ;
58 if( ! _n.getMapped() )
67 * Return the list of computing nodes which are in the cluster.
68 * @return The list of nodes
70 public ArrayList<GNode> getGNodes()
77 * Return cluster's name.
78 * @return Cluster's name
80 public String getName()
87 * Return the amount of computing nodes in the cluster.
88 * @return The amount of nodes
90 public int getNbGNode()
97 * Set the site in which the cluster is.
98 * @param _site Site's name
100 public void setSite( String _site )
107 * Return the site's name in which the cluster is.
108 * @return The site's name
110 public String getSite()
117 * Test if a computing node is in the cluster.
118 * @param _g The node to be tested
119 * @return The position of the node
121 public int isIn( GNode _g )
127 for( int i = 0 ; i < nodes.size() ; i ++ )
129 if( nodes.get( i ).getId() == _g.getId() )
142 * Return the next available computing node in the cluster.
143 * @return The next node in the cluster
145 public GNode nextGNode()
149 if( freenodes.size() > 0 )
151 ret = freenodes.get( 0 ) ;
159 * Return the next available computing node in the cluster,
160 * according to the moreNode iterator.
161 * @return The next node in the cluster
163 public GNode moreGNode()
167 if( freenodes.size() > 0 )
169 if( moreNode >= freenodes.size() )
174 ret = freenodes.get( moreNode ) ;
183 * Remove a failed node from the cluster.
184 * @param _dead The failed node
186 public void removeGNode( GNode _dead )
190 if( _dead.getCluster().equals( name ) && _dead.getSite().equals( site ) )
193 for( i = 0 ; i < nodes.size() ; i++ )
195 if( _dead.getId() == nodes.get( i ).getId() )
200 for( j = 0 ; j < freenodes.size() ; j++ )
202 if( freenodes.get(j).getId() == _dead.getId() )
204 freenodes.remove( j ) ;
213 if( i > nodes.size() )
215 System.err.println( "(Cluster) The GNode was not found in the list!" );
218 System.err.println( "(Cluster) The GNode to be deleted is not mine!" ) ;
221 System.err.println( "(Cluster) The GNode to be deleted is null!" ) ;
227 * Set the mapped status of a node of the cluster.
228 * @param _g The mapped node
229 * @param _status The status of the node
231 public void setGNodeStatus( GNode _g, boolean _status )
235 for( int i = 0 ; i < nodes.size() ; i++ )
237 if( nodes.get( i ).getId() == _g.getId() )
239 nodes.get( i ).setMapped( _status ) ;
243 for( int j = 0 ; j < freenodes.size() ; j++ )
245 if( freenodes.get(j).getId() == nodes.get(i).getId() )
247 freenodes.remove( j ) ;
253 if( ! freenodes.contains( nodes.get( i ) ) )
254 freenodes.add( nodes.get( i ) ) ;
263 * Return the amount of available free nodes in the cluster.
264 * @return The amount of free nodes
266 public int getNbFreeNodes()
268 return freenodes.size() ;
273 * Compute and return the real available computing power of the cluster,
274 * including the heterogeneity degree of the platform.
275 * @return The real available computing power
277 public double getAvailablePower()
281 /** If there is some available nodes **/
282 if( freenodes.size() > 0 )
284 for( int i = 0 ; i < freenodes.size() ; i++ )
286 ret += freenodes.get( i ).getPower() ;
295 * Initialization of computing nodes in this cluster. Set all
296 * of these nodes to be not mapped on.
298 public void initGNodes()
300 /** Initialization of local nodes **/
301 /** and reconstruction of the freenodes list **/
303 freenodes = new ArrayList<GNode>() ;
305 for( int i = 0 ; i < nodes.size() ; i++ )
307 nodes.get( i ).setMapped( false ) ;
309 freenodes.add( nodes.get( i ) ) ;
315 /** La programmation est un art, respectons ceux qui la pratiquent !! **/