small changes to factory and implemented rmi awareness with a simple register/deregister program

This commit is contained in:
2014-12-01 02:03:48 +01:00
parent 238c61f4d3
commit 1ef2207245
10 changed files with 190 additions and 2 deletions

View File

@@ -0,0 +1,44 @@
package rmi_Awareness;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Iterator;
import java.util.Vector;
/**
* Created by Giovanni on 01/12/2014.
*/
public class HelloImplemented extends UnicastRemoteObject implements HelloInterface, register_to_server {
public HelloImplemented () throws RemoteException{
v = new Vector<call_me_back>();
}
@Override
public String sayhello() throws RemoteException {
return "HI!";
}
@Override
public void register(call_me_back obj) throws RemoteException {
v.add(obj);
Iterator<call_me_back> it = v.iterator();
for (;it.hasNext();){
it.next().notify("Un nuovo utente si e' registrato");
}
}
@Override
public void deregister(call_me_back obj) throws RemoteException {
v.remove(obj);
Iterator<call_me_back> it = v.iterator();
for (;it.hasNext();){
it.next().notify("Un utente si e' cancellato ");
}
}
private Vector<call_me_back> v;
}