Fixed EventProcessor and LoginCredentialProcessor

This commit is contained in:
Kai S. K. Engelbart 2020-01-18 09:55:12 +01:00
parent e35487e6f5
commit 387153bc6d
3 changed files with 16 additions and 16 deletions

View File

@ -6,6 +6,7 @@ import java.util.Set;
import com.jenkov.nioserver.Server;
import envoy.server.database.PersistenceManager;
import envoy.server.net.ObjectMessageProcessor;
import envoy.server.net.ObjectMessageReader;
import envoy.server.processors.EventProcessor;
@ -36,8 +37,11 @@ public class Startup {
processors.add(new LoginCredentialProcessor());
processors.add(new MessageProcessor());
processors.add(new EventProcessor());
// new PersistenceManager();
Server server = new Server(8080, () -> new ObjectMessageReader(), new ObjectMessageProcessor(processors));
// TODO: Prevent lazy DB initialization
PersistenceManager.getPersistenceManager();
server.start();
server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance());
}

View File

@ -20,9 +20,8 @@ import envoy.server.net.ObjectWriteProxy;
* @author Leon Hofmeister
* @since Envoy Server Standalone v0.1-alpha
*/
public class EventProcessor implements ObjectProcessor<Event<?>> {
private Event<?> event;
@SuppressWarnings("rawtypes")
public class EventProcessor implements ObjectProcessor<Event> {
/**
* Creates an instance of @link{EventProcessor}.
@ -31,15 +30,13 @@ public class EventProcessor implements ObjectProcessor<Event<?>> {
*/
public EventProcessor() {}
@SuppressWarnings("unchecked")
@Override
public Class<Event<?>> getInputClass() { return (Class<Event<?>>) event.getClass(); }
public Class<Event> getInputClass() { return Event.class; }
@Override
public void process(Event<?> input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
event = input;
if (event instanceof MessageStatusChangeEvent) try {
applyMessageStatusChange((MessageStatusChangeEvent) event, writeProxy);
public void process(Event input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
if (input instanceof MessageStatusChangeEvent) try {
applyMessageStatusChange((MessageStatusChangeEvent) input, writeProxy);
} catch (EnvoyException e) {
e.printStackTrace();
}
@ -71,7 +68,5 @@ public class EventProcessor implements ObjectProcessor<Event<?>> {
e.printStackTrace();
}
perMan.updateMessage(msg);
}
}

View File

@ -49,13 +49,14 @@ public class LoginCredentialProcessor implements ObjectProcessor<LoginCredential
writeProxy.write(socketId, user);
System.out.println("Sending contacts...");
writeProxy.write(socketId, contacts);
System.out.println("Sending unread messages and updating them in the database...");
System.out.println("Acquiring pending messages for the client...");
List<Message> pendingMessages = PersistenceManager.getPersistenceManager().getUnreadMessages(new envoy.server.data.User(user));
pendingMessages.forEach((msg) -> {
for (Message msg : pendingMessages) {
System.out.println("Sending message " + msg.toString());
writeProxy.write(socketId, msg);
msg.setReceivedDate(new Date());
msg.setStatus(MessageStatus.RECEIVED);
PersistenceManager.getPersistenceManager().updateMessage(msg);
});
writeProxy.write(socketId, pendingMessages);
}
}
}