ok grazie hai ragione, provo a postare più codice allora la classe Pacnode è la seguente
codice:
package p2pac.model;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import p2pac.model.AcRule;
import rice.environment.Environment;
import rice.p2p.commonapi.NodeHandle;
import rice.pastry.Id;
import rice.pastry.PastryNode;
public class PacNode {
public Id pid;
private PastryNode pastryNode;
private String database;
private int acCount; //counter of AC Rule
private List acrules = new ArrayList();
private List SecretShares = new ArrayList();
public PacNode(PastryNode pastryNode, String dirFile) {
this.pid = pastryNode.getNodeId();
this.pastryNode = pastryNode;
this.database = pastryNode.getId().toString();
this.acCount = 0;
}
public void addAcRule(String sql, List peers, Map networkMap, int recoveryThreshold, int shareSize, Environment env) throws InterruptedException {
// create the AC rule
AcRule myAcr = new AcRule(pid, acCount++, sql, peers);
acrules.add(myAcr);
// encrypt the database block and get the key
String key = "5";
// enforce the AC rule far rispettare le regole AC
myAcr.enforceAcRule(recoveryThreshold, shareSize, key, networkMap, env);
}
public void addSecretShare(SecretShare share) {
SecretShares.add(share);
}
public int getSecretSharesSize() {
return SecretShares.size();
}
public SecretShare getSecretShare(int index) {
return (SecretShare) SecretShares.get(index);
}
public PastryNode getPastryNode() {
return pastryNode;
}
public boolean isAcRulesEmpty() {
return acrules.isEmpty();
}
public int getAcRulesSize() {
return acrules.size();
}
public AcRule getAcRule(int index) {
return (AcRule) acrules.get(index);
}
}
mentre nella classe del controllo dove viene creata la mappa una parte del codice è la seguente
codice:
BootHandle bootHandle = ((SocketPastryNodeFactory) factory).getNodeHandle(bootaddress);
Pastrynode = pastryNode = factory.newNode(bootHandle);
PacNode node = new PacNode(pastryNode, dirFile);
MyApp app = new MyApp(node.getPastryNode());
NodeIdFactory nidFactory = new RandomNodeIdFactory(env);
synchronized (node.getPastryNode()) {
while (!node.getPastryNode().isReady() && !node.getPastryNode().joinFailed()) {
node.getPastryNode().wait(5000);
// node.wait(500);
if (node.getPastryNode().joinFailed()) {
throw new IOException("Unable to connect to the ring. Reason: " + node.getPastryNode().joinFailedReason());
}
}
}
// route 10 messages
for (int i = 0; i < 1; i++) {
// pick a key at random
Id randId = nidFactory.generateNodeId();
// send to that key
app.routeMyMsg(randId);
// wait a sec
env.getTimeSource().sleep(1000);
}
// wait 10 seconds
env.getTimeSource().sleep(10000);
// send directly to my leafset
LeafSet leafSet = node.getPastryNode().getLeafSet();
// this is a typical loop to cover your leafset. Note that if the leafset
// overlaps, then duplicate nodes will be sent to twice
for (int i=-leafSet.ccwSize(); i<=leafSet.cwSize(); i++) {
if (i != 0) { // don't send to self
// select the item
NodeHandle nh = leafSet.get(i);
// send the message directly to the node
app.routeMyMsgDirect(nh);
nodesKeys.add(nh.getNodeId());
nodes.put(nh.getNodeId()+ "",node);
dove nella mappa dovrebbe esserci un valore di tipo "node" Della classe PAcnode, sul fatto della ridondanza hai ragione, ma stavo facendo delle prove. Cmq non posso cambiare il tipo della mappa.. in quanto su quella ci sono altre classi a molti altri metodi che ci lavorano sopra.. e non posso cambiare il tutto!!!dovrei capire come fa diventare il mio ID del tipo giusto da immettere nella mappa.
Non so se sono stata abbastanza chiara.
Grazie in anticipo