Merge pull request #31 from informatik-ag-ngl/f/simple_object_processor

Remove ObjectProcessor#getInputClass
This commit is contained in:
Kai S. K. Engelbart 2020-07-31 16:49:04 +00:00 committed by GitHub
commit 4e3c33b434
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 13 additions and 52 deletions

View File

@ -3,6 +3,7 @@ package envoy.server.net;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.lang.reflect.ParameterizedType;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -50,14 +51,19 @@ public class ObjectMessageProcessor implements IMessageProcessor {
logger.fine("Received " + obj);
// Process object
processors.stream().filter(p -> p.getInputClass().equals(obj.getClass())).forEach((@SuppressWarnings("rawtypes") ObjectProcessor p) -> {
// Get processor and input class and process object
for (@SuppressWarnings("rawtypes")
ObjectProcessor p : processors) {
Class<?> c = (Class<?>) ((ParameterizedType) p.getClass().getGenericInterfaces()[0]).getActualTypeArguments()[0];
if (c.equals(obj.getClass())) {
try {
p.process(p.getInputClass().cast(obj), message.socketId, new ObjectWriteProxy(writeProxy));
p.process(c.cast(obj), message.socketId, new ObjectWriteProxy(writeProxy));
break;
} catch (IOException e) {
logger.log(Level.SEVERE, "Exception during processor execution: ", e);
}
});
}
}
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}

View File

@ -41,7 +41,4 @@ public class ContactOperationProcessor implements ObjectProcessor<ContactOperati
logger.warning(String.format("Received %s with an unsupported operation.", evt));
}
}
@Override
public Class<ContactOperation> getInputClass() { return ContactOperation.class; }
}

View File

@ -40,7 +40,4 @@ public class GroupCreationProcessor implements ObjectProcessor<GroupCreation> {
.map(connectionManager::getSocketID)
.forEach(memberSocketID -> writeProxy.write(memberSocketID, new ContactOperation(group.toCommon(), ElementOperation.ADD)));
}
@Override
public Class<GroupCreation> getInputClass() { return GroupCreation.class; }
}

View File

@ -61,7 +61,4 @@ public class GroupMessageProcessor implements ObjectProcessor<GroupMessage> {
logger.warning("Received a groupMessage with an ID that already exists");
}
}
@Override
public Class<GroupMessage> getInputClass() { return GroupMessage.class; }
}

View File

@ -63,7 +63,4 @@ public class GroupMessageStatusChangeProcessor implements ObjectProcessor<GroupM
}
persistenceManager.updateMessage(gmsg);
}
@Override
public Class<GroupMessageStatusChange> getInputClass() { return GroupMessageStatusChange.class; }
}

View File

@ -47,7 +47,4 @@ public class GroupResizeProcessor implements ObjectProcessor<GroupResize> {
.map(connectionManager::getSocketID)
.forEach(memberSocketID -> writeProxy.write(memberSocketID, commonGroup));
}
@Override
public Class<GroupResize> getInputClass() { return GroupResize.class; }
}

View File

@ -21,9 +21,6 @@ public class IDGeneratorRequestProcessor implements ObjectProcessor<IDGeneratorR
private static final long ID_RANGE = 200;
@Override
public Class<IDGeneratorRequest> getInputClass() { return IDGeneratorRequest.class; }
@Override
public void process(IDGeneratorRequest input, long socketID, ObjectWriteProxy writeProxy) throws IOException {
writeProxy.write(socketID, createIDGenerator());

View File

@ -23,9 +23,6 @@ public class IsTypingProcessor implements ObjectProcessor<IsTyping> {
private static final ConnectionManager connectionManager = ConnectionManager.getInstance();
private static final PersistenceManager persistenceManager = PersistenceManager.getInstance();
@Override
public Class<IsTyping> getInputClass() { return IsTyping.class; }
@Override
public void process(IsTyping event, long socketID, ObjectWriteProxy writeProxy) throws IOException {
final var contact = persistenceManager.getContactByID(event.get());

View File

@ -191,7 +191,4 @@ public final class LoginCredentialProcessor implements ObjectProcessor<LoginCred
// Complete the handshake
writeProxy.write(socketID, user.toCommon());
}
@Override
public Class<LoginCredentials> getInputClass() { return LoginCredentials.class; }
}

View File

@ -58,7 +58,4 @@ public class MessageProcessor implements ObjectProcessor<Message> {
logger.log(Level.WARNING, "Received " + message + " with an ID that already exists!");
}
}
@Override
public Class<Message> getInputClass() { return Message.class; }
}

View File

@ -42,7 +42,4 @@ public class MessageStatusChangeProcessor implements ObjectProcessor<MessageStat
final long senderID = msg.getSender().getID();
if (connectionManager.isOnline(senderID)) writeProxy.write(connectionManager.getSocketID(senderID), statusChange);
}
@Override
public Class<MessageStatusChange> getInputClass() { return MessageStatusChange.class; }
}

View File

@ -28,7 +28,4 @@ public class NameChangeProcessor implements ObjectProcessor<NameChange> {
// Notify online contacts of the name change
writeProxy.writeToOnlineContacts(toUpdate.getContacts(), nameChange);
}
@Override
public Class<NameChange> getInputClass() { return NameChange.class; }
}

View File

@ -18,12 +18,6 @@ import envoy.server.net.ObjectWriteProxy;
*/
public interface ObjectProcessor<T> {
/**
* @return the class of the request object
* @since Envoy Server Standalone v0.1-alpha
*/
Class<T> getInputClass();
/**
* @param input the request object
* @param socketID the ID of the socket from which the object was received

View File

@ -38,7 +38,4 @@ public class UserSearchProcessor implements ObjectProcessor<UserSearchRequest> {
.map(User::toCommon)
.collect(Collectors.toList())));
}
@Override
public Class<UserSearchRequest> getInputClass() { return UserSearchRequest.class; }
}

View File

@ -26,9 +26,6 @@ public class UserStatusChangeProcessor implements ObjectProcessor<UserStatusChan
private static final PersistenceManager persistenceManager = PersistenceManager.getInstance();
private static final Logger logger = EnvoyLog.getLogger(UserStatusChangeProcessor.class);
@Override
public Class<UserStatusChange> getInputClass() { return UserStatusChange.class; }
@Override
public void process(UserStatusChange input, long socketID, ObjectWriteProxy writeProxy) {
// new status should not equal old status