2019-12-28 14:48:39 +01:00
|
|
|
package envoy.server;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2019-12-30 14:53:40 +01:00
|
|
|
import java.util.Set;
|
2020-06-11 11:45:17 +02:00
|
|
|
import java.util.logging.Level;
|
2019-12-28 14:48:39 +01:00
|
|
|
|
|
|
|
import com.jenkov.nioserver.Server;
|
|
|
|
|
2020-09-25 14:29:23 +02:00
|
|
|
import envoy.server.data.*;
|
|
|
|
import envoy.server.net.*;
|
2020-07-05 16:53:27 +02:00
|
|
|
import envoy.server.processors.*;
|
2020-06-11 11:45:17 +02:00
|
|
|
import envoy.util.EnvoyLog;
|
2020-01-03 15:40:43 +01:00
|
|
|
|
2019-12-28 14:48:39 +01:00
|
|
|
/**
|
2020-09-25 14:29:23 +02:00
|
|
|
* Starts the server.
|
2019-12-30 15:15:25 +01:00
|
|
|
*
|
2019-12-28 14:48:39 +01:00
|
|
|
* @author Kai S. K. Engelbart
|
|
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
|
|
*/
|
2020-08-22 13:37:07 +02:00
|
|
|
public final class Startup {
|
2019-12-28 14:48:39 +01:00
|
|
|
|
2020-06-11 11:45:17 +02:00
|
|
|
/**
|
2020-08-22 13:15:42 +02:00
|
|
|
* Stores the configuration used for the whole server
|
2020-06-11 11:45:17 +02:00
|
|
|
*/
|
2020-08-22 13:15:42 +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.
|
|
|
|
*
|
2020-07-02 20:01:28 +02:00
|
|
|
* @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
|
|
|
|
*/
|
2019-12-28 14:48:39 +01:00
|
|
|
public static void main(String[] args) throws IOException {
|
2020-08-22 13:15:42 +02:00
|
|
|
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
|
|
|
|
2020-08-16 17:14:41 +02:00
|
|
|
final var server = new Server(8080, ObjectMessageReader::new,
|
2020-06-12 10:56:02 +02:00
|
|
|
new ObjectMessageProcessor(Set.of(new LoginCredentialProcessor(),
|
|
|
|
new MessageProcessor(),
|
2020-06-12 23:53:40 +02:00
|
|
|
new GroupMessageProcessor(),
|
2020-06-12 10:56:02 +02:00
|
|
|
new GroupCreationProcessor(),
|
|
|
|
new MessageStatusChangeProcessor(),
|
2020-07-03 16:25:49 +02:00
|
|
|
new GroupMessageStatusChangeProcessor(),
|
2020-06-12 10:56:02 +02:00
|
|
|
new UserStatusChangeProcessor(),
|
|
|
|
new IDGeneratorRequestProcessor(),
|
2020-07-13 21:34:21 +02:00
|
|
|
new UserSearchProcessor(),
|
2020-07-25 16:26:13 +02:00
|
|
|
new ContactOperationProcessor(),
|
2020-08-01 09:54:18 +02:00
|
|
|
new IsTypingProcessor(),
|
2020-08-01 14:57:08 +02:00
|
|
|
new NameChangeProcessor(),
|
|
|
|
new ProfilePicChangeProcessor(),
|
2020-08-16 17:14:41 +02:00
|
|
|
new PasswordChangeRequestProcessor(),
|
|
|
|
new IssueProposalProcessor())));
|
2020-01-18 09:55:12 +01:00
|
|
|
|
2020-04-06 22:55:27 +02:00
|
|
|
// Initialize the current message ID
|
2020-08-16 17:14:41 +02:00
|
|
|
final var persistenceManager = PersistenceManager.getInstance();
|
2020-04-06 22:55:27 +02:00
|
|
|
if (persistenceManager.getConfigItemByID("currentMessageId") == null)
|
2020-06-11 11:45:17 +02:00
|
|
|
persistenceManager.addConfigItem(new envoy.server.data.ConfigItem("currentMessageId", "0"));
|
2020-01-18 09:55:12 +01:00
|
|
|
|
2019-12-28 14:48:39 +01:00
|
|
|
server.start();
|
2020-01-03 17:11:38 +01:00
|
|
|
server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance());
|
2020-02-07 09:34:02 +01:00
|
|
|
|
2020-08-22 13:15:42 +02:00
|
|
|
if (config.isEnterToStop()) {
|
|
|
|
System.out.println("Press Enter to stop the server...");
|
2020-07-02 20:01:28 +02:00
|
|
|
System.in.read();
|
|
|
|
System.out.println("Stopped");
|
|
|
|
System.exit(0);
|
|
|
|
}
|
2019-12-28 14:48:39 +01:00
|
|
|
}
|
2020-03-23 22:12:27 +01:00
|
|
|
}
|