Added builtin ClassicHandler
This commit is contained in:
@@ -5,15 +5,23 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.openautonomousconnection.protocol.annotations.ProtocolInfo;
|
||||
import org.openautonomousconnection.protocol.listeners.ClientListener;
|
||||
import org.openautonomousconnection.protocol.listeners.INSServerListener;
|
||||
import org.openautonomousconnection.protocol.listeners.WebServerListener;
|
||||
import org.openautonomousconnection.protocol.listeners.CustomServerListener;
|
||||
import org.openautonomousconnection.protocol.packets.OACPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.*;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.AuthPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.INSQueryPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.INSResponsePacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.UnsupportedClassicPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebRequestPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.WebResponsePacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.stream.WebStreamChunkPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.stream.WebStreamEndPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.beta.web.stream.WebStreamStartPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_DomainPacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_MessagePacket;
|
||||
import org.openautonomousconnection.protocol.packets.v1_0_0.classic.Classic_PingPacket;
|
||||
import org.openautonomousconnection.protocol.side.client.ProtocolClient;
|
||||
import org.openautonomousconnection.protocol.side.ins.ProtocolINSServer;
|
||||
import org.openautonomousconnection.protocol.side.server.ProtocolCustomServer;
|
||||
import org.openautonomousconnection.protocol.side.web.ProtocolWebServer;
|
||||
import org.openautonomousconnection.protocol.versions.ProtocolVersion;
|
||||
import org.openautonomousconnection.protocol.versions.v1_0_0.classic.handlers.ClassicHandlerClient;
|
||||
@@ -48,23 +56,18 @@ public final class ProtocolBridge {
|
||||
@Getter
|
||||
private Logger logger;
|
||||
|
||||
/**
|
||||
* The protocol side instances
|
||||
*/
|
||||
@Getter
|
||||
private ProtocolINSServer protocolINSServer;
|
||||
|
||||
/**
|
||||
* The protocol side instances
|
||||
*/
|
||||
@Getter
|
||||
private ProtocolClient protocolClient;
|
||||
|
||||
|
||||
/**
|
||||
* The protocol side instances
|
||||
*/
|
||||
@Getter
|
||||
private ProtocolWebServer protocolWebServer;
|
||||
private ProtocolCustomServer protocolServer;
|
||||
|
||||
/**
|
||||
* The classic protocol handlers for INS server side
|
||||
@@ -95,18 +98,18 @@ public final class ProtocolBridge {
|
||||
private Proxy proxy;
|
||||
|
||||
/**
|
||||
* Initialize the ProtocolBridge instance for the INS server side
|
||||
* Initialize the ProtocolBridge instance for the client side
|
||||
*
|
||||
* @param protocolINSServer The ProtocolINSServer instance
|
||||
* @param protocolSettings The ProtocolSettings instance
|
||||
* @param protocolVersion The ProtocolVersion instance
|
||||
* @param logFolder The folder to store the log files
|
||||
* @param protocolServer The ProtocolCustomServer instance
|
||||
* @param protocolSettings The ProtocolSettings instance
|
||||
* @param protocolVersion The ProtocolVersion instance
|
||||
* @param logFolder The folder to store the log files
|
||||
* @throws Exception if an error occurs while initializing the ProtocolBridge
|
||||
*/
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.INS)
|
||||
public ProtocolBridge(ProtocolINSServer protocolINSServer, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) throws Exception {
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.CLIENT)
|
||||
public ProtocolBridge(ProtocolCustomServer protocolServer, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) throws Exception {
|
||||
// Assign the parameters to the class fields
|
||||
this.protocolINSServer = protocolINSServer;
|
||||
this.protocolServer = protocolServer;
|
||||
this.protocolSettings = protocolSettings;
|
||||
this.protocolVersion = protocolVersion;
|
||||
|
||||
@@ -118,36 +121,7 @@ public final class ProtocolBridge {
|
||||
registerListeners();
|
||||
registerPackets();
|
||||
|
||||
// Assign Bridge
|
||||
protocolINSServer.attachBridge(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the ProtocolBridge instance for the web server side
|
||||
*
|
||||
* @param protocolWebServer The ProtocolWebServer instance
|
||||
* @param protocolSettings The ProtocolSettings instance
|
||||
* @param protocolVersion The ProtocolVersion instance
|
||||
* @param logFolder The folder to store the log files
|
||||
* @throws Exception if an error occurs while initializing the ProtocolBridge
|
||||
*/
|
||||
@ProtocolInfo(protocolSide = ProtocolVersion.ProtocolSide.WEB)
|
||||
public ProtocolBridge(ProtocolWebServer protocolWebServer, ProtocolSettings protocolSettings, ProtocolVersion protocolVersion, File logFolder) throws Exception {
|
||||
// Assign the parameters to the class fields
|
||||
this.protocolWebServer = protocolWebServer;
|
||||
this.protocolSettings = protocolSettings;
|
||||
this.protocolVersion = protocolVersion;
|
||||
|
||||
// Initialize the logger and protocol version
|
||||
initializeLogger(logFolder);
|
||||
initializeProtocolVersion();
|
||||
|
||||
// Register the appropriate listeners and packets
|
||||
registerListeners();
|
||||
registerPackets();
|
||||
|
||||
// Assign Bridge
|
||||
protocolWebServer.attachBridge(this);
|
||||
protocolServer.attachBridge(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,14 +176,20 @@ public final class ProtocolBridge {
|
||||
WebStreamEndPacket v100BStreamEndPacket = new WebStreamEndPacket();
|
||||
|
||||
if (isPacketSupported(v100bAuthPath)) protocolSettings.packetHandler.registerPacket(v100bAuthPath);
|
||||
if (isPacketSupported(v100bUnsupportedClassicPacket)) protocolSettings.packetHandler.registerPacket(v100bUnsupportedClassicPacket);
|
||||
if (isPacketSupported(v100bUnsupportedClassicPacket))
|
||||
protocolSettings.packetHandler.registerPacket(v100bUnsupportedClassicPacket);
|
||||
if (isPacketSupported(v100BINSQueryPacket)) protocolSettings.packetHandler.registerPacket(v100BINSQueryPacket);
|
||||
if (isPacketSupported(v100BINSResponsePacket)) protocolSettings.packetHandler.registerPacket(v100BINSResponsePacket);
|
||||
if (isPacketSupported(v100BWebRequestPacket)) protocolSettings.packetHandler.registerPacket(v100BWebRequestPacket);
|
||||
if (isPacketSupported(v100BINSResponsePacket))
|
||||
protocolSettings.packetHandler.registerPacket(v100BINSResponsePacket);
|
||||
if (isPacketSupported(v100BWebRequestPacket))
|
||||
protocolSettings.packetHandler.registerPacket(v100BWebRequestPacket);
|
||||
if (isPacketSupported(v100BResponsePacket)) protocolSettings.packetHandler.registerPacket(v100BResponsePacket);
|
||||
if (isPacketSupported(v100BStreamChunkPacket)) protocolSettings.packetHandler.registerPacket(v100BStreamChunkPacket);
|
||||
if (isPacketSupported(v100BStreamStartPacket)) protocolSettings.packetHandler.registerPacket(v100BStreamStartPacket);
|
||||
if (isPacketSupported(v100BStreamEndPacket)) protocolSettings.packetHandler.registerPacket(v100BStreamEndPacket);
|
||||
if (isPacketSupported(v100BStreamChunkPacket))
|
||||
protocolSettings.packetHandler.registerPacket(v100BStreamChunkPacket);
|
||||
if (isPacketSupported(v100BStreamStartPacket))
|
||||
protocolSettings.packetHandler.registerPacket(v100BStreamStartPacket);
|
||||
if (isPacketSupported(v100BStreamEndPacket))
|
||||
protocolSettings.packetHandler.registerPacket(v100BStreamEndPacket);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -225,31 +205,20 @@ public final class ProtocolBridge {
|
||||
protocolSettings.eventManager.registerListener(classicListener.getClass());
|
||||
} else protocolSettings.eventManager.unregisterListener(Classic_ClientListener.class);
|
||||
|
||||
// INS Listeners
|
||||
if (isRunningAsINSServer()) {
|
||||
INSServerListener serverListener = new INSServerListener();
|
||||
serverListener.setINSServer(protocolINSServer);
|
||||
protocolSettings.eventManager.registerListener(serverListener.getClass());
|
||||
protocolSettings.eventManager.unregisterListener(WebServerListener.class);
|
||||
protocolSettings.eventManager.unregisterListener(ClientListener.class);
|
||||
}
|
||||
|
||||
// Web Listeners
|
||||
if (isRunningAsWebServer()) {
|
||||
WebServerListener serverListener = new WebServerListener();
|
||||
serverListener.setWebServer(protocolWebServer);
|
||||
protocolSettings.eventManager.registerListener(serverListener.getClass());
|
||||
protocolSettings.eventManager.unregisterListener(INSServerListener.class);
|
||||
protocolSettings.eventManager.unregisterListener(ClientListener.class);
|
||||
}
|
||||
|
||||
// Client Listeners
|
||||
if (isRunningAsClient()) {
|
||||
ClientListener clientListener = new ClientListener();
|
||||
clientListener.setClient(protocolClient);
|
||||
protocolSettings.eventManager.registerListener(clientListener.getClass());
|
||||
protocolSettings.eventManager.unregisterListener(INSServerListener.class);
|
||||
protocolSettings.eventManager.unregisterListener(WebServerListener.class);
|
||||
protocolSettings.eventManager.unregisterListener(CustomServerListener.class);
|
||||
}
|
||||
|
||||
// Server Listeners
|
||||
if (isRunningAsServer()) {
|
||||
CustomServerListener serverListener = new CustomServerListener();
|
||||
serverListener.setServer(protocolServer);
|
||||
protocolSettings.eventManager.registerListener(serverListener.getClass());
|
||||
protocolSettings.eventManager.unregisterListener(ClientListener.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,6 +330,8 @@ public final class ProtocolBridge {
|
||||
(isRunningAsWebServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.WEB_INS) ||
|
||||
(isRunningAsWebServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.ALL) ||
|
||||
|
||||
(isRunningAsServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.ALL) ||
|
||||
|
||||
(isRunningAsINSServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.INS) ||
|
||||
(isRunningAsINSServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.WEB_INS) ||
|
||||
(isRunningAsINSServer() && protocolVersion.getProtocolSide() == ProtocolVersion.ProtocolSide.CLIENT_INS) ||
|
||||
@@ -373,7 +344,7 @@ public final class ProtocolBridge {
|
||||
* @return true if the current instance is running as a INS server, false otherwise
|
||||
*/
|
||||
public boolean isRunningAsINSServer() {
|
||||
return protocolINSServer != null;
|
||||
return isRunningAsServer() && protocolServer instanceof ProtocolINSServer;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -391,6 +362,15 @@ public final class ProtocolBridge {
|
||||
* @return true if the current instance is running as a web server, false otherwise
|
||||
*/
|
||||
public boolean isRunningAsWebServer() {
|
||||
return protocolWebServer != null;
|
||||
return isRunningAsServer() && protocolServer instanceof ProtocolWebServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current instance is running as a custom server
|
||||
*
|
||||
* @return true if the current instance is running as a custom server, false otherwise
|
||||
*/
|
||||
public boolean isRunningAsServer() {
|
||||
return protocolServer != null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user