-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerStatus.java
More file actions
90 lines (78 loc) · 2.17 KB
/
ServerStatus.java
File metadata and controls
90 lines (78 loc) · 2.17 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
79
80
81
82
83
84
85
86
87
88
89
90
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
public class ServerStatus {
public final String ipAddress;
public final int port;
public final String uuid;
public long lastSeen = 0;
public long freeSpace;
public long occupiedSpace;
// Persistent connection to DataServer
private Socket socket;
private ObjectOutputStream oos;
public void setSocket(Socket socket) {
this.socket = socket;
}
public void setOos(ObjectOutputStream oos) {
this.oos = oos;
}
public void setOis(ObjectInputStream ois) {
this.ois = ois;
}
private ObjectInputStream ois;
private final Object connectionLock = new Object();
public ServerStatus(String ipAddress, int port, String uuid, long freeSpace, long occupiedSpace) {
this.ipAddress = ipAddress;
this.port = port;
this.uuid = uuid;
this.freeSpace = freeSpace;
this.occupiedSpace = occupiedSpace;
}
public Socket getSocket() {
synchronized (connectionLock) {
return socket;
}
}
public ObjectOutputStream getOos() {
synchronized (connectionLock) {
return oos;
}
}
public ObjectInputStream getOis() {
synchronized (connectionLock) {
return ois;
}
}
public Object getConnectionLock() {
return connectionLock;
}
public void closeConnection() {
synchronized (connectionLock) {
try {
if (ois != null) {
ois.close();
ois = null;
}
} catch (Exception e) {
// Ignore
}
try {
if (oos != null) {
oos.close();
oos = null;
}
} catch (Exception e) {
// Ignore
}
try {
if (socket != null) {
socket.close();
socket = null;
}
} catch (Exception e) {
// Ignore
}
}
}
}