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/server/src/main/java/envoy/server/Startup.java

78 lines
2.3 KiB
Java
Raw Normal View History

package envoy.server;
import java.io.IOException;
import java.util.Set;
2020-06-11 11:45:17 +02:00
import java.util.logging.Level;
import com.jenkov.nioserver.Server;
import envoy.server.data.*;
import envoy.server.net.*;
import envoy.server.processors.*;
2020-06-11 11:45:17 +02:00
import envoy.util.EnvoyLog;
/**
* Starts the server.
2019-12-30 15:15:25 +01:00
*
* @author Kai S. K. Engelbart
* @since Envoy Server Standalone v0.1-alpha
*/
public final class Startup {
2020-06-11 11:45:17 +02:00
/**
* Stores the configuration used for the whole server
2020-06-11 11:45:17 +02:00
*/
public static final ServerConfig config = ServerConfig.getInstance();
2020-06-11 11:45:17 +02:00
2019-12-30 15:15:25 +01:00
/**
* Starts the server.
*
* @param args the run configuration. If it is "no-enter-to-stop" at position 0,
* no command to read in an enter press will be generated
2019-12-30 15:15:25 +01:00
* @throws IOException if the server crashes
* @since Envoy Server Standalone v0.1-alpha
*/
public static void main(String[] args) throws IOException {
try {
config.loadAll(Startup.class, "server.properties", args);
EnvoyLog.initialize(config);
} catch (final IllegalStateException e) {
EnvoyLog.getLogger(Startup.class).log(Level.SEVERE, "Error loading configuration values: ", e);
System.exit(1);
}
2020-06-11 11:45:17 +02:00
final var server = new Server(8080, ObjectMessageReader::new,
new ObjectMessageProcessor(Set.of(new LoginCredentialProcessor(),
new MessageProcessor(),
new GroupMessageProcessor(),
new GroupCreationProcessor(),
new MessageStatusChangeProcessor(),
new GroupMessageStatusChangeProcessor(),
new UserStatusChangeProcessor(),
new GroupResizeProcessor(),
new IDGeneratorRequestProcessor(),
new UserSearchProcessor(),
new UserOperationProcessor(),
new IsTypingProcessor(),
new NameChangeProcessor(),
new ProfilePicChangeProcessor(),
new PasswordChangeRequestProcessor(),
new IssueProposalProcessor())));
// Initialize the current message ID
final var persistenceManager = PersistenceManager.getInstance();
if (persistenceManager.getConfigItemByID("currentMessageId") == null)
2020-06-11 11:45:17 +02:00
persistenceManager.addConfigItem(new envoy.server.data.ConfigItem("currentMessageId", "0"));
server.start();
server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance());
if (config.isEnterToStop()) {
System.out.println("Press Enter to stop the server...");
System.in.read();
System.out.println("Stopped");
System.exit(0);
}
}
}