Filter out subclasses in ObjectMessageProcessor
This commit is contained in:
parent
5f595e640a
commit
fc20f3688f
@ -4,6 +4,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.jenkov.nioserver.IMessageProcessor;
|
||||
@ -50,11 +51,11 @@ public class ObjectMessageProcessor implements IMessageProcessor {
|
||||
logger.fine("Received " + obj);
|
||||
|
||||
// Process object
|
||||
processors.stream().filter(p -> p.getInputClass().isInstance(obj)).forEach((@SuppressWarnings("rawtypes") ObjectProcessor p) -> {
|
||||
processors.stream().filter(p -> p.getInputClass().equals(obj.getClass())).forEach((@SuppressWarnings("rawtypes") ObjectProcessor p) -> {
|
||||
try {
|
||||
p.process(p.getInputClass().cast(obj), message.socketId, new ObjectWriteProxy(writeProxy));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
logger.log(Level.SEVERE, "Exception during processor execution: ", e);
|
||||
}
|
||||
});
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package envoy.server.processors;
|
||||
|
||||
import static envoy.data.Message.MessageStatus.*;
|
||||
import static envoy.data.User.UserStatus.ONLINE;
|
||||
import static envoy.event.HandshakeRejection.*;
|
||||
|
||||
@ -10,7 +11,6 @@ import java.util.logging.Logger;
|
||||
import javax.persistence.NoResultException;
|
||||
|
||||
import envoy.data.LoginCredentials;
|
||||
import envoy.data.Message.MessageStatus;
|
||||
import envoy.event.GroupMessageStatusChange;
|
||||
import envoy.event.HandshakeRejection;
|
||||
import envoy.event.MessageStatusChange;
|
||||
@ -120,7 +120,7 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
|
||||
|
||||
for (var msg : pendingMessages) {
|
||||
final var msgCommon = msg.toCommon();
|
||||
if (msg.getStatus() == MessageStatus.SENT) {
|
||||
if (msg.getStatus() == SENT) {
|
||||
|
||||
// Send the message
|
||||
writeProxy.write(socketID, msgCommon);
|
||||
@ -142,16 +142,17 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
|
||||
final var gmsgCommon = gmsg.toCommon();
|
||||
|
||||
// Deliver the message to the user if he hasn't received it yet
|
||||
if (gmsg.getMemberMessageStatus().get(user.getID()) == MessageStatus.SENT) {
|
||||
gmsg.getMemberMessageStatus().replace(user.getID(), MessageStatus.RECEIVED);
|
||||
if (gmsg.getMemberMessageStatus().get(user.getID()) == SENT) {
|
||||
gmsg.getMemberMessageStatus().replace(user.getID(), RECEIVED);
|
||||
writeProxy.write(socketID, gmsgCommon);
|
||||
|
||||
// Notify all online group members about the status change
|
||||
writeProxy.writeToOnlineContacts(gmsg.getRecipient().getContacts(),
|
||||
new GroupMessageStatusChange(gmsg.getID(), MessageStatus.RECEIVED, LocalDateTime.now(),
|
||||
new GroupMessageStatusChange(gmsg.getID(), RECEIVED, LocalDateTime
|
||||
.now(),
|
||||
connectionManager.getUserIDBySocketID(socketID)));
|
||||
|
||||
if (Collections.min(gmsg.getMemberMessageStatus().values()) == MessageStatus.RECEIVED) {
|
||||
if (Collections.min(gmsg.getMemberMessageStatus().values()) == RECEIVED) {
|
||||
gmsg.received();
|
||||
|
||||
// Notify online members about the status change
|
||||
|
@ -31,10 +31,6 @@ public class MessageProcessor implements ObjectProcessor<Message> {
|
||||
|
||||
@Override
|
||||
public void process(Message message, long socketID, ObjectWriteProxy writeProxy) {
|
||||
// Makes sure, that there are no groupMessages processed here, because
|
||||
// groupMessage is a subclass of message.
|
||||
if (message instanceof envoy.data.GroupMessage) return;
|
||||
|
||||
message.nextStatus();
|
||||
|
||||
// Convert to server message
|
||||
|
@ -5,7 +5,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import envoy.data.Message.MessageStatus;
|
||||
import envoy.event.GroupMessageStatusChange;
|
||||
import envoy.event.MessageStatusChange;
|
||||
import envoy.server.data.PersistenceManager;
|
||||
import envoy.server.net.ConnectionManager;
|
||||
@ -28,8 +27,6 @@ public class MessageStatusChangeProcessor implements ObjectProcessor<MessageStat
|
||||
|
||||
@Override
|
||||
public void process(MessageStatusChange statusChange, long socketID, ObjectWriteProxy writeProxy) throws IOException {
|
||||
// Filtering out subclass objects, which should not be processed here.
|
||||
if (statusChange instanceof GroupMessageStatusChange) return;
|
||||
|
||||
// Any other status than READ is not supposed to be sent to the server
|
||||
if (statusChange.get() != MessageStatus.READ) {
|
||||
|
Reference in New Issue
Block a user