34 lines
1.2 KiB
Java
34 lines
1.2 KiB
Java
package envoy.server.processors;
|
|
|
|
import java.io.IOException;
|
|
|
|
import envoy.event.ContactOperationEvent;
|
|
import envoy.event.ContactOperationEvent.Operation;
|
|
import envoy.server.ConnectionManager;
|
|
import envoy.server.ObjectProcessor;
|
|
import envoy.server.database.PersistenceManager;
|
|
import envoy.server.net.ObjectWriteProxy;
|
|
|
|
/**
|
|
* Project: <strong>envoy-server-standalone</strong><br>
|
|
* File: <strong>ContactOperationProcessor.java</strong><br>
|
|
* Created: <strong>08.02.2020</strong><br>
|
|
*
|
|
* @author Kai S. K. Engelbart
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
*/
|
|
public class ContactOperationProcessor implements ObjectProcessor<ContactOperationEvent> {
|
|
|
|
@Override
|
|
public void process(ContactOperationEvent operation, long socketId, ObjectWriteProxy writeProxy) throws IOException {
|
|
if (operation.getOperationType() == Operation.ADD) {
|
|
long userId = ConnectionManager.getInstance().getUserIdBySocketId(socketId);
|
|
System.out.printf("Adding user %s to the contact list of user %d.%n", operation.get(), userId);
|
|
PersistenceManager.getPersistenceManager().addContact(userId, operation.get().getId());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Class<ContactOperationEvent> getInputClass() { return ContactOperationEvent.class; }
|
|
}
|