Newer
Older
import ufrn.imd.controller.Controller;
import ufrn.imd.domain.Client;
import ufrn.imd.service.impl.DepositServiceImpl;
import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;
import static ufrn.imd.utils.NameSpace.HOST_DEPOSIT_SERVICE;
import static ufrn.imd.utils.NameSpace.PORT_DEPOSIT_SERVICE;
public class DepositControllerImpl extends UnicastRemoteObject implements Controller {
private volatile Queue<Client> clients = new ArrayDeque<>();
public DepositControllerImpl(DepositServiceImpl service) throws RemoteException, MalformedURLException, AlreadyBoundException {
log.info(String.format("Initializing server in %s", HOST_DEPOSIT_SERVICE));
LocateRegistry.createRegistry(PORT_DEPOSIT_SERVICE);
Naming.bind(HOST_DEPOSIT_SERVICE, this);
}
@Override
public void registerClient(Client client) throws RemoteException {
clients.add(client);
log.info("new client registred");
log.info(String.format("total users: %d", clients.size()));
private final DepositServiceImpl service;
public Notify(DepositServiceImpl service) {
super();
this.service = service;
}
public void run() {
for(;;) {
if(clients.size() > 0) {
log.info(String.format("Clients waiting %d", clients.size()));
this.service.deposit(200.00, Optional.of(client));
clients.remove();
log.info(String.format("Clients waiting %d", clients.size()));