Exemple #1
0
 // Finds the responsible node for the photon and updates it and the successor of it
 public void findResponsibleNode() {
   String photonJson = requestSender.findSpark();
   try {
     JSONObject temp = new JSONObject(photonJson);
     JSONObject temp2 = temp.getJSONObject("coreInfo");
     String deviceID = temp2.getString("deviceID");
     int convertedID = Key.generate16BitsKey(deviceID);
     NodeInfo responsible = findSuccessor(convertedID);
     // NodeInfo resposibleSuccessor = requestSender.getNodeSuccessor(responsible);
     requestSender.updatePhoton(responsible);
     // requestSender.updatePhoton(resposibleSuccessor);
     System.out.println("PhotonID: " + convertedID);
     System.out.println("Responsible is:\n" + responsible.getID());
   } catch (JSONException e) {
     e.printStackTrace();
   }
 }
Exemple #2
0
 public Node(String ip, int port) {
   this.ip = ip;
   this.port = port;
   updateTime = 30;
   photon = new JSONObject();
   isPhotonActive = false;
   nodeServer = new NodeServer(port);
   id = Key.generate16BitsKey(ip, port);
   thisNode = new NodeInfo(ip, port, id);
   requestSender = new RequestSender(thisNode);
   fingers = new NodeInfo[16];
   parser = new HtmlParser();
   timer = new Timer();
   photonData = new ArrayList<PhotonData>();
   succList = new NodeInfo[2];
   replicas = 3;
   replicatedValue = 0;
 }
Exemple #3
0
 // Updates the photon of this node
 @PUT
 @Path("/update-photon/")
 public Response updatePhoton(NodeInfo target) {
   String photonJson = requestSender.findSpark();
   try {
     photon = new JSONObject(photonJson);
     JSONObject coreInfo = photon.getJSONObject("coreInfo");
     String deviceID = coreInfo.getString("deviceID");
     photonId = Key.generate16BitsKey(deviceID);
     System.out.println("deviceID returned: " + deviceID);
     System.out.println("deviceID int returned: " + photonId);
     isPhotonActive = true;
     createPhotonUpdateTimer();
   } catch (JSONException e) {
     e.printStackTrace();
   }
   // System.out.println("Spark returned:\n" + photonJson);
   return Response.status(200).entity(photon).build();
 }