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

Fifth Commit - Sending and Receiving between Coordinator and Slaves

parent 49ec3d3f
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<project version="4"> <project version="4">
<component name="ArtifactsWorkspaceSettings"> <component name="ArtifactsWorkspaceSettings">
<artifacts-to-build> <artifacts-to-build>
<artifact name="AutoHealer:jar" /> <artifact name="Distributed-Search:jar" />
</artifacts-to-build> </artifacts-to-build>
</component> </component>
<component name="AutoImportSettings"> <component name="AutoImportSettings">
...@@ -10,17 +10,15 @@ ...@@ -10,17 +10,15 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="b8bcd35c-99f3-44c8-a866-59f81c3c8bd0" name="Changes" comment=""> <list default="true" id="b8bcd35c-99f3-44c8-a866-59f81c3c8bd0" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/src/main/java/WordsCountingInFiles/WordsCountingInFiles.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/artifacts/AutoHealer_jar.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/artifacts/TransientWorker_jar.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/logs/app.log" beforeDir="false" afterPath="$PROJECT_DIR$/logs/app.log" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/AutoHealerAndClusterSearch/Application.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/AutoHealerAndClusterSearch/Application.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/AutoHealerAndClusterSearch/Coordinator.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/AutoHealerAndClusterSearch/Coordinator.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/AutoHealerAndClusterSearch/Coordinator.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/AutoHealerAndClusterSearch/Coordinator.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/AutoHealerAndClusterSearch/OnElectionAction.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/AutoHealerAndClusterSearch/OnElectionAction.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/AutoHealerAndClusterSearch/ServiceRegistry.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/AutoHealerAndClusterSearch/ServiceRegistry.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/AutoHealerAndClusterSearch/TransientWorker.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/AutoHealerAndClusterSearch/TransientWorker.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/AutoHealerAndClusterSearch/TransientWorker.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/AutoHealerAndClusterSearch/TransientWorker.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/AutoHealerAndClusterSearch/TransientWorkerApplication.java" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/ObjectExchangeInCluster/FileWordPair.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ObjectExchangeInCluster/FileWordPair.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/ObjectExchangeInCluster/SearchQueryRequest.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ObjectExchangeInCluster/SearchQueryRequest.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/generalTesting/test.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/generalTesting/test.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/ObjectExchangeInCluster/SearchQueryResponse.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ObjectExchangeInCluster/SearchQueryResponse.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/target/classes/AutoHealerAndClusterSearch/Coordinator.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/AutoHealerAndClusterSearch/Coordinator.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/target/classes/AutoHealerAndClusterSearch/TransientWorker.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/AutoHealerAndClusterSearch/TransientWorker.class" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
...@@ -79,7 +77,35 @@ ...@@ -79,7 +77,35 @@
<recent name="" /> <recent name="" />
</key> </key>
</component> </component>
<component name="RunManager"> <component name="RunManager" selected="Application.n4">
<configuration name="n1" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="AutoHealerAndClusterSearch.Application" />
<module name="Distributed-Search" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="n2" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="AutoHealerAndClusterSearch.Application" />
<module name="Distributed-Search" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="n3" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="AutoHealerAndClusterSearch.Application" />
<module name="Distributed-Search" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="n4" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="AutoHealerAndClusterSearch.Application" />
<module name="Distributed-Search" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="test" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true"> <configuration name="test" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="generalTesting.test" /> <option name="MAIN_CLASS_NAME" value="generalTesting.test" />
<module name="Distributed-Search" /> <module name="Distributed-Search" />
...@@ -93,6 +119,13 @@ ...@@ -93,6 +119,13 @@
<option name="Make" enabled="true" /> <option name="Make" enabled="true" />
</method> </method>
</configuration> </configuration>
<list>
<item itemvalue="Application.n1" />
<item itemvalue="Application.n2" />
<item itemvalue="Application.n3" />
<item itemvalue="Application.n4" />
<item itemvalue="Application.test" />
</list>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="Application.test" /> <item itemvalue="Application.test" />
......
...@@ -259,3 +259,266 @@ java.util.ConcurrentModificationException: null ...@@ -259,3 +259,266 @@ java.util.ConcurrentModificationException: null
at AutoHealerAndClusterSearch.ServiceRegistry.process(ServiceRegistry.java:208) at AutoHealerAndClusterSearch.ServiceRegistry.process(ServiceRegistry.java:208)
at org.apache.zookeeper.ClientCnxn$EventThread.processEvent(ClientCnxn.java:563) at org.apache.zookeeper.ClientCnxn$EventThread.processEvent(ClientCnxn.java:563)
at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:538) at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:538)
2024-01-25 20:51:13,784 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 20:51:13,809 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000077
2024-01-25 20:51:13,815 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am LEADER
2024-01-25 20:51:13,818 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] The cluster addresses are: []
2024-01-25 20:51:13,821 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to be Coordinator and I am Master !
2024-01-25 20:51:13,828 INFO AutoHealerAndClusterSearch.Coordinator [main] Server started on port 12345
2024-01-25 20:52:08,336 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 20:52:08,355 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000078
2024-01-25 20:52:08,359 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 20:52:08,365 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 20:52:08,375 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 12346
2024-01-25 20:52:22,727 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 20:52:22,739 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000079
2024-01-25 20:52:22,744 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 20:52:22,749 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 20:52:22,758 ERROR AutoHealerAndClusterSearch.OnElectionAction [main] Could Not Register To Cluster
2024-01-25 20:52:22,761 INFO AutoHealerAndClusterSearch.LeaderElection [main] Watching znode c_0000000078 in ELECTION
2024-01-25 20:52:26,406 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 20:52:26,418 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000080
2024-01-25 20:52:26,422 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 20:52:26,427 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 20:52:26,435 ERROR AutoHealerAndClusterSearch.OnElectionAction [main] Could Not Register To Cluster
2024-01-25 20:52:26,438 INFO AutoHealerAndClusterSearch.LeaderElection [main] Watching znode c_0000000079 in ELECTION
2024-01-25 20:58:53,570 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 20:58:53,587 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000081
2024-01-25 20:58:53,591 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am LEADER
2024-01-25 20:58:53,594 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] The cluster addresses are: []
2024-01-25 20:58:53,598 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to be Coordinator and I am Master !
2024-01-25 20:58:53,601 INFO AutoHealerAndClusterSearch.Coordinator [main] Server started on port 12345
2024-01-25 20:59:11,110 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 20:59:11,126 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000082
2024-01-25 20:59:11,130 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 20:59:11,137 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 20:59:11,143 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 12346
2024-01-25 20:59:31,477 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 20:59:31,492 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000083
2024-01-25 20:59:31,496 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 20:59:31,503 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 20:59:31,510 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 12347
2024-01-25 21:03:01,619 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:03:01,637 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000084
2024-01-25 21:03:01,642 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am LEADER
2024-01-25 21:03:01,645 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] The cluster addresses are: []
2024-01-25 21:03:01,649 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to be Coordinator and I am Master !
2024-01-25 21:04:41,844 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:04:41,874 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000085
2024-01-25 21:04:41,878 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am LEADER
2024-01-25 21:04:41,882 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] The cluster addresses are: []
2024-01-25 21:04:41,887 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to be Coordinator and I am Master !
2024-01-25 21:04:41,890 INFO AutoHealerAndClusterSearch.Coordinator [main] Server started on port 123
2024-01-25 21:04:46,225 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:04:46,250 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000086
2024-01-25 21:04:46,255 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 21:04:46,263 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 21:04:46,269 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 456
2024-01-25 21:04:48,973 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:04:48,995 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000087
2024-01-25 21:04:48,999 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 21:04:49,006 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 21:04:49,012 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 789
2024-01-25 21:08:16,147 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:08:16,169 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000088
2024-01-25 21:08:16,172 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am LEADER
2024-01-25 21:08:16,175 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] The cluster addresses are: []
2024-01-25 21:08:16,180 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to be Coordinator and I am Master !
2024-01-25 21:08:16,183 INFO AutoHealerAndClusterSearch.Coordinator [main] Server started on port 123
2024-01-25 21:08:19,001 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:08:19,024 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000089
2024-01-25 21:08:19,028 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 21:08:19,035 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 21:08:19,041 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 456
2024-01-25 21:08:20,749 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:08:20,772 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000090
2024-01-25 21:08:20,776 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 21:08:20,785 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 21:08:20,790 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 789
2024-01-25 21:10:15,048 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:10:15,077 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000091
2024-01-25 21:10:15,083 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am LEADER
2024-01-25 21:10:15,087 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] The cluster addresses are: []
2024-01-25 21:10:15,094 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to be Coordinator and I am Master !
2024-01-25 21:10:15,096 INFO AutoHealerAndClusterSearch.Coordinator [main] Server started on port 123
2024-01-25 21:10:17,569 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:10:17,591 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000092
2024-01-25 21:10:17,594 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 21:10:17,602 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 21:10:17,607 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 456
2024-01-25 21:10:20,154 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:10:20,182 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000093
2024-01-25 21:10:20,186 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 21:10:20,194 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 21:10:20,200 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 789
2024-01-25 21:19:31,200 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:19:31,231 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000094
2024-01-25 21:19:31,236 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am LEADER
2024-01-25 21:19:31,240 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] The cluster addresses are: []
2024-01-25 21:19:31,247 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to be Coordinator and I am Master !
2024-01-25 21:19:31,249 INFO AutoHealerAndClusterSearch.Coordinator [main] Server started on port 123
2024-01-25 21:19:33,346 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:19:33,377 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000095
2024-01-25 21:19:33,380 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 21:19:33,388 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 21:19:33,393 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 456
2024-01-25 21:19:35,537 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:19:35,567 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000096
2024-01-25 21:19:35,573 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 21:19:35,583 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 21:19:35,591 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 789
2024-01-25 21:21:22,726 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:21:22,763 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000097
2024-01-25 21:21:22,768 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am LEADER
2024-01-25 21:21:22,772 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] The cluster addresses are: []
2024-01-25 21:21:22,779 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to be Coordinator and I am Master !
2024-01-25 21:21:22,782 INFO AutoHealerAndClusterSearch.Coordinator [main] Server started on port 123
2024-01-25 21:21:25,016 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:21:25,060 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000098
2024-01-25 21:21:25,065 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 21:21:25,073 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 21:21:25,080 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 456
2024-01-25 21:21:27,183 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:21:27,212 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000099
2024-01-25 21:21:27,216 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 21:21:27,231 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 21:21:27,239 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 789
2024-01-25 21:23:06,107 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:23:06,140 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000100
2024-01-25 21:23:06,144 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am LEADER
2024-01-25 21:23:06,155 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] The cluster addresses are: []
2024-01-25 21:23:06,163 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to be Coordinator and I am Master !
2024-01-25 21:25:04,266 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:25:04,294 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000101
2024-01-25 21:25:04,302 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am LEADER
2024-01-25 21:25:04,310 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] The cluster addresses are: []
2024-01-25 21:25:04,319 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to be Coordinator and I am Master !
2024-01-25 21:25:04,325 INFO AutoHealerAndClusterSearch.Coordinator [main] Server started on port 123
2024-01-25 21:25:13,612 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:25:13,640 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000102
2024-01-25 21:25:13,650 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 21:25:13,667 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 21:25:13,672 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 4456
2024-01-25 21:25:20,694 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:25:20,723 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000103
2024-01-25 21:25:20,727 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 21:25:20,743 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 21:25:20,751 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 897
2024-01-25 21:25:23,688 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 21:25:23,688 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 21:28:21,071 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:28:21,106 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000104
2024-01-25 21:28:21,115 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am LEADER
2024-01-25 21:28:21,119 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] The cluster addresses are: []
2024-01-25 21:28:21,127 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to be Coordinator and I am Master !
2024-01-25 21:28:21,133 INFO AutoHealerAndClusterSearch.Coordinator [main] Server started on port 123
2024-01-25 21:28:24,420 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:28:24,462 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000105
2024-01-25 21:28:24,468 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 21:28:24,478 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 21:28:24,486 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 548
2024-01-25 21:28:27,248 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:28:27,291 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000106
2024-01-25 21:28:27,296 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 21:28:27,315 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 21:28:27,322 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 3515
2024-01-25 21:28:29,839 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 21:28:29,839 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 21:33:48,759 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:33:48,795 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000107
2024-01-25 21:33:48,800 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am LEADER
2024-01-25 21:33:48,807 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] The cluster addresses are: []
2024-01-25 21:33:48,819 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to be Coordinator and I am Master !
2024-01-25 21:33:48,823 INFO AutoHealerAndClusterSearch.Coordinator [main] Server started on port 123
2024-01-25 21:33:51,475 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:33:51,519 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000108
2024-01-25 21:33:51,524 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 21:33:51,535 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 21:33:51,540 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 454
2024-01-25 21:33:53,848 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 21:33:53,902 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000109
2024-01-25 21:33:53,910 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 21:33:53,927 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 21:33:53,932 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 656
2024-01-25 21:33:57,894 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 21:33:57,894 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:05:22,295 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 23:05:22,326 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000110
2024-01-25 23:05:22,332 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am LEADER
2024-01-25 23:05:22,335 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] The cluster addresses are: []
2024-01-25 23:05:22,338 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to be Coordinator and I am Master !
2024-01-25 23:05:22,340 INFO AutoHealerAndClusterSearch.Coordinator [main] Server started on port 123
2024-01-25 23:05:25,163 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 23:05:25,183 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000111
2024-01-25 23:05:25,187 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 23:05:25,194 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 23:05:25,199 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 456
2024-01-25 23:05:26,899 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:05:36,398 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 23:05:36,417 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000112
2024-01-25 23:05:36,421 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 23:05:36,426 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 23:05:36,432 ERROR AutoHealerAndClusterSearch.OnElectionAction [main] Could Not Register To Cluster
2024-01-25 23:05:36,435 INFO AutoHealerAndClusterSearch.LeaderElection [main] Watching znode c_0000000111 in ELECTION
2024-01-25 23:05:50,703 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 23:05:50,729 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000113
2024-01-25 23:05:50,733 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am LEADER
2024-01-25 23:05:50,738 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] The cluster addresses are: []
2024-01-25 23:05:50,742 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to be Coordinator and I am Master !
2024-01-25 23:05:50,744 INFO AutoHealerAndClusterSearch.Coordinator [main] Server started on port 123
2024-01-25 23:05:58,229 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 23:05:58,252 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000114
2024-01-25 23:05:58,256 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 23:05:58,262 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 23:05:58,269 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 456
2024-01-25 23:06:00,936 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 23:06:00,958 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000115
2024-01-25 23:06:00,962 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 23:06:00,969 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 23:06:00,976 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 789
2024-01-25 23:06:04,851 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:06:04,851 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:06:22,582 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:06:22,582 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:06:27,779 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:06:27,779 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:06:41,352 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:06:41,352 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:06:47,780 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:06:47,780 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:06:51,194 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:06:51,194 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:07:25,658 INFO AutoHealerAndClusterSearch.Application [main-EventThread] Successfully connected to Zookeeper
2024-01-25 23:07:25,682 INFO AutoHealerAndClusterSearch.LeaderElection [main] My Node under Election is/election/c_0000000116
2024-01-25 23:07:25,687 INFO AutoHealerAndClusterSearch.LeaderElection [main] I am NOT LEADER
2024-01-25 23:07:25,691 INFO AutoHealerAndClusterSearch.ServiceRegistry [main] Registered to service registry
2024-01-25 23:07:25,699 INFO AutoHealerAndClusterSearch.TransientWorker [main] Server started on port 5624
2024-01-25 23:07:31,931 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:07:31,931 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:07:31,932 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:07:42,841 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:07:42,841 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:07:42,841 INFO AutoHealerAndClusterSearch.TransientWorker [main] Coordinator connected: /127.0.0.1
2024-01-25 23:07:53,678 INFO AutoHealerAndClusterSearch.LeaderElection [main-EventThread] I am LEADER
2024-01-25 23:07:53,701 INFO AutoHealerAndClusterSearch.ServiceRegistry [main-EventThread] The cluster addresses are: [127.0.0.1:789, 127.0.0.1:5624]
2024-01-25 23:07:53,705 INFO AutoHealerAndClusterSearch.ServiceRegistry [main-EventThread] Registered to be Coordinator and I am Master !
2024-01-25 23:07:53,707 ERROR AutoHealerAndClusterSearch.OnElectionAction [main-EventThread] Could Not Register to be Coordinator
2024-01-25 23:07:53,711 ERROR org.apache.zookeeper.ClientCnxn [main-EventThread] Error while calling watcher.
java.lang.RuntimeException: java.net.BindException: Address already in use: bind
at AutoHealerAndClusterSearch.OnElectionAction.onElectedToBeLeader(OnElectionAction.java:35)
at AutoHealerAndClusterSearch.LeaderElection.reelectLeader(LeaderElection.java:51)
at AutoHealerAndClusterSearch.LeaderElection.process(LeaderElection.java:73)
at org.apache.zookeeper.ClientCnxn$EventThread.processEvent(ClientCnxn.java:563)
at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:538)
Caused by: java.net.BindException: Address already in use: bind
at java.base/sun.nio.ch.Net.bind0(Native Method)
at java.base/sun.nio.ch.Net.bind(Net.java:555)
at java.base/sun.nio.ch.Net.bind(Net.java:544)
at java.base/sun.nio.ch.NioSocketImpl.bind(NioSocketImpl.java:643)
at java.base/java.net.ServerSocket.bind(ServerSocket.java:388)
at java.base/java.net.ServerSocket.<init>(ServerSocket.java:274)
at java.base/java.net.ServerSocket.<init>(ServerSocket.java:167)
at AutoHealerAndClusterSearch.Coordinator.start(Coordinator.java:45)
at AutoHealerAndClusterSearch.ServiceRegistry.registerToCoordinator(ServiceRegistry.java:75)
at AutoHealerAndClusterSearch.OnElectionAction.onElectedToBeLeader(OnElectionAction.java:29)
... 4 common frames omitted
...@@ -8,6 +8,7 @@ import org.slf4j.Logger; ...@@ -8,6 +8,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.util.Scanner;
public class Application implements Watcher public class Application implements Watcher
{ {
...@@ -21,12 +22,16 @@ public class Application implements Watcher ...@@ -21,12 +22,16 @@ public class Application implements Watcher
public static void main(String[] args) throws IOException, InterruptedException, KeeperException { public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
/*int currentServerPort = args.length == 3 ? Integer.parseInt(args[0]) : DEFAULT_PORT; /*String IP = args.length == 1 ? args[0] : "127.0.0.1:55451";
numberOfInstances = args.length == 3 ? Integer.parseInt(args[1]) : 4; int port = Integer.parseInt(IP.split(":")[1]);*/
String IP = args.length == 3 ? args[2] : "M_Salameh@127.0.0.1";*/
String IP = args.length == 1 ? args[0] : "127.0.0.1:55451";
int port = Integer.parseInt(IP.split(":")[1]);
Scanner scanner = new Scanner(System.in);
System.out.println("Enter Port !!");
String IP = "127.0.0.1";
int port = scanner.nextInt();
System.out.println("IP is : " + IP );
System.out.println("Port is : " + port);
Application application = new Application(); Application application = new Application();
ZooKeeper zooKeeper = application.connectToZookeeper(); ZooKeeper zooKeeper = application.connectToZookeeper();
...@@ -35,7 +40,7 @@ public class Application implements Watcher ...@@ -35,7 +40,7 @@ public class Application implements Watcher
OnElectionAction onElectionAction = new OnElectionAction(serviceRegistry, port); OnElectionAction onElectionAction = new OnElectionAction(serviceRegistry, port);
LeaderElection leaderElection = new LeaderElection(zooKeeper, onElectionAction); LeaderElection leaderElection = new LeaderElection(zooKeeper, onElectionAction);
leaderElection.volunteerForLeadership(IP); leaderElection.volunteerForLeadership(IP+":"+port);
leaderElection.reelectLeader(); leaderElection.reelectLeader();
application.run(); application.run();
......
...@@ -12,8 +12,12 @@ import org.slf4j.LoggerFactory; ...@@ -12,8 +12,12 @@ import org.slf4j.LoggerFactory;
import java.io.*; import java.io.*;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*; import java.util.*;
import java.util.concurrent.*; import java.util.concurrent.*;
import java.util.stream.Stream;
public class Coordinator public class Coordinator
{ {
...@@ -32,7 +36,7 @@ public class Coordinator ...@@ -32,7 +36,7 @@ public class Coordinator
this.zooKeeper = zooKeeper; this.zooKeeper = zooKeeper;
COORDINATOR_PORT = Integer.parseInt(SOCKET.split(":")[1]); COORDINATOR_PORT = Integer.parseInt(SOCKET.split(":")[1]);
FILES_DIRECTORY = System.getProperty(("user.dir") + "/SearchFiles"); FILES_DIRECTORY = System.getProperty("user.dir") + "/SearchFiles/";
} }
...@@ -60,6 +64,7 @@ public class Coordinator ...@@ -60,6 +64,7 @@ public class Coordinator
String query; String query;
System.out.println("Enter Query To Search : "); System.out.println("Enter Query To Search : ");
query = scanner.nextLine(); query = scanner.nextLine();
System.out.println("Query = " + query);
Thread clientThread = new Thread(() -> Thread clientThread = new Thread(() ->
{ {
SearchQueryResponse searchQueryResponseMap = handleClient(query); SearchQueryResponse searchQueryResponseMap = handleClient(query);
...@@ -97,7 +102,8 @@ public class Coordinator ...@@ -97,7 +102,8 @@ public class Coordinator
} catch (IOException | ClassNotFoundException e) { } catch (IOException | ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
System.out.println("Printing Search Query Response");
System.out.println(searchQueryResponse);
return searchQueryResponse; return searchQueryResponse;
} }
...@@ -164,19 +170,12 @@ public class Coordinator ...@@ -164,19 +170,12 @@ public class Coordinator
private int countFilesInDirectory() private int countFilesInDirectory()
{ {
File directory = new File(FILES_DIRECTORY); try (Stream<Path> files = Files.list(Paths.get(FILES_DIRECTORY)))
File[] files = directory.listFiles(); {
return (int) files.count();
int fileCount = 0; } catch (IOException e) {
if (files != null) { throw new RuntimeException(e);
for (File file : files) {
if (file.isFile()) {
fileCount++;
}
}
} }
return fileCount;
} }
...@@ -194,6 +193,7 @@ public class Coordinator ...@@ -194,6 +193,7 @@ public class Coordinator
int totalFilesNumber = countFilesInDirectory(); int totalFilesNumber = countFilesInDirectory();
System.out.println("Files Number = " + totalFilesNumber);
int filesNumberforNode = (totalFilesNumber + physicalZnodes.size()-1)/physicalZnodes.size(); int filesNumberforNode = (totalFilesNumber + physicalZnodes.size()-1)/physicalZnodes.size();
int remaining = totalFilesNumber; int remaining = totalFilesNumber;
int index = 0; int index = 0;
......
...@@ -41,7 +41,8 @@ public class TransientWorker ...@@ -41,7 +41,8 @@ public class TransientWorker
public TransientWorker (String SOCKET) throws IOException { public TransientWorker (String SOCKET) throws IOException {
CLUSTER_PORT =Integer.parseInt(SOCKET.split(":")[1]); CLUSTER_PORT =Integer.parseInt(SOCKET.split(":")[1]);
filesLocation = System.getProperty("user.dir") + "/SearchFiles"; filesLocation = System.getProperty("user.dir") + "/SearchFiles/";
System.out.println("FL = " + filesLocation);
connectToZookeeper(); connectToZookeeper();
} }
public void connectToZookeeper() throws IOException { public void connectToZookeeper() throws IOException {
...@@ -117,7 +118,7 @@ public class TransientWorker ...@@ -117,7 +118,7 @@ public class TransientWorker
Files.newDirectoryStream(Paths.get(filesLocation))) { Files.newDirectoryStream(Paths.get(filesLocation))) {
for (Path file : stream) { for (Path file : stream) {
if (Files.isRegularFile(file)) { if (Files.isRegularFile(file)) {
fileNames.add(file.getFileName().toString()); fileNames.add(filesLocation+file.getFileName().toString());
} }
} }
} catch (IOException e) } catch (IOException e)
...@@ -138,6 +139,10 @@ public class TransientWorker ...@@ -138,6 +139,10 @@ public class TransientWorker
searchQueryResponse.setWordFrequencies searchQueryResponse.setWordFrequencies
(WordsCountingInFiles.countWordsInFiles(words , myFiles)); (WordsCountingInFiles.countWordsInFiles(words , myFiles));
if(searchQueryResponse.getWordFrequencies().size() == 0)
{
System.out.println("Problem in Counting Words in Files");
}
return searchQueryResponse; return searchQueryResponse;
} }
} }
......
package ObjectExchangeInCluster; package ObjectExchangeInCluster;
public class FileWordPair import java.io.Serializable;
public class FileWordPair implements Serializable
{ {
public String fileName; public String fileName;
public long freq; public long freq;
......
...@@ -9,6 +9,7 @@ import java.nio.file.Files; ...@@ -9,6 +9,7 @@ import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.*; import java.util.*;
import java.util.stream.Stream;
public class test public class test
{ {
...@@ -62,6 +63,15 @@ public class test ...@@ -62,6 +63,15 @@ public class test
} }
} }
private static int countFilesInDirectory()
{
try (Stream<Path> files = Files.list(Paths.get(System.getProperty("user.dir") + "/SearchFiles/")))
{
return (int) files.count();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static Map<String, List<FileWordPair>> countWordOccurrences(List<String> words, List<String> filePaths) public static Map<String, List<FileWordPair>> countWordOccurrences(List<String> words, List<String> filePaths)
{ {
Map<String, List<FileWordPair>> wordOccurrences = new HashMap<>(); Map<String, List<FileWordPair>> wordOccurrences = new HashMap<>();
...@@ -109,6 +119,7 @@ public class test ...@@ -109,6 +119,7 @@ public class test
public static void main(String[] args) public static void main(String[] args)
{ {
///listFilesForFolder(System.getProperty("user.dir") + "/SearchFiles"); ///listFilesForFolder(System.getProperty("user.dir") + "/SearchFiles");
countWordsInFiles(); ///countWordsInFiles();
System.out.println(countFilesInDirectory());
} }
} }
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