import java.io.InputStream;
import java.io.InputStreamReader;
import java.rmi.Naming;
+import java.util.ArrayList;
import java.util.Random;
-import java.util.Vector;
import and.Mapping.Algo;
import and.Mapping.GNode;
// attributes
public static SuperNodeListe Instance;
private Random r;
- @SuppressWarnings("unchecked")
- private Vector liste = null;
+ private ArrayList<Object> liste = null;
// constructors
- @SuppressWarnings("unchecked")
public SuperNodeListe() {
- liste = new Vector();
+ liste = new ArrayList<Object>() ;
r = new Random();
}
}
return Instance;
}
-
+
@SuppressWarnings("unchecked")
public synchronized SuperNodeListe clone() {
SuperNodeListe d = new SuperNodeListe();
// d.r = (Random) r.clone();
- d.liste = (Vector) liste.clone();
- return d;
+ d.liste = (ArrayList<Object>) liste.clone() ;
+ return d ;
}
// methods
// TODO change to have non-static list
// using a config file
// in order to discover new superNodes dynamicaly
- @SuppressWarnings("unchecked")
+
+ /* Sébastien Miquée -- ajout de la lecture du fichier de config **/
public void staticInitialization() {
String adr = "";
String home = System.getProperty("user.home");
br.close();
} catch (Exception e) {
- System.out.println(e.toString());
+ System.err.println(e.toString());
}
// String adr1 =
// donnees ds un fichier de conf
}
- @SuppressWarnings("unchecked")
- public Vector getListe() {
+
+ public ArrayList<Object> getListe() {
return liste;
}
if (index < 0) {
index = -index;
}
- return (SuperNodeData) liste.elementAt(index);
+ return (SuperNodeData) liste.get(index);
}
public SuperNodeData getSuperNodeData(int i) {
- return (SuperNodeData) liste.elementAt(i);
+ return (SuperNodeData) liste.get(i);
}
// if returns 0, there are no nodes at all
SuperNodeData return_d = null;
for (int i = 0; i < liste.size(); i++) {
- d = (SuperNodeData) liste.elementAt(i);
+ d = (SuperNodeData) liste.get(i);
if (d.getNbOfNodes() > max) {
max = d.getNbOfNodes();
- return_d = (SuperNodeData) liste.elementAt(i);
+ return_d = (SuperNodeData) liste.get(i);
}
}
return return_d;
}
public void addStub(int index, JaceSuperNodeInterface stub) {
- ((SuperNodeData) liste.elementAt(index)).setStub(stub);
+ ((SuperNodeData) liste.get(index)).setStub(stub);
}
- @SuppressWarnings("unchecked")
public void addStubOf(String snode, int port, JaceSuperNodeInterface stub) {
int is = -1;
is = existSuperNode(snode);
if (is != -1) {
- ((SuperNodeData) liste.elementAt(is)).setStub(stub);
+ ((SuperNodeData) liste.get(is)).setStub(stub);
} else {
- System.out.println("this superNode does not exist : " + snode);
- System.out.println("add the new SuperNode");
+ System.err.println("This superNode does not exist : " + snode);
+ System.out.println("Add the new SuperNode");
SuperNodeData data = new SuperNodeData(snode, port);
data.setStub(stub);
data.setNbOfNodes(0);
return null;
} else {
if (superNode == null) {
- System.out
+ System.err
.println("In Register.getNode : host == null !!!!!!!!!!!!!!!");
}
is = existSuperNode(superNode);
if (is != -1) {
return ((SuperNodeData) liste.get(is)).getStub();
} else {
- System.out.println("this superNode does not exist");
+ System.err.println("This superNode does not exist");
return null;
}
}
public synchronized int existSuperNode(String snode) {
if (snode == null) {
- System.out
- .println("!!!!!!!!!!!!!!!!!!!!!!!!! hostIP in existNode = "
+ System.err
+ .println("HostIP in existNode = "
+ snode);
}
int existe = -1;
JaceSuperNodeInterface remoteStub = null;
for (int i = 0; i < liste.size(); i++) {
- d = (SuperNodeData) liste.elementAt(i);
+ d = (SuperNodeData) liste.get(i);
if (!d.getIP().equals(LocalHost.Instance().getIP())) {
// if not me, I inform the other super nodes
remoteStub = d.getStub();
int is = -1;
is = existSuperNode(IP);
if (is != -1) {
- SuperNodeData d = (SuperNodeData) liste.elementAt(is);
+ SuperNodeData d = (SuperNodeData) liste.get(is);
d.setNbOfNodes(nb);
} else {
- System.out.println("ce superNode existe pas ds ma liste : " + IP);
+ System.err.println("This SuperNode does not exists in my list: " + IP);
}
}
- @SuppressWarnings("unchecked")
public void locateSuperNodes(JaceSuperNodeInterface stub) {
String remoteIP;
int remotePort;
boolean inStaticList = false;
while (i < liste.size() && !connected) {
remoteIP = LocalHost.Instance().resolve(
- ((SuperNodeData) liste.elementAt(i)).getIP());
- remotePort = ((SuperNodeData) liste.elementAt(i)).getPort();
+ ((SuperNodeData) liste.get(i)).getIP());
+ remotePort = ((SuperNodeData) liste.get(i)).getPort();
// If I'm not this superNode, I locate the others
if (!remoteIP.equals(LocalHost.Instance().getIP())) {
// SuperNodeListe.Instance().addStub(i, remoteStub);
// Send my stub to this corresponding remote SuperNode
- liste = (Vector<?>) remoteStub.sendStub(LocalHost.Instance()
+ liste = (ArrayList<Object>) remoteStub.sendStub(LocalHost.Instance()
.getIP(), LocalHost.Instance().getPort(), stub);
System.out.println("Recieved List");
connected = true;
// get the nb of Daemons the remote SuperNode has already
// registered
// nb = remoteStub.getNbOfNodes();
- // ((SuperNodeData)liste.elementAt(i)).setNbOfNodes(nb);
+ // ((SuperNodeData)liste.get(i)).setNbOfNodes(nb);
// System.out.println("bien envoye mon stub a " + remoteIP);
System.out.println("size:" + liste.size());
viewAll();
} catch (Exception e) {
- System.out.println("SuperNode " + remoteIP
+ System.err.println("SuperNode " + remoteIP
+ " is down or not already launched: " + e);
}
} else
liste.add(data);
TokenThread.Instance().setToken();
} else {
- System.out
- .println("no superNode alive in the static List, closing application");
+ System.err
+ .println("No superNode alive in the static List, closing application");
System.exit(1);
}
}
- @SuppressWarnings("unchecked")
public void addSuperNode(SuperNodeData d) {
int is = -1;
String name = d.getIP();
is = existSuperNode(name);
if (is != -1) {
- liste.setElementAt(d, is);
+ liste.set( is, d ) ;
} else {
liste.add(d);
}
// System.out.println("je remove le noeud de rang " + i);
liste.remove(i);
} else {
- System.out.println("super node existe pas");
+ System.err.println("The SuperNode does not exists!");
}
}
System.out.println("\nConfig of the superNodes :");
String msg = "";
for (int i = 0; i < liste.size(); i++) {
- SuperNodeData d = (SuperNodeData) liste.elementAt(i);
+ SuperNodeData d = (SuperNodeData) liste.get(i);
if (d.getIP().equals(LocalHost.Instance().getIP())) {
msg = "me : " + Register.Instance().getSize();
} else {
System.out.println(d.getIP() + " : "
- + ((SuperNodeData) liste.elementAt(i)).getNbOfNodes());
+ + ((SuperNodeData) liste.get(i)).getNbOfNodes());
}
}
System.out.println(msg);
/*********** Sébastien Miquée ***********/
/****************************************/
- public void addGNode( GNode _g )
+ public synchronized void addGNode( GNode _g )
{
if( _g != null )
{
for( int i = 0 ; i < liste.size() ; i++ )
{
- d = (SuperNodeData) liste.elementAt( i ) ;
+ d = (SuperNodeData) liste.get( i ) ;
if( ! d.getIP().equals(LocalHost.Instance().getIP() ) )
{
// if not me, I inform the other super nodes
try {
remoteStub.addGNode( _g ) ;
} catch( Exception e ) {
- System.err.println( "Unable to add new GNode at SuperNode " + d.getIP() ) ;
+ System.err.println( "Unable to add new GNode on SuperNode " + d.getIP() ) ;
+ }
+ }
+ }
+ }
+ }
+
+ public synchronized void removeGNode( GNode _g, int _mode, String _spawnerIP )
+ {
+ if( _g != null )
+ {
+
+ SuperNodeData d = null ;
+ JaceSuperNodeInterface remoteStub = null ;
+
+ for( int i = 0 ; i < liste.size() ; i++ )
+ {
+ d = (SuperNodeData) liste.get( i ) ;
+ if( ! d.getIP().equals(LocalHost.Instance().getIP() ) )
+ {
+ // if not me, I inform the other super nodes
+ remoteStub = d.getStub() ;
+ try {
+ remoteStub.delGNodeFromList( (Node)_g.getNode(), _mode, _spawnerIP ) ;
+ } catch( Exception e ) {
+ System.err.println( "Unable to remove GNode on SuperNode " + d.getIP() ) ;
+ }
+ }
+ }
+ }
+ }
+
+ public synchronized void removeGNode( GNode _g, int _mode )
+ {
+ if( _g != null )
+ {
+
+ SuperNodeData d = null ;
+ JaceSuperNodeInterface remoteStub = null ;
+
+ for( int i = 0 ; i < liste.size() ; i++ )
+ {
+ d = (SuperNodeData) liste.get( i ) ;
+ if( ! d.getIP().equals(LocalHost.Instance().getIP() ) )
+ {
+ // if not me, I inform the other super nodes
+ remoteStub = d.getStub() ;
+ try {
+ remoteStub.removeMappedGNode( _g, _mode ) ;
+ } catch( Exception e ) {
+ System.err.println( "Unable to remove GNode on SuperNode " + d.getIP() ) ;
}
}
}
}
}
- public void removeGNode( GNode _g )
+ public synchronized void setMappedGNode( GNode _g, int _mode )
{
if( _g != null )
{
for( int i = 0 ; i < liste.size() ; i++ )
{
- d = (SuperNodeData) liste.elementAt( i ) ;
+ d = (SuperNodeData) liste.get( i ) ;
if( ! d.getIP().equals(LocalHost.Instance().getIP() ) )
{
// if not me, I inform the other super nodes
remoteStub = d.getStub() ;
try {
- remoteStub.removeGNode( _g ) ;
+ remoteStub.setMapped( _g, _mode ) ;
} catch( Exception e ) {
- System.err.println( "Unable to remove GNode at SuperNode " + d.getIP() ) ;
+ System.err.println( "Unable to set mapped GNode on SuperNode " + d.getIP() ) ;
}
}
}
}
}
+
+
+ protected boolean workingOnGnodes()
+ {
+ boolean ok = true ;
+
+ SuperNodeData d = null ;
+ JaceSuperNodeInterface remoteStub = null ;
+
+ for( int i = 0 ; i < liste.size() ; i++ )
+ {
+ d = (SuperNodeData) liste.get( i ) ;
+ if( ! d.getIP().equals(LocalHost.Instance().getIP() ) )
+ {
+ // if not me, I inform the other super nodes
+ remoteStub = d.getStub() ;
+ try {
+ ok = ok && remoteStub.blockForMapping() ;
+ } catch( Exception e ) {
+ System.err.println( "Unable to remove GNode on SuperNode " + d.getIP() ) ;
+ }
+ }
+ }
+
+ return ok ;
+ }
public void setMapping( Algo al )
{
for( int i = 0 ; i < liste.size() ; i++ )
{
- d = (SuperNodeData) liste.elementAt( i ) ;
+ d = (SuperNodeData) liste.get( i ) ;
if( ! d.getIP().equals(LocalHost.Instance().getIP() ) )
{
// if not me, I inform the other super nodes
try {
remoteStub.setMapping( al ) ;
} catch( Exception e ) {
- System.err.println( "Unable to set mapping data at SuperNode " + d.getIP() ) ;
+ System.err.println( "Unable to set mapping data on SuperNode " + d.getIP() ) ;
}
}
}
}
}
+ public synchronized void propagateReplaceNode( GNode _dead, GNode _remp, String _spawnerIP )
+ {
+ if( _dead != null && _remp != null )
+ {
+ SuperNodeData d = null ;
+ JaceSuperNodeInterface remoteStub = null ;
+
+ for( int i = 0 ; i < liste.size() ; i++ )
+ {
+ d = (SuperNodeData) liste.get( i ) ;
+ if( ! d.getIP().equals( LocalHost.Instance().getIP() ) )
+ {
+ // if not me, I inform the other super nodes
+ remoteStub = d.getStub() ;
+ try {
+ remoteStub.updateMappedNode( _dead, _remp, _spawnerIP ) ;
+ } catch( Exception e ) {
+ System.err.println( "Unable to propagate replacing node on SuperNode " + d.getIP() ) ;
+ }
+ }
+ }
+ }
+ }
+
+
+ /**
+ * Send to all SuperNode the deletion of a mapping algorithm.
+ * @param id The mapping algorithm's identifier
+ */
+ public void removeAlgo( String _id )
+ {
+ SuperNodeData d = null ;
+ JaceSuperNodeInterface remoteStub = null ;
+
+ for( int i = 0 ; i < liste.size() ; i++ )
+ {
+ d = (SuperNodeData) liste.get( i ) ;
+ if( ! d.getIP().equals( LocalHost.Instance().getIP() ) )
+ {
+ // if not me, I inform the other super nodes
+ remoteStub = d.getStub() ;
+ try {
+ remoteStub.removeAlgo( _id, 1 ) ;
+ } catch( Exception e ) {
+ System.err.println( "Unable to propagate the mapping algorithm deletion " + d.getIP() ) ;
+ }
+ }
+ }
+ }
+
}