-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckClientStatus.java
More file actions
44 lines (37 loc) · 1.22 KB
/
Copy pathCheckClientStatus.java
File metadata and controls
44 lines (37 loc) · 1.22 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
package turing;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.TimerTask;
import turing.Message.RESULT;
public class CheckClientStatus extends TimerTask{
public void run() {
for (User u: Turing.databaseUsers.getUsers())
{
String user = u.getUsername();
SocketChannel client = Turing.databaseUsers.isOnline(user);
ByteBuffer b = ByteBuffer.allocate(1);
if (client != null) {
try {
client.configureBlocking(false);
int letti = client.read(b);
if (letti== -1){ //client è crashato
client.close(); //chiudo la socket
Turing.databaseUsers.setOffline(user); //imposto il client come offline
System.out.println(user+" chiuso in modo errato, impostato offline.");
/* controllo se stava modificando documenti,
* in tal caso li rendo disponibili per la modifica*/
for (Document d: Turing.databaseDocuments.getDocuments()){
for (Section s: d.getSections()){
if (s.endEdit(user) == RESULT.OP_OK)
System.out.println(d.getDocName()+"_"+s.getNumSec() + " disponibile per la modifica.");
}
}
}
} catch (IOException e){
e.printStackTrace();
}
}
}
}
}