2019-12-28 14:48:39 +01:00
|
|
|
package envoy.server;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2019-12-30 14:53:40 +01:00
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Set;
|
2019-12-28 14:48:39 +01:00
|
|
|
|
|
|
|
import com.jenkov.nioserver.Server;
|
|
|
|
|
2020-01-28 20:46:27 +01:00
|
|
|
import envoy.server.data.ConfigItem;
|
2020-01-18 09:55:12 +01:00
|
|
|
import envoy.server.database.PersistenceManager;
|
2020-01-03 15:40:43 +01:00
|
|
|
import envoy.server.net.ObjectMessageProcessor;
|
|
|
|
import envoy.server.net.ObjectMessageReader;
|
2020-01-28 19:25:30 +01:00
|
|
|
import envoy.server.processors.*;
|
2020-01-03 15:40:43 +01:00
|
|
|
|
2019-12-28 14:48:39 +01:00
|
|
|
/**
|
2019-12-30 15:15:25 +01:00
|
|
|
* Starts the server.<br>
|
|
|
|
* <br>
|
2019-12-28 14:48:39 +01:00
|
|
|
* Project: <strong>envoy-server-standalone</strong><br>
|
|
|
|
* File: <strong>Startup.java</strong><br>
|
|
|
|
* Created: <strong>24.12.2019</strong><br>
|
2019-12-30 15:15:25 +01:00
|
|
|
*
|
2019-12-28 14:48:39 +01:00
|
|
|
* @author Kai S. K. Engelbart
|
|
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
|
|
*/
|
|
|
|
public class Startup {
|
|
|
|
|
2019-12-30 15:15:25 +01:00
|
|
|
/**
|
|
|
|
* Starts the server.
|
|
|
|
*
|
|
|
|
* @param args the run configuration. Currently unused.
|
|
|
|
* @throws IOException if the server crashes
|
|
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
|
|
*/
|
2019-12-28 14:48:39 +01:00
|
|
|
public static void main(String[] args) throws IOException {
|
2020-01-06 17:40:19 +01:00
|
|
|
Set<ObjectProcessor<?>> processors = new HashSet<>();
|
2019-12-30 14:53:40 +01:00
|
|
|
processors.add(new LoginCredentialProcessor());
|
|
|
|
processors.add(new MessageProcessor());
|
2020-01-30 12:52:27 +01:00
|
|
|
processors.add(new MessageStatusChangeProcessor());
|
2020-02-01 23:37:44 +01:00
|
|
|
processors.add(new UserStatusChangeProcessor());
|
2020-01-28 19:25:30 +01:00
|
|
|
processors.add(new IdGeneratorRequestProcessor());
|
2019-12-30 14:53:40 +01:00
|
|
|
Server server = new Server(8080, () -> new ObjectMessageReader(), new ObjectMessageProcessor(processors));
|
2020-01-18 09:55:12 +01:00
|
|
|
|
2020-01-28 20:46:27 +01:00
|
|
|
initializeCurrentMessageId();
|
2020-01-18 09:55:12 +01:00
|
|
|
|
2019-12-28 14:48:39 +01:00
|
|
|
server.start();
|
2020-01-03 17:11:38 +01:00
|
|
|
server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance());
|
2019-12-28 14:48:39 +01:00
|
|
|
}
|
2020-01-28 20:46:27 +01:00
|
|
|
|
|
|
|
private static void initializeCurrentMessageId() {
|
|
|
|
PersistenceManager persMan = PersistenceManager.getPersistenceManager();
|
|
|
|
if (persMan.getConfigItemById("currentMessageId") == null) persMan.addConfigItem(new ConfigItem("currentMessageId", "0"));
|
|
|
|
}
|
2019-12-28 14:48:39 +01:00
|
|
|
}
|