67 lines
1.8 KiB
Java
67 lines
1.8 KiB
Java
package ru.kirillius.pf.sdn;
|
|
|
|
import lombok.Getter;
|
|
import org.eclipse.jetty.server.Server;
|
|
import ru.kirillius.pf.sdn.External.API.HEInfoProvider;
|
|
import ru.kirillius.pf.sdn.core.Auth.AuthManager;
|
|
import ru.kirillius.pf.sdn.core.Config;
|
|
import ru.kirillius.pf.sdn.core.Context;
|
|
import ru.kirillius.pf.sdn.core.ContextEventsHandler;
|
|
import ru.kirillius.pf.sdn.core.Networking.ASInfoService;
|
|
import ru.kirillius.pf.sdn.core.Networking.NetworkManager;
|
|
|
|
import java.io.Closeable;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
|
|
public class AppContext implements Context, Closeable {
|
|
|
|
public AppContext(File configFile) {
|
|
try {
|
|
config = Config.load(configFile);
|
|
} catch (IOException e) {
|
|
config = new Config();
|
|
try {
|
|
Config.store(config, configFile);
|
|
} catch (IOException ex) {
|
|
throw new RuntimeException(ex);
|
|
}
|
|
}
|
|
|
|
authManager = new AuthManager(this);
|
|
server = new Server();
|
|
ASInfoService = new ASInfoService();
|
|
ASInfoService.setProvider(new HEInfoProvider(this));
|
|
networkManager = new NetworkManager(this);
|
|
networkManager.getInputResources().add(config.getCustomResources());
|
|
}
|
|
|
|
|
|
@Getter
|
|
private final NetworkManager networkManager;
|
|
@Getter
|
|
private Config config;
|
|
@Getter
|
|
private final AuthManager authManager;
|
|
@Getter
|
|
private final Server server;
|
|
@Getter
|
|
private final ASInfoService ASInfoService;
|
|
|
|
@Override
|
|
public void close() throws IOException {
|
|
ASInfoService.close();
|
|
networkManager.close();
|
|
try {
|
|
server.stop();
|
|
} catch (Exception e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
|
|
@Getter
|
|
private final ContextEventsHandler EventsHandler = new ContextEventsHandler();
|
|
|
|
|
|
}
|