-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatObserverImpl.java
More file actions
32 lines (25 loc) · 1.11 KB
/
ChatObserverImpl.java
File metadata and controls
32 lines (25 loc) · 1.11 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
import java.rmi.*;
import java.rmi.server.*;
/*
* Questa è la classe degli oggetti remoti Observer che estende la classe UnicastRemoteObject e implementa l'interfaccia Observer,
* quindi ne definisce il corpo dei metodi.
*/
class ChatObserverImpl extends UnicastRemoteObject implements Observer {
/**
*
*/
private static final long serialVersionUID = 1L;
// Il costruttore
protected ChatObserverImpl() throws RemoteException { }
// Il metodo update, ricevuto il messaggio da chi invoca il metodo (il Subject), stampa sullo stdout della macchina che ospita il processo Observer (client) il messaggio ricevuto
public void update(Object msg) throws RemoteException {
System.out.println("Received: " + msg);
}
// Eventuale variante
// Questa sarebbe l'update senza parametro e quindi c'è l'invocazione di getState su Subject per recuperare lo stato
// Sarebbe più complesso perché il Subject dovrebbe memorizzare tutte le stringhe, in questo caso ha solo uno stato apparente
/*
public void update() throws RemoteException {
System.out.println(subj.getState());
}*/
}