/** * Process Next query response * * @param response * @return */ public Request NextQueryResponseProcess(Response response) { switch (Integer.parseInt(response.getResponseCode())) { case 200: String[] msg = response.getMessage().get(0).trim().split("\\s+"); this.setNextPeerHostName(msg[0]); this.setNextPeerPort(msg[1]); this.setNextPeerID(msg[2]); ArrayList<String> message = new ArrayList<String>(); message.add(this.getHostname() + " " + this.getPort()); redirectClient(new Request("PULL", Settings.Version, 1, this.getID(), message).toString()); return new Request("PULL", Settings.Version, 1, this.getID(), message); case 501: redirectClient(new Request("NEXT", Settings.Version, 0).toString()); return new Request("NEXT", Settings.Version, 0); } return new Request(); }
/** * Process pull query response * * @param response * @return */ public Request PullQueryResponseProcess(Response response) { switch (Integer.parseInt(response.getResponseCode())) { case 200: redirectClient(new Request("DONE", Settings.Version, 0).toString()); return new Request("DONE", Settings.Version, 0); } return new Request(); }
/** * Processes an ID query response * * @param response * @return */ public Request IDQueryResponseProcess(Response response) { switch (Integer.parseInt(response.getResponseCode())) { case 301: // interpret first element of the arraylist containing the message to get the information // for next hostname and port number String[] msg = response.getMessage().get(0).trim().split("\\s+"); this.setRedirectHostName(msg[0]); this.setRedirectPort(msg[1]); redirectClient(this.genRequest("ID", 0, this.getID()).toString()); return this.genRequest("ID", 0, this.getID()); case 200: redirectClient(this.genRequest("NEXT", 0, "0").toString()); return this.genRequest("NEXT", 0, "0"); default: redirectClient(this.genRequest("ID", 0, this.getID()).toString()); return this.genRequest("ID", 0, this.getID()); } }