-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChunkServer.java
More file actions
78 lines (58 loc) · 2.32 KB
/
Copy pathChunkServer.java
File metadata and controls
78 lines (58 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* Created and edited by: Sahil Pethe (ssp5329@g.rit.edu)
* Sukraat Ahluwalia (sxa4430@g.rit.edu)
*/
import java.io.*;
import java.net.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ChunkServer {
// the chunk server is the server connected to the master node and will get offloaded with
// files that the chunk server sends
// we use socket s to connect to a server
Socket s;
// datastream is used to stream data
DataInputStream din;
DataOutputStream dout;
PrintWriter pw;
ObjectInputStream ob_in;
static String eventManIP="129.21.22.196";
public ChunkServer() {
}
public static void main(String args[]) {
// we use this in case the initial IP address of the master node is different than the default one
if(args.length == 0){
//do nothing
}else{
eventManIP = args[0];
}
ChunkServer myc1 = new ChunkServer();
myc1.start_running();
}
public void start_running() {
try {
// this method initializes all the threads that need to run parallely in order for the different chunk server functions to work
new Thread(new ChunkServer_Heartbeat()).start();
s = new Socket(eventManIP, 8000);
//we print the user PC information
System.out.println(s);
//we close the connection in order to listen to it again
s.close();
// we create directories on the chunk server
if (!Files.isDirectory(Paths.get("cached_data"))) {
File dir = new File("cached_data");
dir.mkdir();
}
// all the necessary threads are initialized here
new Thread(new ChunkServerFileTransfer_receiving()).start();
new Thread(new ChunkServerFileTransfer_sending()).start();
new Thread(new ChunkServer_permissionListener()).start();
} catch (Exception e) {
e.printStackTrace();
}
}
}