*/
public void addGNode( GNode _n )
{
- if( _n != null )
+ if( _n != null && _n.getClusterName().equalsIgnoreCase( name ) )
{
_n.setInCluster( true ) ;
nodes.add( _n ) ;
}
+ /**
+ * Return the list of free computing nodes which are in the cluster.
+ * @return The list of free nodes
+ */
+ public ArrayList<GNode> getFreeGNodes()
+ {
+ return freenodes ;
+ }
+
+
/**
* Return cluster's name.
* @return Cluster's name
/**
- * Test if a computing node is in the cluster.
+ * Test if a computing node is in the cluster, and return its position (if
+ * it exists).
* @param _g The node to be tested
* @return The position of the node
*/
{
pos = i ;
break ;
- }
-
+ }
}
}
return pos ;
}
+
+ /**
+ * Test if a computing node is in the cluster, and return it (if
+ * it exists).
+ * @param _g The node to be tested
+ * @return The position of the node
+ */
+ public GNode exists( GNode _g )
+ {
+ if( _g != null )
+ {
+ for( int i = 0 ; i < nodes.size() ; i ++ )
+ {
+ if( nodes.get( i ).getId() == _g.getId() )
+ {
+ return nodes.get( i ) ;
+ }
+ }
+ }
+
+ return null ;
+ }
+
/**
* Return the next available computing node in the cluster.
* @return The next node in the cluster
{
if( _dead != null )
{
- if( _dead.getCluster().equals( name ) && _dead.getSite().equals( site ) )
+ if( _dead.getClusterName().equalsIgnoreCase( name )
+ && _dead.getSiteName().equalsIgnoreCase( site ) )
{
int i = 0 ;
for( i = 0 ; i < nodes.size() ; i++ )
}
}
+
+ /**
+ * Replace a node in the cluster (in case of a reconnection for example).
+ * @param _g The node to be replaced
+ */
+ public void replaceGNode( GNode _g )
+ {
+ if( _g != null )
+ {
+ removeGNode( _g ) ;
+ addGNode( _g ) ;
+ }
+ }
+
+
+ /**
+ * Search and return the better (most powerful) available node
+ * of the cluster.
+ * @return The best available node
+ */
+ public GNode getBetterFreeGNode()
+ {
+ GNode ret = null ;
+
+ if( freenodes.size() > 0 )
+ {
+ ret = freenodes.get( 0 ) ;
+ }
+
+ for( int i = 1 ; i < freenodes.size() ; i++ )
+ {
+ if( freenodes.get( i ).getPower() > ret.getPower() )
+ {
+ ret = freenodes.get( i ) ;
+ }
+ }
+
+ return ret ;
+ }
+
+
+ /**
+ * Construct and return a copy of the current Cluster.
+ * @return A copy of the cluster
+ */
+ public Cluster clone()
+ {
+ Cluster copy = new Cluster() ;
+
+ copy.setName( name ) ;
+ copy.setSite( site ) ;
+
+ for( int i = 0 ; i < nodes.size() ; i++ )
+ {
+ GNode newgn = (GNode) nodes.get( i ).clone() ;
+ newgn.setCluster( copy ) ;
+ copy.addGNode( newgn ) ;
+ }
+
+ return copy ;
+ }
+
}
/** La programmation est un art, respectons ceux qui la pratiquent !! **/