Abstract insa proxy with proxy interface
This commit is contained in:
parent
599a4a1121
commit
65872c33aa
12 changed files with 52 additions and 26 deletions
|
@ -1,6 +1,6 @@
|
|||
package fr.insa.clavardator.client.config;
|
||||
|
||||
import fr.insa.clavardator.client.server.PresenceType;
|
||||
import fr.insa.clavardator.client.server.ServerType;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
@ -43,7 +43,7 @@ public class Config {
|
|||
|
||||
private boolean enabled;
|
||||
private String uri;
|
||||
private PresenceType type;
|
||||
private ServerType type;
|
||||
private int presencePort;
|
||||
private int proxyPort;
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class Config {
|
|||
public ServerConfig() {
|
||||
enabled = false;
|
||||
uri = "";
|
||||
type = PresenceType.INSA;
|
||||
type = ServerType.INSA;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,9 +113,9 @@ public class Config {
|
|||
*/
|
||||
private void readServerType() {
|
||||
try {
|
||||
type = obj.getEnum(PresenceType.class, TYPE_KEY);
|
||||
type = obj.getEnum(ServerType.class, TYPE_KEY);
|
||||
} catch (JSONException e) {
|
||||
type = PresenceType.INSA;
|
||||
type = ServerType.INSA;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ public class Config {
|
|||
return uri;
|
||||
}
|
||||
|
||||
public PresenceType getType() {
|
||||
public ServerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package fr.insa.clavardator.client.server;
|
||||
|
||||
public enum PresenceType {
|
||||
public enum ServerType {
|
||||
INSA,
|
||||
TEST,
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package fr.insa.clavardator.client.server;
|
||||
package fr.insa.clavardator.client.server.presence;
|
||||
|
||||
import fr.insa.clavardator.client.users.CurrentUser;
|
||||
import fr.insa.clavardator.client.server.proxy.InsaProxy;
|
||||
import fr.insa.clavardator.client.server.proxy.Proxy;
|
||||
import fr.insa.clavardator.lib.message.Message;
|
||||
import fr.insa.clavardator.lib.network.TcpConnection;
|
||||
import fr.insa.clavardator.lib.users.UserInformation;
|
||||
|
@ -40,7 +41,7 @@ public class InsaPresence implements Presence {
|
|||
public InsaPresence(String path, int presencePort, int proxyPort) {
|
||||
this.path = path;
|
||||
this.presencePort = presencePort;
|
||||
this.proxy = new Proxy(path, proxyPort);
|
||||
this.proxy = new InsaProxy(path, proxyPort);
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,5 +1,6 @@
|
|||
package fr.insa.clavardator.client.server;
|
||||
package fr.insa.clavardator.client.server.presence;
|
||||
|
||||
import fr.insa.clavardator.client.server.proxy.Proxy;
|
||||
import fr.insa.clavardator.lib.users.UserInformation;
|
||||
import fr.insa.clavardator.lib.util.ErrorCallback;
|
||||
import fr.insa.clavardator.lib.util.ParametrizedCallback;
|
||||
|
@ -12,7 +13,7 @@ import java.util.ArrayList;
|
|||
* Interface exposing public methods necessary for any presence server.
|
||||
*
|
||||
* @implNote Implement this interface when creating your own presence server class,
|
||||
* then update the {@link fr.insa.clavardator.client.server.PresenceFactory factory}
|
||||
* then update the {@link PresenceFactory factory}
|
||||
* to add your new implementation.
|
||||
*/
|
||||
public interface Presence {
|
|
@ -1,10 +1,12 @@
|
|||
package fr.insa.clavardator.client.server;
|
||||
package fr.insa.clavardator.client.server.presence;
|
||||
|
||||
import fr.insa.clavardator.client.server.ServerType;
|
||||
|
||||
/**
|
||||
* Static factory class used to create concrete presence server implementations.
|
||||
*/
|
||||
public class PresenceFactory {
|
||||
public static Presence create(PresenceType type, String uri, int serverPort, int proxyPort) throws UnknownPresenceException {
|
||||
public static Presence create(ServerType type, String uri, int serverPort, int proxyPort) throws UnknownPresenceException {
|
||||
switch (type) {
|
||||
case INSA:
|
||||
return new InsaPresence(uri, serverPort, proxyPort);
|
|
@ -1,4 +1,4 @@
|
|||
package fr.insa.clavardator.client.server;
|
||||
package fr.insa.clavardator.client.server.presence;
|
||||
|
||||
public class UnknownPresenceException extends Exception {
|
||||
public UnknownPresenceException() {
|
|
@ -1,4 +1,4 @@
|
|||
package fr.insa.clavardator.client.server;
|
||||
package fr.insa.clavardator.client.server.proxy;
|
||||
|
||||
import fr.insa.clavardator.client.users.CurrentUser;
|
||||
import fr.insa.clavardator.lib.message.SenderInfo;
|
||||
|
@ -16,14 +16,14 @@ import java.net.UnknownHostException;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Proxy {
|
||||
public class InsaProxy implements Proxy {
|
||||
private final String path;
|
||||
private final int proxyPort;
|
||||
TcpConnection proxyConnection;
|
||||
Map<String, TcpConnection.MessageReceivedCallback> callbackMap = new HashMap<>();
|
||||
private boolean receiving = false;
|
||||
|
||||
public Proxy(String path, int proxyPort) {
|
||||
public InsaProxy(String path, int proxyPort) {
|
||||
this.path = path;
|
||||
this.proxyPort = proxyPort;
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package fr.insa.clavardator.client.server.proxy;
|
||||
|
||||
import fr.insa.clavardator.lib.network.TcpConnection;
|
||||
import fr.insa.clavardator.lib.util.ErrorCallback;
|
||||
import fr.insa.clavardator.lib.util.SimpleCallback;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface Proxy {
|
||||
void connect(SimpleCallback callback, ErrorCallback errorCallback);
|
||||
|
||||
void send(Serializable message, @Nullable SimpleCallback callback, @Nullable ErrorCallback errorCallback);
|
||||
|
||||
void receive(String userId, TcpConnection.MessageReceivedCallback callback, ErrorCallback errorCallback);
|
||||
|
||||
boolean isConnected();
|
||||
|
||||
void close();
|
||||
|
||||
void disconnectUser(String id);
|
||||
}
|
|
@ -4,10 +4,10 @@ import com.jfoenix.controls.JFXSnackbar;
|
|||
import fr.insa.clavardator.client.config.Config;
|
||||
import fr.insa.clavardator.client.config.ConfigLoader;
|
||||
import fr.insa.clavardator.client.db.DatabaseController;
|
||||
import fr.insa.clavardator.client.server.Presence;
|
||||
import fr.insa.clavardator.client.server.PresenceFactory;
|
||||
import fr.insa.clavardator.client.server.PresenceType;
|
||||
import fr.insa.clavardator.client.server.UnknownPresenceException;
|
||||
import fr.insa.clavardator.client.server.presence.Presence;
|
||||
import fr.insa.clavardator.client.server.presence.PresenceFactory;
|
||||
import fr.insa.clavardator.client.server.ServerType;
|
||||
import fr.insa.clavardator.client.server.presence.UnknownPresenceException;
|
||||
import fr.insa.clavardator.client.ui.chat.ChatController;
|
||||
import fr.insa.clavardator.client.ui.dialogs.AboutDialogController;
|
||||
import fr.insa.clavardator.client.ui.dialogs.EditUsernameDialogController;
|
||||
|
@ -307,7 +307,7 @@ public class MainController implements Initializable {
|
|||
private void initPresenceServer(Config.ServerConfig serverConfig) {
|
||||
if (serverConfig.isEnabled()) {
|
||||
try {
|
||||
final PresenceType type = serverConfig.getType();
|
||||
final ServerType type = serverConfig.getType();
|
||||
final String uri = serverConfig.getUri();
|
||||
final int presencePort = serverConfig.getPresencePort();
|
||||
final int proxyPort = serverConfig.getProxyPort();
|
||||
|
|
|
@ -2,7 +2,7 @@ package fr.insa.clavardator.client.users;
|
|||
|
||||
import fr.insa.clavardator.client.chat.ChatHistory;
|
||||
import fr.insa.clavardator.client.db.DatabaseController;
|
||||
import fr.insa.clavardator.client.server.Proxy;
|
||||
import fr.insa.clavardator.client.server.proxy.Proxy;
|
||||
import fr.insa.clavardator.lib.errors.UsernameTakenException;
|
||||
import fr.insa.clavardator.lib.message.FileMessage;
|
||||
import fr.insa.clavardator.lib.message.Message;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package fr.insa.clavardator.client.users;
|
||||
|
||||
import fr.insa.clavardator.client.server.Proxy;
|
||||
import fr.insa.clavardator.client.server.proxy.Proxy;
|
||||
import fr.insa.clavardator.lib.network.TcpConnection;
|
||||
import fr.insa.clavardator.lib.util.ErrorCallback;
|
||||
import fr.insa.clavardator.lib.util.SimpleCallback;
|
||||
|
|
|
@ -3,7 +3,7 @@ package fr.insa.clavardator.client.users;
|
|||
import fr.insa.clavardator.client.db.DatabaseController;
|
||||
import fr.insa.clavardator.client.network.NetDiscoverer;
|
||||
import fr.insa.clavardator.client.network.PeerHandshake;
|
||||
import fr.insa.clavardator.client.server.Proxy;
|
||||
import fr.insa.clavardator.client.server.proxy.Proxy;
|
||||
import fr.insa.clavardator.lib.network.TcpListener;
|
||||
import fr.insa.clavardator.lib.users.User;
|
||||
import fr.insa.clavardator.lib.users.UserInformation;
|
||||
|
|
Loading…
Reference in a new issue