89 lines
2.8 KiB
Java
89 lines
2.8 KiB
Java
package com.mediamanager;
|
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.util.Properties;
|
|
|
|
import com.mediamanager.service.database.DatabaseManager;
|
|
|
|
public class MediaManagerApplication {
|
|
private static final Logger logger = LogManager.getLogger(MediaManagerApplication.class);
|
|
private static Properties config;
|
|
private static DatabaseManager databaseManager;
|
|
|
|
public static void main(String[] args) {
|
|
logger.info("Starting MediaManager Core Application...");
|
|
|
|
try {
|
|
// Load configuration
|
|
loadConfiguration();
|
|
databaseManager = new DatabaseManager(config);
|
|
databaseManager.init();
|
|
|
|
|
|
// TODO: Initialize IPC server with named pipes
|
|
// TODO: Start application services
|
|
|
|
logger.info("MediaManager Core started successfully");
|
|
logger.info("IPC Pipe: {}", config.getProperty("ipc.pipe.path") + "/" + config.getProperty("ipc.pipe.name"));
|
|
|
|
// Keep application running
|
|
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
|
|
|
logger.info("Shutting down MediaManager Core...");
|
|
|
|
|
|
if (databaseManager != null) {
|
|
databaseManager.close();
|
|
}
|
|
|
|
|
|
logger.info("MediaManager Core shutdown successfully");
|
|
logger.info("Goodbye!");
|
|
|
|
|
|
// Give Log4j2 time to write all pending messages before shutting down
|
|
try {
|
|
Thread.sleep(1000);
|
|
} catch (InterruptedException e) {
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
|
|
// Now shutdown Log4j2
|
|
org.apache.logging.log4j.LogManager.shutdown();
|
|
}));
|
|
logger.info("Application is running");
|
|
logger.info("Press Ctrl+C to exit");
|
|
Thread.currentThread().join();
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
logger.info("Application interrupted, initiating shutdown...");
|
|
|
|
Thread.currentThread().interrupt();
|
|
|
|
} catch (Exception e) {
|
|
logger.error("Failed to start MediaManager Core", e);
|
|
System.exit(1);
|
|
}
|
|
}
|
|
|
|
private static void loadConfiguration() throws IOException {
|
|
config = new Properties();
|
|
try (InputStream input = MediaManagerApplication.class.getClassLoader().getResourceAsStream("config.properties")) {
|
|
if (input == null) {
|
|
throw new IOException("Unable to find config.properties");
|
|
}
|
|
config.load(input);
|
|
logger.info("Configuration loaded successfully");
|
|
}
|
|
}
|
|
|
|
public static Properties getConfig() {
|
|
return config;
|
|
}
|
|
}
|