60 lines
1.9 KiB
Java
Executable File
60 lines
1.9 KiB
Java
Executable File
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.<br>
|
|
* <br>
|
|
* Project: <strong>envoy-server-standalone</strong><br>
|
|
* File: <strong>Startup.java</strong><br>
|
|
* Created: <strong>24.12.2019</strong><br>
|
|
*
|
|
* @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<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));
|
|
|
|
// Initialize the current message ID
|
|
PersistenceManager persistenceManager = PersistenceManager.getInstance();
|
|
if (persistenceManager.getConfigItemByID("currentMessageId") == null)
|
|
persistenceManager.addConfigItem(new ConfigItem("currentMessageId", "0"));
|
|
|
|
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);
|
|
}
|
|
}
|