package jaceP2P;
-import java.util.Vector;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import and.Mapping.*;
public class TokenThread extends Thread {
public void setToken() {
token = true;
ScanThreadSuperNode.Instance().setToken(false);
- System.out.println("the token is put to true in the tokenthread");
+ System.out.println("The token is put to true in the tokenthread");
try {
synchronized (TokenThread.Instance()) {
TokenThread.Instance().notify();
}
} catch (Exception e) {
- System.out.println("unable to notify :" + e);
+ System.err.println("Unable to notify :" + e);
}
// System.out.println("finished set token");
}
- @SuppressWarnings("unchecked")
+
public void distribute() {
System.out.println("totalDaemons="
+ SuperNodeListe.Instance().getTotalDaemons());
int nbLocal = Register.Instance().getSize();
int totalDaemons;
- Vector liste = SuperNodeListe.Instance().getListe();
+ ArrayList<Object> liste = SuperNodeListe.Instance().getListe();
+
+ /******* Sébastien Miquée ********/
+ ArrayList<GNode> gnodes = null ;
+ try {
+ gnodes = SuperNodeListe.Instance().getStubOf(LocalHost.Instance().getIP()).getGNodes() ;
+ } catch (RemoteException e1) {
+ System.err.println( "Unable to retrieve local gnodes list !" ) ;
+ e1.printStackTrace();
+ }
+
synchronized (SuperNodeListe.Instance()) {
synchronized (Register.Instance()) {
if (nbLocal > 5) {
if (((SuperNodeData) liste.get(i)).getNbOfNodes() < nbDaemons)
try {
// System.out.println("Snode="+i+" nodes="+((SuperNodeData)liste.get(i)).getNbOfNodes());
- Vector nodes = Register.Instance()
+ ArrayList<Node> nodes = Register.Instance()
.getListe();
int amountToSend = nbDaemons
- ((SuperNodeData) liste.get(i))
.getNbOfNodes();
- Vector newVector = new Vector();
+ ArrayList<Node> newVector = new ArrayList<Node>() ;
for (int j = 0; j < amountToSend; j++) {
- newVector.add(nodes.elementAt(j));
+ newVector.add(nodes.get(j));
}
((SuperNodeData) liste.get(i)).getStub()
- .sendSurplus(newVector);
+ .sendSurplus(newVector, gnodes);
for (int j = 0; j < amountToSend; j++)
nodes.remove(0);
int index = SuperNodeListe.Instance()
new ForwardCount().start();
} catch (Exception e) {
- System.out
- .println("unable to send surplus to "
+ System.err
+ .println("Unable to send surplus to "
+ ((SuperNodeData) liste
.get(i)).getIP()
+ " :" + e);
index = (index + 1) % SuperNodeListe.Instance().getListe().size();
// System.out.println("index="+index);
try {
- ((SuperNodeData) liste.elementAt(index)).getStub().setToken();
+ ((SuperNodeData) liste.get(index)).getStub().setToken();
if (index != SuperNodeListe.Instance().existSuperNode(
LocalHost.Instance().getIP()))
token = false;
System.out.println("Passing token to " + index);
} catch (Exception e) {
try {
- System.out.println("Unable to send Token to "
- + ((SuperNodeData) liste.elementAt(index)).getIP()
+ System.err.println("Unable to send Token to "
+ + ((SuperNodeData) liste.get(index)).getIP()
+ " :" + e);
/*
* SuperNodeListe.Instance().removeSuperNode(((SuperNodeData)