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

61 lines
1.9 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.data.PersistenceManager;
import envoy.server.net.ConnectionManager;
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());
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());
2020-02-07 10:02:40 +01:00
System.out.println("Press the return key to stop the server...");
System.in.read();
2020-03-14 15:08:58 +01:00
System.out.println("Stopped");
System.exit(0);
}
private static void initializeCurrentMessageId() {
2020-02-12 07:10:33 +01:00
PersistenceManager persMan = PersistenceManager.getInstance();
if (persMan.getConfigItemById("currentMessageId") == null) persMan.addConfigItem(new ConfigItem("currentMessageId", "0"));
}
}