This repository has been archived on 2021-12-05. You can view files and clone it, but cannot push or open issues or pull requests.
envoy/src/main/java/envoy/server/Startup.java

53 lines
1.7 KiB
Java
Raw Normal View History

package envoy.server;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import com.jenkov.nioserver.Server;
import envoy.server.data.ConfigItem;
import envoy.server.database.PersistenceManager;
import envoy.server.net.ObjectMessageProcessor;
import envoy.server.net.ObjectMessageReader;
import envoy.server.processors.*;
/**
2019-12-30 15:15:25 +01:00
* Starts the server.<br>
* <br>
* 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
*
* @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
*/
public static void main(String[] args) throws IOException {
Set<ObjectProcessor<?>> processors = new HashSet<>();
processors.add(new LoginCredentialProcessor());
processors.add(new MessageProcessor());
processors.add(new MessageStatusChangeProcessor());
processors.add(new UserStatusChangeProcessor());
processors.add(new IdGeneratorRequestProcessor());
Server server = new Server(8080, () -> new ObjectMessageReader(), new ObjectMessageProcessor(processors));
initializeCurrentMessageId();
server.start();
server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance());
}
private static void initializeCurrentMessageId() {
PersistenceManager persMan = PersistenceManager.getPersistenceManager();
if (persMan.getConfigItemById("currentMessageId") == null) persMan.addConfigItem(new ConfigItem("currentMessageId", "0"));
}
}