Beispiel #1
0
 /**
  * @throws RemoteException
  * @throws UnknownHostException
  */
 public void stabilize() throws RemoteException, UnknownHostException {
   ChordMessageInterface succ = rmiChord(successor.getIp(), successor.getPort());
   Finger x = succ.getPredecessor();
   if (ino(x.getId(), i, successor.getId())) {
     successor = x;
   }
   InetAddress ip = InetAddress.getLocalHost();
   succ = rmiChord(successor.getIp(), successor.getPort());
   succ.notify(new Finger(ip.getHostAddress(), port, i));
 }
Beispiel #2
0
 /**
  * @param guid
  * @param data
  * @throws IOException
  */
 public void put(int guid, byte[] data) throws IOException {
   Finger succ = locateSuccessor(guid);
   if (succ != null) {
     ChordMessageInterface succChord = rmiChord(succ.getIp(), succ.getPort());
     succChord.write(
         guid, data); // Writes bytes from the specified byte array to this file output stream
   }
   // TODO: Store data in the closest node.
   // before calling this method you need to find the node using
   // locateSuccessor.
 }
Beispiel #3
0
 /**
  * @param guid
  * @throws IOException
  */
 public void remove(int guid) throws IOException {
   Finger succ = locateSuccessor(guid);
   if (succ != null) {
     ChordMessageInterface succChord = rmiChord(succ.getIp(), succ.getPort());
     succChord.delete(
         guid); // Writes bytes from the specified byte array to this file output stream
   }
   // TODO: remove the file guid.
   // before calling this method you need to find the node using
   // locateSuccessor.
 }
Beispiel #4
0
 /**
  * @param key
  * @return
  * @throws RemoteException
  */
 public Finger locateSuccessor(int key) throws RemoteException {
   if (key == i) {
     throw new IllegalArgumentException("Key must be distinct that  " + i);
   }
   if (successor != null && successor.getId() != i) {
     if (in(key, i, successor.getId())) {
       return successor;
     }
     Finger jguid = closestPrecedingNode(key);
     ChordMessageInterface j = rmiChord(jguid.getIp(), jguid.getPort());
     if (j == null) {
       return null;
     }
     return j.locateSuccessor(key);
   }
   return successor;
 }
Beispiel #5
0
 /**
  * @param ip
  * @param port
  * @throws RemoteException
  */
 public void joinRing(String ip, int port) throws RemoteException {
   ChordMessageInterface j = rmiChord(ip, port);
   predecessor = null;
   successor = j.locateSuccessor(i);
 }