Skip to content
Snippets Groups Projects
Commit bbe2edae authored by tmp1u19's avatar tmp1u19 :octopus:
Browse files

Dstores can now join the Controller

parent 411ca5e6
Branches
Tags
No related merge requests found
import java.io.*; import java.io.*;
import java.net.*; import java.net.*;
import java.util.ArrayList;
import java.util.List;
public class Controller { public class Controller {
...@@ -20,24 +22,41 @@ public class Controller { ...@@ -20,24 +22,41 @@ public class Controller {
int rebalance_period = Integer.parseInt(args[3]); int rebalance_period = Integer.parseInt(args[3]);
System.out.println("Started"); System.out.println("Started");
List<Socket> ports = new ArrayList<>();
try { try {
ServerSocket socket = new ServerSocket(cport); ServerSocket socket = new ServerSocket(cport);
socket.setSoTimeout(10 * timeout);
for(;;) { for(;;) {
try { try {
if(R > 0) { if(R > 0) {
Socket client = socket.accept(); System.out.println("waiting for Dstore to join");
Socket client = socket.accept(); // establish a connection between client and server
System.out.print(R + ": ");
ports.add(client);
R = R - 1; R = R - 1;
} else {
BufferedReader in = new BufferedReader(
new InputStreamReader(client.getInputStream()));
String line;
while((line = in.readLine()) != null)
System.out.println(line + " received");
client.close();
} else {
break;
} }
} catch (Exception e1) { } catch (Exception e1) {
System.out.println(e1); System.out.println(e1);
} }
} }
/*
#TODO
- use threads to connect multiple clients to a server
*/
} catch (IOException e) { } catch (IOException e) {
System.out.println("error" + e); System.out.println("error" + e);
} }
......
import java.io.*;
import java.net.*;
public class Dstore { public class Dstore {
public static void main (String[] args) { public static void main (String[] args) {
...@@ -11,6 +14,23 @@ public class Dstore { ...@@ -11,6 +14,23 @@ public class Dstore {
// where to store the data locally // where to store the data locally
String file_folder = args[3]; String file_folder = args[3];
System.out.println("Adding"); InetAddress ip;
try {
ip = InetAddress.getLocalHost();
Socket socket = new Socket();
socket.connect(new InetSocketAddress(ip, cport), timeout);
for(;;) {
PrintWriter out = new PrintWriter(socket.getOutputStream());
out.println("adding Dstore");
out.flush();
System.out.println("Dstore was added");
Thread.sleep(1000);
}
} catch (Exception e) {
System.out.println("error " + e);
}
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment