-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerRMI.java
More file actions
51 lines (40 loc) · 1.55 KB
/
ServerRMI.java
File metadata and controls
51 lines (40 loc) · 1.55 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
import java.io.IOException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
/**
* Server RMI che espone varie operazioni al client:
* -registrazione all'applicazione Worth
* -login sull'applicazione Worth
* -lista utenti registrati e il loro status on/off
* -verifica della registrazione di un utente all'applicazione Worth
* -registrazione al servizio RMI callback per la notifica della stato
* on/off degli utenti registrati
* -disiscrizione al servizio RMI callback di notifica
* -metodo per l'invio della notifica ai client registrati al servizio RMI callback
*/
public class ServerRMI {
/**
* porta utilizzata dal server di default
*/
private static final int PORT_DEFAULT = 5000;
public void start() throws IOException, NotBoundException{
int port = PORT_DEFAULT;
try {
EventManager eventManager = new EventManager();
// esporta l'oggetto
EventManagerInterface stub = (EventManagerInterface) UnicastRemoteObject.exportObject(eventManager, port);
// crea il registro
LocateRegistry.createRegistry(port);
Registry register = LocateRegistry.getRegistry(port);
// binding
register.rebind("EVENT_MANAGER", stub);
System.out.println("Server RMI è pronto");
}
catch (RemoteException e) {
e.printStackTrace();
}
}
}