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
// in order to discover new superNodes dynamicaly
/* Sébastien Miquée -- ajout de la lecture du fichier de config **/
-
- @SuppressWarnings("unchecked")
public void staticInitialization() {
String adr = "";
String home = System.getProperty("user.home");
// 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.err.println("This superNode does not exist : " + snode);
System.out.println("Add the new SuperNode");
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.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());
}
- @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("\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
}
}
}
+
+ 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 void removeGNode( GNode _g )
+ public synchronized void removeGNode( 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.removeMappedGNode( _g, _mode ) ;
} catch( Exception e ) {
System.err.println( "Unable to remove GNode on SuperNode " + d.getIP() ) ;
}
}
}
+ public synchronized void setMappedGNode( 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.setMapped( _g, _mode ) ;
+ } catch( Exception e ) {
+ System.err.println( "Unable to set mapped GNode on SuperNode " + d.getIP() ) ;
+ }
+ }
+ }
+ }
+ }
+
protected boolean workingOnGnodes()
{
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 {
ok = ok && remoteStub.blockForMapping() ;
} catch( Exception e ) {
- System.err.println( "Unable to remove GNode at SuperNode " + d.getIP() ) ;
+ System.err.println( "Unable to remove GNode on SuperNode " + d.getIP() ) ;
}
}
}
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 void propagateReplaceNode( GNode _dead, GNode _remp )
+ public synchronized void propagateReplaceNode( GNode _dead, GNode _remp, String _spawnerIP )
{
if( _dead != null && _remp != null )
{
for( int i = 0 ; i < liste.size() ; i++ )
{
- d = (SuperNodeData) liste.elementAt( i ) ;
- if( ! d.getIP().equals(LocalHost.Instance().getIP() ) )
+ 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 ) ;
+ remoteStub.updateMappedNode( _dead, _remp, _spawnerIP ) ;
} catch( Exception e ) {
- System.err.println( "Unable to set mapping data at SuperNode " + d.getIP() ) ;
+ 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() ) ;
+ }
+ }
+ }
+ }
+
}