Shorten event names, compatibility verification
This commit is contained in:
@@ -15,7 +15,7 @@ import envoy.client.data.LocalDB;
|
||||
import envoy.client.event.SendEvent;
|
||||
import envoy.data.*;
|
||||
import envoy.event.*;
|
||||
import envoy.event.contact.ContactOperationEvent;
|
||||
import envoy.event.contact.ContactOperation;
|
||||
import envoy.event.contact.ContactSearchResult;
|
||||
import envoy.util.EnvoyLog;
|
||||
import envoy.util.SerializationUtils;
|
||||
@@ -56,11 +56,16 @@ public class Client implements Closeable {
|
||||
* will block for up to 5 seconds. If the handshake does exceed this time limit,
|
||||
* an exception is thrown.
|
||||
*
|
||||
* @param credentials the login credentials of the user
|
||||
* @param receivedMessageCache a message cache containing all unread messages
|
||||
* from the server that can be relayed after
|
||||
* initialization
|
||||
* @param receivedMessageStatusChangeEventCache an event cache containing all received messageStatusChangeEvents from the server that can be relayed after initialization
|
||||
* @param credentials the login credentials of the user
|
||||
* @param receivedMessageCache a message cache containing all unread
|
||||
* messages
|
||||
* from the server that can be relayed
|
||||
* after
|
||||
* initialization
|
||||
* @param receivedMessageStatusChangeCache an event cache containing all
|
||||
* received messageStatusChangeEvents
|
||||
* from the server that can be relayed
|
||||
* after initialization
|
||||
* @throws TimeoutException if the server could not be reached
|
||||
* @throws IOException if the login credentials could not be
|
||||
* written
|
||||
@@ -68,7 +73,7 @@ public class Client implements Closeable {
|
||||
* waiting for the handshake response
|
||||
*/
|
||||
public void performHandshake(LoginCredentials credentials, Cache<Message> receivedMessageCache,
|
||||
Cache<MessageStatusChangeEvent> receivedMessageStatusChangeEventCache)
|
||||
Cache<MessageStatusChange> receivedMessageStatusChangeCache)
|
||||
throws TimeoutException, IOException, InterruptedException {
|
||||
if (online) throw new IllegalStateException("Handshake has already been performed successfully");
|
||||
// Establish TCP connection
|
||||
@@ -82,8 +87,8 @@ public class Client implements Closeable {
|
||||
// Register user creation processor, contact list processor and message cache
|
||||
receiver.registerProcessor(User.class, sender -> { this.sender = sender; contacts = sender.getContacts(); });
|
||||
receiver.registerProcessor(Message.class, receivedMessageCache);
|
||||
receiver.registerProcessor(MessageStatusChangeEvent.class, receivedMessageStatusChangeEventCache);
|
||||
receiver.registerProcessor(HandshakeRejectionEvent.class, evt -> { rejected = true; eventBus.dispatch(evt); });
|
||||
receiver.registerProcessor(MessageStatusChange.class, receivedMessageStatusChangeCache);
|
||||
receiver.registerProcessor(HandshakeRejection.class, evt -> { rejected = true; eventBus.dispatch(evt); });
|
||||
|
||||
rejected = false;
|
||||
|
||||
@@ -121,23 +126,29 @@ public class Client implements Closeable {
|
||||
* Initializes the {@link Receiver} used to process data sent from the server to
|
||||
* this client.
|
||||
*
|
||||
* @param localDB the local database used to persist the current
|
||||
* {@link IDGenerator}
|
||||
* @param receivedMessageCache a message cache containing all unread messages
|
||||
* from the server that can be relayed after
|
||||
* initialization
|
||||
* @param receivedMessageStatusChangeEventCache an event cache containing all received messageStatusChangeEvents from the server that can be relayed after initialization
|
||||
* @param localDB the local database used to persist
|
||||
* the current
|
||||
* {@link IDGenerator}
|
||||
* @param receivedMessageCache a message cache containing all unread
|
||||
* messages
|
||||
* from the server that can be relayed
|
||||
* after
|
||||
* initialization
|
||||
* @param receivedMessageStatusChangeCache an event cache containing all
|
||||
* received messageStatusChangeEvents
|
||||
* from the server that can be relayed
|
||||
* after initialization
|
||||
* @throws IOException if no {@link IDGenerator} is present and none could be
|
||||
* requested from the server
|
||||
* @since Envoy Client v0.2-alpha
|
||||
*/
|
||||
public void initReceiver(LocalDB localDB, Cache<Message> receivedMessageCache,
|
||||
Cache<MessageStatusChangeEvent> receivedMessageStatusChangeEventCache) throws IOException {
|
||||
Cache<MessageStatusChange> receivedMessageStatusChangeCache) throws IOException {
|
||||
checkOnline();
|
||||
|
||||
// Process incoming messages
|
||||
final ReceivedMessageProcessor receivedMessageProcessor = new ReceivedMessageProcessor();
|
||||
final MessageStatusChangeEventProcessor messageStatusChangeEventProcessor = new MessageStatusChangeEventProcessor();
|
||||
final MessageStatusChangeProcessor messageStatusChangeEventProcessor = new MessageStatusChangeProcessor();
|
||||
|
||||
receiver.registerProcessor(Message.class, receivedMessageProcessor);
|
||||
|
||||
@@ -145,26 +156,26 @@ public class Client implements Closeable {
|
||||
receivedMessageCache.setProcessor(receivedMessageProcessor);
|
||||
|
||||
// Process message status changes
|
||||
receiver.registerProcessor(MessageStatusChangeEvent.class, messageStatusChangeEventProcessor);
|
||||
receivedMessageStatusChangeEventCache.setProcessor(messageStatusChangeEventProcessor);
|
||||
receiver.registerProcessor(MessageStatusChange.class, messageStatusChangeEventProcessor);
|
||||
receivedMessageStatusChangeCache.setProcessor(messageStatusChangeEventProcessor);
|
||||
|
||||
// Process user status changes
|
||||
receiver.registerProcessor(UserStatusChangeEvent.class, eventBus::dispatch);
|
||||
receiver.registerProcessor(UserStatusChange.class, eventBus::dispatch);
|
||||
|
||||
// Process message ID generation
|
||||
receiver.registerProcessor(IDGenerator.class, localDB::setIDGenerator);
|
||||
|
||||
// Process name changes
|
||||
receiver.registerProcessor(NameChangeEvent.class, evt -> { localDB.replaceContactName(evt); eventBus.dispatch(evt); });
|
||||
receiver.registerProcessor(NameChange.class, evt -> { localDB.replaceContactName(evt); eventBus.dispatch(evt); });
|
||||
|
||||
// Process contact searches
|
||||
receiver.registerProcessor(ContactSearchResult.class, eventBus::dispatch);
|
||||
|
||||
// Process contact operations
|
||||
receiver.registerProcessor(ContactOperationEvent.class, eventBus::dispatch);
|
||||
receiver.registerProcessor(ContactOperation.class, eventBus::dispatch);
|
||||
|
||||
// Process group size changes
|
||||
receiver.registerProcessor(GroupResizeEvent.class, evt -> { localDB.updateGroup(evt); eventBus.dispatch(evt); });
|
||||
receiver.registerProcessor(GroupResize.class, evt -> { localDB.updateGroup(evt); eventBus.dispatch(evt); });
|
||||
|
||||
// Send event
|
||||
eventBus.register(SendEvent.class, evt -> {
|
||||
|
Reference in New Issue
Block a user