This commit is contained in:
Lorenzo Iovino 2017-07-10 23:02:02 +02:00
parent 6b915932ae
commit dc206c0bb0
15 changed files with 1540 additions and 332 deletions

View file

@ -1,5 +1,7 @@
package com.texttwist.server.components;
import com.texttwist.client.App;
import interfaces.IAuth;
import interfaces.INotificationClient;
import models.Response;
import org.json.simple.JsonObject;
import utilities.Logger;
@ -9,6 +11,8 @@ import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.security.SecureRandom;
import static com.texttwist.server.Server.notificationServer;
/**
* Created by loke on 15/06/2017.
*/
@ -56,8 +60,10 @@ public class Auth extends UnicastRemoteObject implements IAuth {
}
@Override
public Response logout(String userName, String token) throws RemoteException {
public Response logout(String userName, String token, INotificationClient stub) throws RemoteException {
Logger.write("Invoked logout with username=" + userName + " AND " + " token=" + token);
notificationServer.unregisterForCallback(stub);
if ((userName != null && !userName.isEmpty()) && (token != null && !token.isEmpty())) {
boolean res = SessionsManager.getInstance().remove(userName);
if(res) {

View file

@ -10,6 +10,8 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import static com.texttwist.client.App.session;
/**
* Created by loke on 19/06/2017.
*/
@ -18,12 +20,13 @@ public class NotificationServer implements INotificationServer {
private List<INotificationClient> clients;
public NotificationServer() throws RemoteException {
super();
clients = new ArrayList<INotificationClient>();
clients = new ArrayList<>();
}
public synchronized void registerForCallback(INotificationClient clientInterface) throws RemoteException {
if(!clients.contains(clientInterface)){
clients.add(clientInterface);
System.out.println(clientInterface);
System.out.println("New client registered");
}
}
@ -49,7 +52,11 @@ public class NotificationServer implements INotificationServer {
client.sendInvite(username, users);
} catch (RemoteException e) {
System.out.println("Sembra down");
//unregisterForCallback(client);
try {
unregisterForCallback(client);
} catch (RemoteException e1) {
e1.printStackTrace();
}
}
}

View file

@ -1,4 +1,5 @@
package com.texttwist.server.components;
import interfaces.INotificationClient;
import models.Session;
import models.User;
@ -13,7 +14,6 @@ import java.util.List;
public class SessionsManager {
private List<Session> sessions = Collections.synchronizedList(new ArrayList<Session>());
private static class Holder {
static final SessionsManager INSTANCE = new SessionsManager();
}