forked from jonasagx/lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCentral.java
More file actions
71 lines (59 loc) · 1.38 KB
/
Copy pathCentral.java
File metadata and controls
71 lines (59 loc) · 1.38 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
import java.util.HashMap;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
/*
* Para a central cada departamento é apenas um IP (InetAddress)
*/
public class Central {
private HashMap<Integer, InetAddress> students = null;
private ServerSocket deps = null;
public Central(){
this.students = new HashMap<Integer, InetAddress>();
try {
this.deps = new ServerSocket(8080);
} catch (IOException e) {
e.printStackTrace();
}
}
public void listen(){
try {
Socket dep = this.deps.accept();
Processor p = new Processor(dep, this);
p.start();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public InetAddress whoIs(int student){
return this.students.get(students);
}
public void update(Student student){
this.students.put(student.getId(), student.getDep());
}
public void insert(Student student){
update(student);
}
public void insert(Student [] students){
for(Student s : students){
this.students.put(s.getId(), s.getDep());
}
System.out.println("Students addeds");
}
public void remove(Student student){
this.students.remove(student.getId());
}
}
class Processor extends Thread{
private Socket s;
private Central c;
public Processor(Socket s, Central c){
this.s = s;
this.c = c;
}
@Override
public void run(){
}
}