2019-12-28 14:48:39 +01:00
|
|
|
package envoy.server;
|
|
|
|
|
2020-06-11 11:45:17 +02:00
|
|
|
import java.io.File;
|
2019-12-28 14:48:39 +01:00
|
|
|
import java.io.IOException;
|
2020-06-11 11:45:17 +02:00
|
|
|
import java.util.HashMap;
|
2019-12-30 14:53:40 +01:00
|
|
|
import java.util.HashSet;
|
|
|
|
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-06-11 11:45:17 +02:00
|
|
|
import envoy.data.Config;
|
|
|
|
import envoy.data.ConfigItem;
|
2020-02-15 22:43:20 +01:00
|
|
|
import envoy.server.data.PersistenceManager;
|
2020-02-12 22:01:32 +01:00
|
|
|
import envoy.server.net.ConnectionManager;
|
2020-01-03 15:40:43 +01:00
|
|
|
import envoy.server.net.ObjectMessageProcessor;
|
|
|
|
import envoy.server.net.ObjectMessageReader;
|
2020-06-11 11:45:17 +02:00
|
|
|
import envoy.server.processors.*;
|
|
|
|
import envoy.util.EnvoyLog;
|
2020-01-03 15:40:43 +01:00
|
|
|
|
2019-12-28 14:48:39 +01:00
|
|
|
/**
|
2019-12-30 15:15:25 +01:00
|
|
|
* Starts the server.<br>
|
|
|
|
* <br>
|
2019-12-28 14:48:39 +01:00
|
|
|
* 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
|
|
|
*
|
2019-12-28 14:48:39 +01:00
|
|
|
* @author Kai S. K. Engelbart
|
|
|
|
* @since Envoy Server Standalone v0.1-alpha
|
|
|
|
*/
|
|
|
|
public class Startup {
|
|
|
|
|
2020-06-11 11:45:17 +02:00
|
|
|
/**
|
|
|
|
* Initializes the logger with a new config instance.
|
|
|
|
*
|
|
|
|
* @since Envoy Server Standalone v0.1-beta
|
|
|
|
*/
|
|
|
|
private static void initLogging() {
|
|
|
|
final var items = new HashMap<String, ConfigItem<?>>();
|
|
|
|
items.put("homeDirectory",
|
|
|
|
new ConfigItem<>("homeDirectory", "h", File::new, new File(System.getProperty("user.home"), ".envoy-server"), true));
|
|
|
|
items.put("fileLevelBarrier", new ConfigItem<>("fileLevelBarrier", "fb", Level::parse, Level.SEVERE, true));
|
2020-06-11 12:06:06 +02:00
|
|
|
items.put("consoleLevelBarrier", new ConfigItem<>("consoleLevelBarrier", "cb", Level::parse, Level.FINE, true));
|
2020-06-11 11:45:17 +02:00
|
|
|
|
|
|
|
final var config = new Config();
|
|
|
|
config.load(items);
|
|
|
|
|
|
|
|
EnvoyLog.initialize(config);
|
2020-06-11 12:08:51 +02:00
|
|
|
EnvoyLog.attach("envoy");
|
2020-06-11 11:45:17 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
2019-12-28 14:48:39 +01:00
|
|
|
public static void main(String[] args) throws IOException {
|
2020-06-11 11:45:17 +02:00
|
|
|
initLogging();
|
|
|
|
|
2020-01-06 17:40:19 +01:00
|
|
|
Set<ObjectProcessor<?>> processors = new HashSet<>();
|
2019-12-30 14:53:40 +01:00
|
|
|
processors.add(new LoginCredentialProcessor());
|
|
|
|
processors.add(new MessageProcessor());
|
2020-06-09 21:05:30 +02:00
|
|
|
processors.add(new GroupCreationProcessor());
|
2020-06-06 15:42:10 +02:00
|
|
|
processors.add(new GroupMessageProcessor());
|
2020-01-30 12:52:27 +01:00
|
|
|
processors.add(new MessageStatusChangeProcessor());
|
2020-02-01 23:37:44 +01:00
|
|
|
processors.add(new UserStatusChangeProcessor());
|
2020-03-24 18:41:26 +01:00
|
|
|
processors.add(new IDGeneratorRequestProcessor());
|
2020-02-10 22:29:34 +01:00
|
|
|
processors.add(new ContactsRequestEventProcessor());
|
2020-02-09 22:16:33 +01:00
|
|
|
processors.add(new ContactOperationProcessor());
|
2020-06-11 11:45:17 +02:00
|
|
|
Server server = new Server(8080, ObjectMessageReader::new, new ObjectMessageProcessor(processors));
|
2020-01-18 09:55:12 +01:00
|
|
|
|
2020-04-06 22:55:27 +02:00
|
|
|
// Initialize the current message ID
|
|
|
|
PersistenceManager 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"));
|
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-02-07 10:02:40 +01:00
|
|
|
System.out.println("Press the return key to stop the server...");
|
2020-02-07 09:34:02 +01:00
|
|
|
System.in.read();
|
2020-03-14 15:08:58 +01:00
|
|
|
System.out.println("Stopped");
|
2020-02-07 09:34:02 +01:00
|
|
|
System.exit(0);
|
2019-12-28 14:48:39 +01:00
|
|
|
}
|
2020-03-23 22:12:27 +01:00
|
|
|
}
|