restored compatibility with envoy common (and envoy server standalone)
This commit is contained in:
@@ -5,6 +5,7 @@ import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.naming.TimeLimitExceededException;
|
||||
@@ -15,7 +16,8 @@ import envoy.client.data.LocalDB;
|
||||
import envoy.client.event.SendEvent;
|
||||
import envoy.data.*;
|
||||
import envoy.event.*;
|
||||
import envoy.event.ContactOperationEvent.Operation;
|
||||
import envoy.event.contact.ContactOperationEvent;
|
||||
import envoy.event.contact.ContactSearchResult;
|
||||
import envoy.util.EnvoyLog;
|
||||
import envoy.util.SerializationUtils;
|
||||
|
||||
@@ -40,9 +42,9 @@ public class Client implements Closeable {
|
||||
private boolean online;
|
||||
|
||||
// Asynchronously initialized during handshake
|
||||
private volatile User sender;
|
||||
private volatile Contacts contacts;
|
||||
private volatile boolean rejected;
|
||||
private volatile User sender;
|
||||
private volatile Set<? extends Contact> contacts;
|
||||
private volatile boolean rejected;
|
||||
|
||||
// Configuration and logging
|
||||
private static final ClientConfig config = ClientConfig.getInstance();
|
||||
@@ -67,7 +69,6 @@ public class Client implements Closeable {
|
||||
public void performHandshake(LoginCredentials credentials, Cache<Message> receivedMessageCache)
|
||||
throws TimeLimitExceededException, IOException, InterruptedException {
|
||||
if (online) throw new IllegalStateException("Handshake has already been performed successfully");
|
||||
|
||||
// Establish TCP connection
|
||||
logger.info(String.format("Attempting connection to server %s:%d...", config.getServer(), config.getPort()));
|
||||
socket = new Socket(config.getServer(), config.getPort());
|
||||
@@ -77,8 +78,7 @@ public class Client implements Closeable {
|
||||
receiver = new Receiver(socket.getInputStream());
|
||||
|
||||
// Register user creation processor, contact list processor and message cache
|
||||
receiver.registerProcessor(User.class, sender -> this.sender = sender);
|
||||
receiver.registerProcessor(Contacts.class, contacts -> this.contacts = contacts);
|
||||
receiver.registerProcessor(User.class, sender -> { this.sender = sender; contacts = sender.getContacts(); });
|
||||
receiver.registerProcessor(Message.class, receivedMessageCache);
|
||||
receiver.registerProcessor(HandshakeRejectionEvent.class, evt -> { rejected = true; EventBus.getInstance().dispatch(evt); });
|
||||
|
||||
@@ -92,7 +92,7 @@ public class Client implements Closeable {
|
||||
|
||||
// Wait for a maximum of five seconds to acquire the sender object
|
||||
long start = System.currentTimeMillis();
|
||||
while (sender == null || contacts == null) {
|
||||
while (sender == null) {
|
||||
|
||||
// Quit immediately after handshake rejection
|
||||
// This method can then be called again
|
||||
@@ -151,8 +151,9 @@ public class Client implements Closeable {
|
||||
// Process contact searches
|
||||
receiver.registerProcessor(ContactSearchResult.class, EventBus.getInstance()::dispatch);
|
||||
|
||||
receiver.registerProcessor(Contacts.class,
|
||||
contacts -> EventBus.getInstance().dispatch(new ContactOperationEvent(contacts.getContacts().get(0), Operation.ADD)));
|
||||
receiver.registerProcessor(Contact.class,
|
||||
contacts -> EventBus.getInstance()
|
||||
.dispatch(new ContactOperationEvent(contacts.getContacts().iterator().next(), ElementOperation.ADD)));
|
||||
|
||||
// Process group size changes
|
||||
receiver.registerProcessor(GroupResizeEvent.class, evt -> { localDB.updateGroup(evt); EventBus.getInstance().dispatch(evt); });
|
||||
@@ -218,10 +219,10 @@ public class Client implements Closeable {
|
||||
* user names as keys
|
||||
* @since Envoy Client v0.2-alpha
|
||||
*/
|
||||
public Map<String, User> getUsers() {
|
||||
public Map<String, Contact> getUsers() {
|
||||
checkOnline();
|
||||
Map<String, User> users = new HashMap<>();
|
||||
contacts.getContacts().forEach(u -> users.put(u.getName(), u));
|
||||
Map<String, Contact> users = new HashMap<>();
|
||||
contacts.forEach(u -> users.put(u.getName(), u));
|
||||
return users;
|
||||
}
|
||||
|
||||
@@ -245,10 +246,10 @@ public class Client implements Closeable {
|
||||
/**
|
||||
* Sets the client user which is used to send messages.
|
||||
*
|
||||
* @param sender the client user to set
|
||||
* @param clientUser the client user to set
|
||||
* @since Envoy Client v0.2-alpha
|
||||
*/
|
||||
public void setSender(User sender) { this.sender = sender; }
|
||||
public void setSender(User clientUser) { this.sender = clientUser; }
|
||||
|
||||
/**
|
||||
* @return the {@link Receiver} used by this {@link Client}
|
||||
@@ -265,11 +266,11 @@ public class Client implements Closeable {
|
||||
* @return the contacts of this {@link Client}
|
||||
* @since Envoy Client v0.3-alpha
|
||||
*/
|
||||
public Contacts getContacts() { return contacts; }
|
||||
public Set<? extends Contact> getContacts() { return contacts; }
|
||||
|
||||
/**
|
||||
* @param contacts the contacts to set
|
||||
* @since Envoy Client v0.3-alpha
|
||||
*/
|
||||
public void setContacts(Contacts contacts) { this.contacts = contacts; }
|
||||
public void setContacts(Set<? extends Contact> contacts) { this.contacts = contacts; }
|
||||
}
|
||||
|
Reference in New Issue
Block a user