Commit edef04e6 authored by mohammad.salama's avatar mohammad.salama

Second commit

parent 8f751f16
...@@ -92,10 +92,10 @@ public class Coordinator ...@@ -92,10 +92,10 @@ public class Coordinator
} }
private Request extractRequest(Socket clientSocket) throws IOException, ClassNotFoundException private String extractRequest(Socket clientSocket) throws IOException, ClassNotFoundException
{ {
ObjectInputStream objectInputStream = new ObjectInputStream(clientSocket.getInputStream()); ObjectInputStream objectInputStream = new ObjectInputStream(clientSocket.getInputStream());
Request request = (Request) objectInputStream.readObject(); String request = (String) objectInputStream.readObject();
return request; return request;
} }
...@@ -103,8 +103,8 @@ public class Coordinator ...@@ -103,8 +103,8 @@ public class Coordinator
{ {
try try
{ {
Request request = extractRequest(clientSocket); String query = extractRequest(clientSocket);
List<Response> responses = spreadQuery(request); List<Response> responses = spreadQuery(query);
processResultsAndPrepareAnswer(responses); processResultsAndPrepareAnswer(responses);
} }
catch (IOException | InterruptedException | ClassNotFoundException | KeeperException e) catch (IOException | InterruptedException | ClassNotFoundException | KeeperException e)
...@@ -160,7 +160,7 @@ public class Coordinator ...@@ -160,7 +160,7 @@ public class Coordinator
* response is tree-map here the keys are words * response is tree-map here the keys are words
* and values are list of pair<fileName,Number Of Appearance of the word in it> * and values are list of pair<fileName,Number Of Appearance of the word in it>
* */ * */
public List<Response> spreadQuery(Request request) throws InterruptedException, KeeperException, IOException, ExecutionException public List<Response> spreadQuery(String query) throws InterruptedException, KeeperException, IOException, ExecutionException
{ {
List<String> physicalZnodes = zooKeeper.getChildren(PHYSICAL_ZNODES_PATH, false); List<String> physicalZnodes = zooKeeper.getChildren(PHYSICAL_ZNODES_PATH, false);
...@@ -191,6 +191,7 @@ public class Coordinator ...@@ -191,6 +191,7 @@ public class Coordinator
PHYSICAL_ZNODES_PATH + "/" + physicalZnodes.get(index), PHYSICAL_ZNODES_PATH + "/" + physicalZnodes.get(index),
false, stat) false, stat)
); );
Request request = new Request(query , filesNumberforNode , filesOffset);
tasks.add(() -> sendRequestToNode(request, ipAddress)); tasks.add(() -> sendRequestToNode(request, ipAddress));
index = (1 + index) % physicalZnodes.size(); index = (1 + index) % physicalZnodes.size();
filesOffset = (filesOffset + filesNumberforNode) % totalFilesNumber; filesOffset = (filesOffset + filesNumberforNode) % totalFilesNumber;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment