Fixed incorrect error handling, upgraded appearance of this processor

This commit is contained in:
delvh 2020-01-30 13:20:39 +01:00
parent 96f8ef0eec
commit 0a0245da0e

View File

@ -33,24 +33,20 @@ public class MessageStatusChangeProcessor implements ObjectProcessor<MessageStat
@Override
public void process(MessageStatusChangeEvent input, long socketId, ObjectWriteProxy writeProxy) throws IOException {
try {
if (!(input.get() == MessageStatus.READ))// check that no invalid MessageStatuses are sent
throw new EnvoyException("Message" + input.getId() + "has an invalid status");
// any other status than read is not supposed to be sent to the server
if (!(input.get() == MessageStatus.READ)) throw new EnvoyException("Message" + input.getId() + "has an invalid status");
} catch (EnvoyException e) {
e.printStackTrace();
return;
}
ConnectionManager conMan = ConnectionManager.getInstance();
PersistenceManager perMan = PersistenceManager.getPersistenceManager();
envoy.server.data.Message msg = perMan.getMessageById(input.getId());
envoy.server.data.Message msg = perMan.getMessageById(input.getId());
msg.setStatus(input.get());
msg.setReadDate(input.getDate());
if (conMan.isOnline(msg.getRecipient().getId())) writeProxy.write(conMan.getSocketId(msg.getRecipient().getId()), input);
perMan.updateMessage(msg);
} catch (IOException | EnvoyException e) {
if (e.getClass() == IOException.class)
System.err.println("Recipient online. Failed to send MessageStatusChangedMessageStatusChangeEvent at message" + input.getId());
e.printStackTrace();
}
if (conMan.isOnline(msg.getRecipient().getId())) writeProxy.write(conMan.getSocketId(msg.getRecipient().getId()), input);
}
}