Commit 552d0700 authored by abdullh.alsoleman's avatar abdullh.alsoleman

last_commit

parent a6915636
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="bf5af6ac-395d-482c-b7ee-2acf3d1efc46" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/encodings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/WebClient/index.html" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/ClientHttp.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2bdp20AbtdMmnErAkdLTlTymbPF" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"last_opened_file_path": "C:/Users/Abdullah/Downloads/network-communication-master/HTTP_Client"
}
}]]></component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="C:\Users\Abdullah\Downloads\network-communication-master\HTTP_Client\src\main\WebClient" />
</key>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="bf5af6ac-395d-482c-b7ee-2acf3d1efc46" name="Changes" comment="" />
<created>1706554653280</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1706554653280</updated>
</task>
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
</project>
\ No newline at end of file
......@@ -5,32 +5,20 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>Service-Registration-and-Discovery</artifactId>
<artifactId>HTTP_Client</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.5</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.9.1</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTTP Client</title>
<style>
/* Add your CSS styles here */
body {
background: linear-gradient(to right, #091228, #141d20);
background-image: url("https://coinsult.net/wp-content/uploads/2022/10/bgf-224.png");
color: #eaecef;
font-family: Sans-serif;
}
h1 {
font-size: 3rem;
}
* {
box-sizing: border-box;
}
.main-wrapper {
max-width: 1000px;
margin: 4rem auto;
padding: 2rem;
@media (max-width: 768px) {
padding: 2rem 1rem;
}
}
.grey-round {
background: #181a20;
border-radius: 10px;
border: none;
outline: none;
color: white;
padding: 1em;
font-size: 1.05rem;
}
.button {
background: linear-gradient(90deg, #368d74 0%, #1e7b8e 100%);
border: none;
padding: 0.8rem 1.5rem 0.7rem 1.5rem;
display: flex;
color: white;
border-radius: 4rem;
text-decoration: none;
line-height: 1em;
align-items: center;
transition: all 0.2s;
&:hover {
opacity: 0.8;
cursor: pointer;
}
&.grey {
background: #3a3a3a;
font-weight: bold;
padding: 0.6rem 0.6rem 0.5rem 0.6rem;
font-size: 0.85rem;
}
}
.search {
position: relative;
margin: 1rem 0;
input {
width: 100%;
}
.button {
position: absolute;
top: 0;
right: 0;
bottom: 0;
border-radius: 0 10px 10px 0;
padding: 0.75rem 1.25rem;
}
}
#output {
margin-top: 2rem;
}
.results {
margin: 1rem -1rem;
display: grid;
grid-template-columns: 1fr 1fr;
@media (max-width: 980px) {
grid-template-columns: 1fr;
}
.project {
margin: 1rem 1rem;
display: flex;
flex-direction: row;
align-items: center;
@media (max-width: 768px) {
padding: 1rem 0.75rem;
}
img {
width: 3rem;
height: 3rem;
border-radius: 100%;
margin-right: 1rem;
}
.title {
flex: 1;
font-size: 1.3rem;
font-weight: bold;
@media (max-width: 768px) {
font-size: 1rem;
word-break: break-all;
}
}
.score {
margin-left: 1rem;
font-size: 1rem;
}
.button {
margin-left: 0.75rem;
}
}
}
.no-results {
padding: 0 1rem;
text-align: center;
}
</style>
</head>
<body>
<div class="main-wrapper">
<h1>Projects</h1>
<div class="search">
<input type="text" class="grey-round" autocomplete="off" placeholder="Search projects..." id="inputString" />
<button class="button" onclick="executeSearch()">
<svg width="1.5rem" height="1.5rem" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="10" cy="10" r="6" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
<path d="M14.5 14.5L19 19" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
</svg>
</button>
</div>
<div id="output" class="results"></div>
</div>
<script>
function executeSearch() {
// Replace with your server URL
var serverUrl = "http://localhost:7777/search";
// Get the input string from the user
var inputString = document.getElementById("inputString").value;
// Create a request URL with the input string
var requestUrl = serverUrl + "?inputString=" + encodeURIComponent(inputString);
// Use Fetch API to make the request
fetch(requestUrl)
.then(response => {
// Check if the request was successful (status code 200)
if (response.ok) {
return response.json();
} else {
throw new Error("Error: " + response.status);
}
})
.then(outputMap => {
// Display the results with filename and score
var outputHtml = '';
// Check if outputMap is an object
if (outputMap && typeof outputMap === 'object') {
for (var filename in outputMap) {
if (outputMap.hasOwnProperty(filename)) {
var score = outputMap[filename];
outputHtml += `<div class="grey-round project">
<span class="title">${filename}</span>
<span class="score">Score: ${score}</span>
</div><br>`;
}
}
} else {
// Handle the case where outputMap is not an object
outputHtml = '<p>No projects found...</p>';
}
// Append the results to the existing content in the output div
document.getElementById("output").innerHTML += outputHtml;
})
.catch(error => {
document.getElementById("output").innerHTML = "Error: " + error.message;
});
}
</script>
</body>
</html>
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.Map;
import java.util.TreeMap;
public class ClientHttp {
public static void main(String[] args) {
try {
// Replace with your server URL
String serverUrl = "http://localhost:7777/search";
// Replace with your input string
String inputString = "the_car";
// Create a request object with the input string
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(serverUrl + "?inputString=" + inputString))
.build();
// Create an HTTP client
HttpClient httpClient = HttpClient.newHttpClient();
// Send the request and get the response
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
// Check if the request was successful (status code 200)
if (response.statusCode() == 200) {
// Parse the JSON response into a TreeMap
ObjectMapper objectMapper = new ObjectMapper();
Map<String, Double> outputMap = objectMapper.readValue(response.body(), TreeMap.class);
// Use the outputMap as needed
System.out.println("Received TreeMap from server: " + outputMap);
} else {
System.out.println("Error: " + response.statusCode() + ", " + response.body());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17 (2)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -29,11 +29,19 @@
<change afterPath="$PROJECT_DIR$/src/main/java/Zookeeper/OnElectionAction.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/Zookeeper/OnElectionCallback.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/Zookeeper/ServiceRegistry.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/file1.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/file2.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/file3.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/file4.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/file5.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/grpc/server/grpcServer.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/proto/Search.proto" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/META-INF/MANIFEST.MF" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/files/file1.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/files/file10.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/files/file2.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/files/file3.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/files/file4.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/files/file5.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/files/file6.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/files/file7.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/files/file8.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/files/file9.txt" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/logback.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
......@@ -54,29 +62,36 @@
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProblemsViewState">
<option name="selectedTabId" value="CurrentFile" />
</component>
<component name="ProjectId" id="2bAGyJ84QDiRIUvnsCkECWwzYqo" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;C:/Users/Abdullah/Downloads/network-communication-master/Cordinator_Worker/src/main/resources&quot;,
&quot;project.structure.last.edited&quot;: &quot;Artifacts&quot;,
&quot;project.structure.proportion&quot;: &quot;0.0&quot;,
&quot;project.structure.side.proportion&quot;: &quot;0.0&quot;
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"last_opened_file_path": "C:/Users/Abdullah/Downloads/network-communication-master/HTTP_Client",
"project.structure.last.edited": "Modules",
"project.structure.proportion": "0.0",
"project.structure.side.proportion": "0.2"
}
}</component>
}]]></component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\Abdullah\Downloads\network-communication-master\Cordinator_Worker\src\main\resources" />
<recent name="C:\Users\Abdullah\Downloads\network-communication-master\Cordinator_Worker\src\main" />
<recent name="C:\Users\Abdullah\Downloads\network-communication-master\Cordinator_Worker\src\main\java" />
<recent name="C:\Users\Abdullah\Downloads\network-communication-master\Cordinator_Worker\src\main\java\Zookeeper" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="C:\Users\Abdullah\Downloads\network-communication-master\Cordinator_Worker\src\main\resources\files" />
</key>
<key name="MoveClassesOrPackagesDialog.RECENTS_KEY">
<recent name="" />
</key>
......@@ -84,25 +99,50 @@
<recent name="" />
</key>
</component>
<component name="RunManager" selected="Application.Application">
<configuration name="Application" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<component name="RunAnythingCache">
<option name="myCommands">
<command value="mvn clean" />
<command value="mvn clean install" />
</option>
</component>
<component name="RunManager" selected="Application.worker2">
<configuration name="worker1" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="Application" />
<module name="Cordinator_Worker" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="Main" />
<configuration name="worker2" type="Application" factoryName="Application" temporary="true">
<option name="MAIN_CLASS_NAME" value="Application" />
<module name="Cordinator_Worker" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="worker3" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="Application" />
<module name="Cordinator_Worker" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="worker4" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="Application" />
<module name="Cordinator_Worker" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<list>
<item itemvalue="Application.worker1" />
<item itemvalue="Application.worker3" />
<item itemvalue="Application.worker4" />
<item itemvalue="Application.worker2" />
</list>
<recent_temporary>
<list>
<item itemvalue="Application.Application" />
<item itemvalue="Application.Main" />
<item itemvalue="Application.worker2" />
</list>
</recent_temporary>
</component>
......@@ -128,4 +168,25 @@
</map>
</option>
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/Coordinator_Worker/Coordinator.java</url>
<line>63</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/Coordinator_Worker/Worker.java</url>
<line>34</line>
<option name="timeStamp" value="2" />
</line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/Zookeeper/ServiceRegistry.java</url>
<line>89</line>
<option name="timeStamp" value="3" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>
\ No newline at end of file
2024-02-01 16:36:22,144 INFO Coordinator_Worker.Worker [Thread-0] Received data from coordinator: the car , [file1.txt, file10.txt, file2.txt, file3.txt, file4.txt, file5.txt, file6.txt, file7.txt, file8.txt, file9.txt]
2024-02-01 16:36:24,151 INFO Coordinator_Worker.Worker [Thread-0] Waiting Request at port: 8888
2024-02-01 16:36:27,145 INFO grpc.server.grpcServer [pool-4-thread-1] The Response which send by gRPC: {file1.txt=0.6081723552157728, file10.txt=0.6081723552157728, file2.txt=0.6081723552157728, file3.txt=0.6081723552157728, file4.txt=0.6081723552157728, file5.txt=0.6081723552157728, file6.txt=2.0794415416798357, file7.txt=2.0794415416798357, file8.txt=2.0794415416798357, file9.txt=2.0794415416798357}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>Service-Registration-and-Discovery</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.2</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.18.1:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.42.1:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.9.1</version>
</dependency>
<!-- gRPC dependencies -->
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
<version>1.53.0</version> <!-- Use the latest version available -->
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>1.53.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>1.53.0</version>
</dependency>
<!-- Protocol Buffers (protobuf) dependencies -->
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.22.2</version> <!-- Use the latest version available -->
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
<version>1.53.0</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version> <!-- Use the latest version available -->
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -2,13 +2,13 @@ import Zookeeper.LeaderElection;
import Zookeeper.OnElectionAction;
import Zookeeper.ServiceRegistry;
import ch.qos.logback.classic.Logger;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Scanner;
public class Application implements Watcher {
......@@ -18,12 +18,14 @@ public class Application implements Watcher {
private static final int DEFAULT_PORT = 8080;
private ZooKeeper zooKeeper;
public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
public static void main(String[] args) throws Exception {
// if (args.length != 3) {
// logger.error("Expecting parameters <port number> <number of workers> <path to worker jar file>");
// System.exit(1);
// }
int currentServerPort = args.length == 1 ? Integer.parseInt(args[0]) : DEFAULT_PORT;
Scanner input = new Scanner(System.in);
System.out.println("Enter the port of this node");
int currentServerPort = input.nextInt();
Application application = new Application();
ZooKeeper zooKeeper = application.connectToZookeeper();
......
......@@ -7,21 +7,36 @@ import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue;
public class Communication {
// Method to send data to the specified socket
public static void sendData(Socket socket, String dataString, List<String> fileNames) throws IOException {
ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
// Create and send a DataObject containing dataString and fileNames
objectOutputStream.writeObject(new DataObject(dataString, fileNames));
}
// Method to receive a result as a ConcurrentLinkedQueue<Document> from the specified socket
public static ConcurrentLinkedQueue<Document> receiveResult(Socket socket) throws IOException, ClassNotFoundException {
ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream());
return (ConcurrentLinkedQueue <Document>) objectInputStream.readObject();
// Read and return the result as a ConcurrentLinkedQueue<Document>
return (ConcurrentLinkedQueue<Document>) objectInputStream.readObject();
}
// Method to receive a DataObject from the specified socket
public static DataObject receiveData(Socket socket) throws IOException, ClassNotFoundException {
ObjectInputStream objectInputStream = new ObjectInputStream(socket.getInputStream());
// Read and return the received DataObject
return (DataObject) objectInputStream.readObject();
}
// Method to send a ConcurrentLinkedQueue<Document> as a result to the specified socket
public static void sendResult(Socket socket, ConcurrentLinkedQueue<Document> response) throws IOException {
ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
// Send the result as a ConcurrentLinkedQueue<Document>
objectOutputStream.writeObject(response);
}
}
......@@ -13,80 +13,103 @@ import java.util.*;
import java.util.concurrent.*;
public class Coordinator {
private static final int PORT = 12363;
public static void startCoordinator() {
// Method to start the coordinator and coordinate the processing
public static TreeMap<String, Double> startCoordinator(String dataString) {
// Data structures to store results
ConcurrentLinkedQueue<Document> workersResult = new ConcurrentLinkedQueue<>();
try {
String dataString = "the car";
TreeMap<String, Double> IDF = new TreeMap<>();
try {
// Split data string into terms
String[] parts = dataString.split("\\s");
List<Term> terms = new ArrayList<>();
for (String part : parts) {
terms.add(new Term(part));
}
// Response data structure
TreeMap<String, Double> response = new TreeMap<>();
List<String> fileNames = getFileNamesInDirectory("src/main/resources");
// Get file names in the specified directory
List<String> fileNames = getFileNamesInDirectory("src/main/resources/files");
// Calculate the number of files each worker should handle
int eachWorkerFiles = fileNames.size() / ServiceRegistry.getWorkers().size();
int mode = fileNames.size() % ServiceRegistry.getWorkers().size();
int index = 0;
// Thread pool to manage worker threads
ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
for (Worker worker : ServiceRegistry.getWorkers()) {
List<String> workerFilesList = new ArrayList<>();
for (int i = 0; i < eachWorkerFiles; i++) {
workerFilesList.add(fileNames.get(index));
index++;
if (mode != 0) {
if (index != fileNames.size()) {
workerFilesList.add(fileNames.get(index));
index++;
// Check if workers are available
if (ServiceRegistry.getWorkers() != null) {
for (Worker worker : ServiceRegistry.getWorkers()) {
// Prepare the list of files to be processed by the worker
List<String> workerFilesList = new ArrayList<>();
for (int i = 0; i < eachWorkerFiles; i++) {
workerFilesList.add(fileNames.get(index));
index++;
// Handle the remaining files if any and the mode is not zero
if (mode != 0) {
if (index != fileNames.size()) {
workerFilesList.add(fileNames.get(index));
index++;
}
}
}
// Connect to the worker
Socket workerSocket = new Socket(worker.getIpAddress(),worker.getPort() );
// Create a CoordinatorHandler instance for each worker
Runnable task = () -> processRequest(workerSocket, workerFilesList, dataString, workersResult);
// Start the CoordinatorHandler thread
executorService.submit(task);
}
// Connect to worker
Socket workerSocket = new Socket("127.0.0.1", PORT);
// Create a CoordinatorHandler instance for each worker
Runnable task = () -> processRequest(workerSocket, workerFilesList, dataString, workersResult);
// Start the CoordinatorHandler thread
executorService.submit(task);
}
executorService.awaitTermination(5, TimeUnit.SECONDS);
for (int i = 0; i < terms.size(); i++) {
// Wait for all worker threads to finish
executorService.awaitTermination(5, TimeUnit.SECONDS);
// Process results to calculate Term Frequency (TF)
for (int i = 0; i < terms.size(); i++) {
for (Document document : workersResult) {
Map<String, Double> tf = document.getTf();
if (tf.get(terms.get(i).getTermName()) > 0) {
terms.get(i).increase();
}
}
}
// Set terms and calculate IDF for each document
for (Document document : workersResult) {
Map<String, Double> tf = document.getTf();
if (tf.get(terms.get(i).getTermName()) > 0) ;
terms.get(i).increase();
document.setTerms(terms);
document.CalculateIDF(fileNames.size());
IDF.put(document.getName(), document.getIDF());
}
}
TreeMap<String, Double> IDF = new TreeMap<>();
for (Document document : workersResult) {
document.setTerms(terms);
document.CalculateIDF(fileNames.size());
IDF.put(document.getName(), document.getIDF());
// Shutdown the executor service
executorService.shutdown();
}
System.out.println("IDF Files: " + IDF);
executorService.shutdown();
} catch (UnknownHostException e) {
// Handle unknown host exception
throw new RuntimeException(e);
} catch (IOException e) {
// Handle IO exception
throw new RuntimeException(e);
} catch (InterruptedException e) {
// Handle interrupted exception
throw new RuntimeException(e);
}finally {
} finally {
// Return the calculated IDF values
return IDF;
}
}
// Method to get file names in the specified directory
public static List<String> getFileNamesInDirectory(String directoryPath) {
try {
// Create a Path object for the specified directory
......@@ -113,9 +136,9 @@ public class Coordinator {
}
}
// Method to process requests from workers
private static void processRequest(Socket clientSocket, List<String> fileNames,
String dataString, ConcurrentLinkedQueue<Document> documents) {
try {
// Send data to worker
Communication.sendData(clientSocket, dataString, fileNames);
......@@ -123,13 +146,16 @@ public class Coordinator {
// Receive results from worker
ConcurrentLinkedQueue<Document> d = Communication.receiveResult(clientSocket);
documents.addAll(d);
// Close the client socket
clientSocket.close();
} catch (IOException e) {
// Handle IO exception
e.printStackTrace();
} catch (ClassNotFoundException e) {
// Handle class not found exception
throw new RuntimeException(e);
}
}
}
......@@ -3,19 +3,23 @@ package Coordinator_Worker;
import java.io.Serializable;
import java.util.List;
// Serializable class to represent the data being sent between Coordinator and Worker
class DataObject implements Serializable {
private String dataString;
private List<String> fileNames;
private String dataString; // String data to be processed
private List<String> fileNames; // List of file names associated with the data
// Constructor to initialize DataObject with dataString and fileNames
public DataObject(String dataString, List<String> fileNames) {
this.dataString = dataString;
this.fileNames = fileNames;
}
// Getter method to retrieve the dataString
public String getDataString() {
return dataString;
}
// Getter method to retrieve the list of file names
public List<String> getFileNames() {
return fileNames;
}
......
......@@ -6,40 +6,49 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
// Serializable class to represent a document with term frequency (TF) and inverse document frequency (IDF)
public class Document implements Serializable {
private String name;
private Map<String,Double> tf=new HashMap<>();
private List<Term> terms;
private Double IDF=0.0;
public Document(String name)
{
private String name; // Name of the document
private Map<String, Double> tf = new HashMap<>(); // Term Frequency (TF) for each term in the document
private List<Term> terms; // List of terms in the document
private Double IDF = 0.0; // Inverse Document Frequency (IDF) for the document
// Constructor to initialize a Document with a name
public Document(String name) {
this.name = name;
this.terms = new ArrayList<>(); // Initialize the terms list
this.terms = new ArrayList<>(); // Initialize the terms list
}
// Getter method to retrieve the name of the document
public String getName() {
return name;
}
// Getter method to retrieve the Term Frequency (TF) map for the document
public Map<String, Double> getTf() {
return tf;
}
// Setter method to set the terms for the document
public void setTerms(List<Term> terms) {
this.terms.addAll(terms);
}
public void setTf(String fileName, Double value ) {
this.tf.put(fileName,value);
// Setter method to set the Term Frequency (TF) for a specific term in the document
public void setTf(String termName, Double value) {
this.tf.put(termName, value);
}
// Getter method to retrieve the Inverse Document Frequency (IDF) for the document
public Double getIDF() {
return IDF;
}
public void CalculateIDF(int totalNumFiles){
for(int i=0; i < terms.size();i++) {
// Method to calculate the Inverse Document Frequency (IDF) for the document
public void CalculateIDF(int totalNumFiles) {
for (int i = 0; i < terms.size(); i++) {
Term term = terms.get(i);
IDF += Math.log(term.getNumOfFile() / totalNumFiles) * tf.get(term.getTermName());
IDF += Math.log(term.getNumOfFile() / (double) totalNumFiles) * tf.get(term.getTermName());
}
}
}
package Coordinator_Worker;
// Class to represent a term in a document with a count of occurrences
public class Term {
private String term;
private double numOfFile;
private String term; // The term itself
private double numOfFile; // The count of occurrences in files
// Constructor to initialize a Term with a term name
public Term(String term) {
this.term = term;
}
// Getter method to retrieve the count of occurrences in files
public double getNumOfFile() {
return numOfFile;
}
// Getter method to retrieve the term name
public String getTermName() {
return term;
}
public void increase(){
// Method to increase the count of occurrences in files
public void increase() {
numOfFile++;
}
}
package Coordinator_Worker;
import ch.qos.logback.classic.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.net.ServerSocket;
......@@ -9,34 +12,40 @@ import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
// Worker class representing a node that processes search requests from a coordinator
public class Worker {
private static final int PORT = 12363;
private static final Logger logger = (Logger) LoggerFactory.getLogger(Worker.class);
private String nodeName;
private String ipAddress;
private String userName;
public Worker(String fullPathNode) {
private int port;
// Constructor to initialize Worker with the full path of the node
public Worker(String fullPathNode,int port) {
this.nodeName = fullPathNode;
this.port=port;
}
public static void startWorker() {
// Method to start the Worker and listen for search requests
public static void startWorker(int port) {
ServerSocket serverSocket = null;
try {
// Step 1: Set up server socket to listen for connections
serverSocket = new ServerSocket(PORT);
serverSocket = new ServerSocket(port);
} catch (IOException e) {
throw new RuntimeException(e);
}
while (true) {
try {
System.out.println("Waiting Request");
logger.info("Waiting Request at port: "+port);
// Step 2: Accept connection from coordinator
Socket coordinatorSocket = serverSocket.accept();
// Step 3: Receive data from coordinator
DataObject data = Communication.receiveData(coordinatorSocket);
System.out.println("Received data from coordinator: " + data.getDataString() + ", " + data.getFileNames());
logger.info("Received data from coordinator: " + data.getDataString() + ", " + data.getFileNames());
// Step 4: Process the data using IDF algorithm
ConcurrentLinkedQueue<Document> response = new ConcurrentLinkedQueue<>();
......@@ -55,10 +64,9 @@ public class Worker {
}
}
// Function to calculate IDF for each term in the search query across files
private static ConcurrentLinkedQueue<Document> IDF(DataObject data) {
ConcurrentLinkedQueue<Document> documents=new ConcurrentLinkedQueue<>();
ConcurrentLinkedQueue<Document> documents = new ConcurrentLinkedQueue<>();
String searchQuery = data.getDataString();
String[] terms = searchQuery.split("\\s+");
......@@ -67,15 +75,15 @@ public class Worker {
try {
for (String fileName : data.getFileNames()) {
File file = new File("C:\\Users\\Abdullah\\Downloads\\network-communication-master\\Cordinator_Worker\\src\\main\\resources\\" + fileName);
Runnable task = () -> processFile(file, terms,documents);
File file = new File("C:\\Users\\Abdullah\\Downloads\\network-communication-master\\Cordinator_Worker\\src\\main\\resources\\files\\" + fileName);
Runnable task = () -> processFile(file, terms, documents);
executorService.submit(task);
}
executorService.awaitTermination(2, TimeUnit.SECONDS);
executorService.awaitTermination(2, TimeUnit.SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
//Step 5: Shutdown the ExecutorService
// Step 5: Shutdown the ExecutorService
executorService.shutdown();
}
......@@ -84,7 +92,7 @@ public class Worker {
}
// Function to process each file and calculate term frequencies
private static void processFile(File file, String[] terms,ConcurrentLinkedQueue<Document>documents) {
private static void processFile(File file, String[] terms, ConcurrentLinkedQueue<Document> documents) {
Document document = new Document(file.getName());
double totalWords = 0;
......@@ -102,7 +110,7 @@ public class Worker {
}
totalWords++;
}
Double d= frequency/totalWords;
Double d = frequency / totalWords;
document.setTf(term, d);
documents.offer(document);
}
......@@ -111,6 +119,8 @@ public class Worker {
// Handle file reading exception
}
}
// Getter and setter methods for ipAddress, userName, and nodeName
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
......@@ -138,4 +148,8 @@ public class Worker {
public String getUserName() {
return userName;
}
public int getPort() {
return port;
}
}
......@@ -29,7 +29,7 @@ public class LeaderElection implements Watcher {
this.currentZnodeName = znodeFullPath.replace(ELECTION_NAMESPACE + "/", "");
}
public void reelectLeader() throws InterruptedException, KeeperException {
public void reelectLeader() throws Exception {
String predecessorName = "";
Stat predecessorStat = null;
......@@ -41,6 +41,8 @@ public class LeaderElection implements Watcher {
String smallestChild = children.get(0); //the first element
if (smallestChild.equals(currentZnodeName)) {
System.out.println("I'm a leader");
String currentLeaderAddress = "127.0.0.1";
zooKeeper.setData(ELECTION_NAMESPACE+"/"+currentZnodeName,currentLeaderAddress.getBytes(),-1);
onElectionCallback.onElectedToBeLeader();
return;
......@@ -67,6 +69,8 @@ public class LeaderElection implements Watcher {
throw new RuntimeException(e);
} catch (KeeperException e) {
throw new RuntimeException(e);
} catch (Exception e) {
throw new RuntimeException(e);
}
break;
......
package Zookeeper;
import Coordinator_Worker.Coordinator;
import Coordinator_Worker.Worker;
import org.apache.zookeeper.KeeperException;
import grpc.server.grpcServer;
public class OnElectionAction implements OnElectionCallback {
......@@ -16,11 +15,18 @@ public class OnElectionAction implements OnElectionCallback {
}
@Override
public void onElectedToBeLeader() throws InterruptedException, KeeperException {
public void onElectedToBeLeader() {
serviceRegistry.unregisterFromCluster();
serviceRegistry.registerForUpdates();
Thread.sleep(30000);
Coordinator.startCoordinator();
Runnable task = ()-> {
try {
grpcServer.startGrpcServer();
} catch (Exception e) {
throw new RuntimeException(e);
}
};
Thread thread = new Thread(task);
thread.start();
}
@Override
......@@ -28,9 +34,9 @@ public class OnElectionAction implements OnElectionCallback {
try {
String username = System.getProperty("user.name");
String currentServerAddress =
"192.168.56.116"+","+username+"," +port;
"127.0.0.1"+","+username+"," +port;
serviceRegistry.registerToCluster(currentServerAddress);
Runnable task = ()->Worker.startWorker();
Runnable task = ()->Worker.startWorker(port);
Thread thread =new Thread(task);
thread.start();
} catch (InterruptedException e) {
......
......@@ -4,7 +4,7 @@ import org.apache.zookeeper.KeeperException;
public interface OnElectionCallback {
void onElectedToBeLeader() throws InterruptedException, KeeperException;
void onElectedToBeLeader() throws Exception;
void onWorker();
}
......@@ -79,7 +79,6 @@ public class ServiceRegistry implements Watcher {
Thread.sleep(100);
for (String workerZnode : workerZnodes) {
String workerFullPath = REGISTRY_ZNODE + "/" + workerZnode;
Worker newWorker = new Worker(workerZnode);
Stat stat = zooKeeper.exists(workerFullPath, false);
if (stat == null) {
continue;
......@@ -88,6 +87,8 @@ public class ServiceRegistry implements Watcher {
byte[] addressBytes = zooKeeper.getData(workerFullPath, false, stat);
String data = new String(addressBytes);
String[] parts = data.split(",");
Worker newWorker = new Worker(workerZnode,Integer.parseInt(parts[2]));
String address = parts[0];
newWorker.setIpAddress(address);
newWorker.setUserName(parts[1]);
......
package grpc.server;
import Coordinator_Worker.Coordinator;
import ch.qos.logback.classic.Logger;
import grpc.Request;
import grpc.Response;
import grpc.searchServiceGrpc;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.stub.StreamObserver;
import org.slf4j.LoggerFactory;
import java.util.*;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
public class grpcServer {
private static final Logger logger = (Logger) LoggerFactory.getLogger(grpcServer.class);
// Method to start the gRPC server
public static void startGrpcServer() throws Exception {
System.out.println("Starting gRPC Server");
// Create a gRPC server with the specified port and service implementation
Server server = ServerBuilder.forPort(8080)
.addService(new SearchServiceImpl())
.executor(Executors.newFixedThreadPool(10)) // Adjust the pool size as needed
.build();
// Start the gRPC server and wait for it to terminate
server.start();
server.awaitTermination();
}
// Implementation of the gRPC service
private static class SearchServiceImpl extends searchServiceGrpc.searchServiceImplBase {
// gRPC method to handle search requests asynchronously
@Override
public void search(Request request, StreamObserver<Response> responseObserver) {
// Use a separate thread or executor for handling each request asynchronously
Executors.newCachedThreadPool().submit(() -> {
try {
// Step 1: Retrieve Inverse Document Frequency (IDF) from Coordinator
TreeMap<String, Double> IDF = Coordinator.startCoordinator(request.getInput());
// Create a new TreeMap with a custom comparator for sorting by values in reverse order
TreeMap<String, Double> sortedIDF = new TreeMap<>(new Comparator<String>() {
@Override
public int compare(String key1, String key2) {
int valueCompare = IDF.get(key2).compareTo(IDF.get(key1));
return (valueCompare == 0) ? key1.compareTo(key2) : valueCompare;
}
});
// Put all entries from IDF into the sortedIDF TreeMap
sortedIDF.putAll(IDF);
//contain just the first 10 element from sortedIDF
TreeMap<String,Double> first10=new TreeMap<>();
int count=0;
for(Map.Entry<String,Double> entry: sortedIDF.entrySet()) {
if(count==10) break;
first10.put(entry.getKey(),entry.getValue());
count++;
}
// Step 2: Build the response with a TreeMap which Coordinator provides
Response.Builder responseBuilder = Response.newBuilder();
for (Map.Entry<String, Double> entry : first10.entrySet()) {
responseBuilder.putOutput(entry.getKey(), entry.getValue());
}
logger.info("The Response which send by gRPC: {}",first10);
Response response = responseBuilder.build();
// Step 3: Send the response to the client
responseObserver.onNext(response);
responseObserver.onCompleted();
} catch (Exception e) {
e.printStackTrace();
// Handle exceptions appropriately
}
});
}
}
}
syntax = "proto3";
option java_multiple_files = true;
option java_package = "grpc";
message Request {
string input = 1;
}
message Response {
map<double, string> output = 1;
}
service searchService {
rpc Search(Request) returns (Response);
}
Manifest-Version: 1.0
Main-Class: Application
fadfma the the fadfma the the fadfma the the fadfma the the fadfma the the fadfma the thev fadfma the the
fadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the the
fadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the the
fadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the the
fadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the thefadfma the the car
carcarcarcarcarcarcarcarcarcarcarcarcarcarcarcarcarcarcarcar car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""car ""
car ""
car ""car ""car ""
car ""
car ""car ""
car ""
car ""car ""
car ""
vcar ""
car ""car ""car ""car ""car ""v
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the
\ No newline at end of file
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the
\ No newline at end of file
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the
\ No newline at end of file
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the the
the the the the the the the the the the the the the the the the the the the the the the the the the the the the
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="HOME_LOG" value="logs/app.log"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${HOME_LOG}</file>
<append>true</append>
<immediateFlush>true</immediateFlush>
<encoder>
<pattern>%d %p %c{1.} [%t] %m%n</pattern>
</encoder>
</appender>
<!-- Log Level: ERROR, WARN, INFO, DEBUG, TRACE-->
<logger name="Zookeeper" level="DEBUG" additivity="false">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</logger>
<logger name="grpc.server" level="DEBUG" additivity="false">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</logger>
<logger name="Coordinator_Worker" level="DEBUG" additivity="false">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</logger>
<root level="error">
<appender-ref ref="FILE"/>
</root>
</configuration>
\ No newline at end of file
# Search_System
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17 (2)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="8e0dd0ec-08a8-43ba-a79e-5e132d3f95f4" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/encodings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/uiDesigner.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/HTTP/ServerHttp.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/grpc/client/grpcClient.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/proto/Search.proto" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/logback.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2bV9dIkzuzEvmwT84kGb293Sz1Z" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"last_opened_file_path": "C:/Users/Abdullah/Downloads/network-communication-master/Cordinator_Worker",
"project.structure.last.edited": "Modules",
"project.structure.proportion": "0.15",
"project.structure.side.proportion": "0.2"
}
}]]></component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\Abdullah\Downloads\network-communication-master\Server\src\main\resources" />
<recent name="C:\Users\Abdullah\Downloads\network-communication-master\Server\src\main\java" />
</key>
<key name="MoveFile.RECENT_KEYS">
<recent name="C:\Users\Abdullah\Downloads\network-communication-master\Server\src\main" />
</key>
</component>
<component name="RunAnythingCache">
<option name="myCommands">
<command value="mvn clean" />
<command value="mvn clean install" />
</option>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="8e0dd0ec-08a8-43ba-a79e-5e132d3f95f4" name="Changes" comment="" />
<created>1706289470107</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1706289470107</updated>
</task>
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/HTTP/ServerHttp.java</url>
<line>89</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>
\ No newline at end of file
2024-01-29 06:20:13,001 INFO grpc.Main [main-EventThread] Successfully connected to Zookeeper
2024-01-29 21:48:10,971 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-01-29 21:53:48,070 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-01-29 22:00:15,045 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-01-29 22:06:03,274 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 05:37:40,191 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 05:41:47,842 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 05:43:44,363 ERROR HTTP.ServerHttp [main-EventThread] Disconnected from Zookeeper
2024-02-01 06:09:58,302 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 06:25:02,102 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 06:29:04,505 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 06:32:29,476 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 06:32:34,702 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 06:33:11,152 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 06:33:35,724 ERROR HTTP.ServerHttp [main-EventThread] Disconnected from Zookeeper
2024-02-01 06:36:29,364 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 06:36:45,710 ERROR HTTP.ServerHttp [main-EventThread] Disconnected from Zookeeper
2024-02-01 06:38:04,586 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 06:38:27,241 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 06:47:04,385 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 07:07:52,852 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 07:17:53,935 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 07:18:34,110 ERROR HTTP.ServerHttp [main-EventThread] Disconnected from Zookeeper
2024-02-01 09:03:01,371 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 09:21:59,576 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 09:30:40,879 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 09:35:10,103 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 09:47:52,196 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 11:00:21,268 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 11:02:29,956 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 11:06:09,393 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 11:09:25,570 ERROR HTTP.ServerHttp [main-EventThread] Disconnected from Zookeeper
2024-02-01 12:05:02,797 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 12:35:17,171 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 13:03:31,095 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 13:04:21,016 ERROR HTTP.ServerHttp [main-EventThread] Disconnected from Zookeeper
2024-02-01 16:17:18,670 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 16:21:54,756 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 16:22:24,863 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
2024-02-01 16:33:19,416 INFO HTTP.ServerHttp [main-EventThread] Successfully connected to Zookeeper
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.anubhav</groupId>
<artifactId>grpc</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<lognet.grpc.version>4.7.1</lognet.grpc.version>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.9.1</version>
</dependency>
<dependency>
<groupId>io.github.lognet</groupId>
<artifactId>grpc-spring-boot-starter</artifactId>
<version>${lognet.grpc.version}</version>
</dependency>
</dependencies>
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.6.2</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.17.2:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.39.0:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package HTTP;
import ch.qos.logback.classic.Logger;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import grpc.client.grpcClient;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
public class ServerHttp implements Watcher {
private ZooKeeper zooKeeper;
private static final Logger logger = (Logger) LoggerFactory.getLogger(ServerHttp.class);
private static final String address = "192.168.56.115:2181";
private static final int SESSION_TIMEOUT = 3000; //dead client
private static grpcClient client;
public static void main(String[] args) throws IOException, InterruptedException, KeeperException {
ServerHttp serverHttp =new ServerHttp();
ZooKeeper zooKeeper = serverHttp.connectToZookeeper();
client= new grpcClient(zooKeeper);
// Create a simple HTTP server listening on port 8080
HttpServer server = HttpServer.create(new InetSocketAddress(7777), 0);
// Create a context for the "/search" path
server.createContext("/search", new SearchHandler());
// Start the server
server.start();
System.out.println("Server started on port 7777");
}
public ZooKeeper connectToZookeeper() throws IOException {
this.zooKeeper = new ZooKeeper(address, SESSION_TIMEOUT, this);
return zooKeeper;
}
public void run() throws InterruptedException {
synchronized (zooKeeper) {
zooKeeper.wait();
}
}
void close() throws InterruptedException {
this.zooKeeper.close();
}
@Override
public void process(WatchedEvent watchedEvent) {
switch (watchedEvent.getType()) {
case None:
if (watchedEvent.getState() == Watcher.Event.KeeperState.SyncConnected) {
logger.info("Successfully connected to Zookeeper");
} else if (watchedEvent.getState() == Watcher.Event.KeeperState.Disconnected) {
synchronized (zooKeeper) {
logger.error("Disconnected from Zookeeper");
zooKeeper.notifyAll();
}
} else if (watchedEvent.getState() == Watcher.Event.KeeperState.Closed) {
logger.error ("Closed Successfully");
}
break;
}
}
static class SearchHandler implements HttpHandler {
@Override
public void handle(HttpExchange exchange) throws IOException {
// Get the current date and time
LocalDateTime currentTime = LocalDateTime.now();
// Format the date and time if needed
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedTime = currentTime.format(formatter);
System.out.println(formattedTime+"- receive request");
TreeMap<String, String> queryParams = getQueryParams(exchange.getRequestURI());
// Retrieve input string from query parameters
String inputString = queryParams.get("inputString");
// get sorted files with IDF values from a Coordinator
String [] parts= inputString.split("_");
String dataString="";
for (String part:parts) {
dataString+=part+" ";
}
Map<String, Double> FilesWithIDF= client.startClient(dataString) ;
// Build JSON response
String jsonResponse = mapToJson(FilesWithIDF);
// Set response headers
exchange.getResponseHeaders()
.set("Content-Type", "application/json");
exchange.getResponseHeaders().set("Access-Control-Allow-Origin", "*");
exchange.getResponseHeaders().set("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
exchange.getResponseHeaders().set("Access-Control-Allow-Headers", "Content-Type");
exchange.sendResponseHeaders(200, jsonResponse.length());
// Send response body
try (OutputStream os = exchange.getResponseBody()) {
os.write(jsonResponse.getBytes());
}
}
}
// Helper method to convert a Map to a JSON string
private static String mapToJson(Map<String, Double> map) {
StringBuilder json = new StringBuilder("{");
for (Map.Entry<String, Double> entry : map.entrySet()) {
json.append("\"").append(entry.getKey()).append("\":").append(entry.getValue()).append(",");
}
if (json.length() > 1) {
json.setLength(json.length() - 1); // Remove trailing comma
}
json.append("}");
return json.toString();
}
// Helper method to extract query parameters from a URI
private static TreeMap<String, String> getQueryParams(java.net.URI uri) {
TreeMap<String, String> result = new TreeMap<>();
String query = uri.getQuery();
if (query != null) {
for (String param : query.split("&")) {
String[] pair = param.split("=");
if (pair.length > 1) {
try {
String key = java.net.URLDecoder.decode(pair[0], "UTF-8");
String value = java.net.URLDecoder.decode(pair[1], "UTF-8");
result.put(key, value);
} catch (java.io.UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
}
return result;
}
}
package grpc.client;
import grpc.searchServiceGrpc;
import grpc.Request;
import grpc.Response;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;
import org.checkerframework.checker.units.qual.Time;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
public class grpcClient implements Watcher {
private static final String ELECTION_NAMESPACE = "/election";
private ZooKeeper zooKeeper;
private String leaderIP;
// Method to start the gRPC client
public grpcClient(ZooKeeper zooKeeper) throws InterruptedException, KeeperException {
this.zooKeeper = zooKeeper;
this.getLeaderIP();
}
private void getLeaderIP() throws InterruptedException, KeeperException {
List<String> children= zooKeeper.getChildren(ELECTION_NAMESPACE,this);
Collections.sort(children);
String leader = children.get(0);
Stat state = zooKeeper.exists(ELECTION_NAMESPACE+"/"+leader,false);
byte[] ipBytes= zooKeeper.getData(ELECTION_NAMESPACE+"/"+leader,false,state);
leaderIP= new String(ipBytes);
}
public Map<String,Double> startClient(String searchQuery) {
// Step 1: Create a gRPC channel to connect to the server
ManagedChannel channel = ManagedChannelBuilder.forAddress(leaderIP, 8080)
.usePlaintext() // For simplicity, using plaintext communication. In production, consider using TLS.
.build();
// Step 2: Create a blocking stub for the search service
searchServiceGrpc.searchServiceBlockingStub searchServiceStub = searchServiceGrpc.newBlockingStub(channel);
// Step 3: Create a request with the input string
Request request = Request.newBuilder().setInput(searchQuery).build();
// Step 4: Make the RPC call and receive the response
Response response = searchServiceStub.search(request);
TreeMap<String,Double> result= new TreeMap<>(new Comparator<String>() {
@Override
public int compare(String key1, String key2) {
int valueCompare = response.getOutputMap().get(key2).compareTo(response.getOutputMap().get(key1));
return (valueCompare == 0) ? key1.compareTo(key2) : valueCompare;
}
});;
result.putAll(response.getOutputMap());
// Step 5: Process the response
// Get the current date and time
LocalDateTime currentTime = LocalDateTime.now();
// Format the date and time if needed
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedTime = currentTime.format(formatter);
System.out.println( formattedTime + "- Result gRPC= " + result);
// Step 6: Shutdown the gRPC channel
channel.shutdown();
return result;
}
@Override
public void process(WatchedEvent watchedEvent) {
}
}
syntax = "proto3";
option java_multiple_files = true;
option java_package = "grpc";
message Request {
string input = 1;
}
message Response {
map<string, double> output = 1;
}
service searchService {
rpc Search(Request) returns (Response);
}
......@@ -17,7 +17,7 @@
</encoder>
</appender>
<!-- Log Level: ERROR, WARN, INFO, DEBUG, TRACE-->
<logger name="Zookeeper" level="DEBUG" additivity="false">
<logger name="HTTP" level="DEBUG" additivity="false">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</logger>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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