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.data.PersistenceManager; import envoy.server.net.ConnectionManager; import envoy.server.net.ObjectMessageProcessor; import envoy.server.net.ObjectMessageReader; import envoy.server.processors.*; /** * Starts the server.
*
* Project: envoy-server-standalone
* File: Startup.java
* Created: 24.12.2019
* * @author Kai S. K. Engelbart * @since Envoy Server Standalone v0.1-alpha */ public class Startup { /** * 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> processors = new HashSet<>(); processors.add(new LoginCredentialProcessor()); processors.add(new MessageProcessor()); processors.add(new MessageStatusChangeProcessor()); processors.add(new UserStatusChangeProcessor()); processors.add(new IdGeneratorRequestProcessor()); processors.add(new ContactsRequestEventProcessor()); processors.add(new ContactOperationProcessor()); Server server = new Server(8080, () -> new ObjectMessageReader(), new ObjectMessageProcessor(processors)); initializeCurrentMessageId(); server.start(); server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance()); System.out.println("Press the return key to stop the server..."); System.in.read(); System.out.println("Stopped"); System.exit(0); } private static void initializeCurrentMessageId() { PersistenceManager persMan = PersistenceManager.getInstance(); if (persMan.getConfigItemById("currentMessageId") == null) persMan.addConfigItem(new ConfigItem("currentMessageId", "0")); } }