|
1 | 1 | package org.bread_experts_group.application_carpool.supervisor |
2 | 2 |
|
3 | | -import java.lang.Integer.parseInt |
| 3 | +import org.bread_experts_group.command_line.Flag |
| 4 | +import org.bread_experts_group.command_line.readArgs |
| 5 | +import org.bread_experts_group.command_line.stringToInt |
| 6 | +import java.nio.file.Path |
4 | 7 | import java.rmi.registry.LocateRegistry |
5 | 8 | import java.util.logging.FileHandler |
6 | 9 | import java.util.logging.Level |
7 | 10 | import java.util.logging.Logger |
8 | 11 | import kotlin.io.path.Path |
9 | 12 | import kotlin.system.exitProcess |
10 | 13 |
|
| 14 | +private val FLAGS = listOf( |
| 15 | + Flag( |
| 16 | + "log_level", |
| 17 | + "Log level", |
| 18 | + default = Level.INFO, |
| 19 | + conv = Level::parse |
| 20 | + ), |
| 21 | + Flag( |
| 22 | + "port", |
| 23 | + "Port", |
| 24 | + default = 1099, |
| 25 | + conv = stringToInt() |
| 26 | + ), |
| 27 | + Flag( |
| 28 | + "log_dir", |
| 29 | + "Log directory", |
| 30 | + default = Path("./logs/"), |
| 31 | + conv = { Path(it) } |
| 32 | + ) |
| 33 | +) |
11 | 34 | private val LOGGER = Logger.getLogger("Application Carpool Supervisor") |
12 | 35 |
|
13 | 36 | fun main(args: Array<String>) { |
| 37 | + val args = readArgs( |
| 38 | + args, |
| 39 | + FLAGS, |
| 40 | + "Application Carpool Supervisor", |
| 41 | + "Application Carpool Supervisor process" |
| 42 | + ) |
14 | 43 | val pid = ProcessHandle.current().pid() |
15 | | - val port = parseInt(args[1]) |
| 44 | + val port = args.getRequired<Int>("port") |
16 | 45 |
|
17 | 46 | LOGGER.useParentHandlers = false |
18 | | - LOGGER.addHandler(FileHandler(Path(args[2]).resolve("supervisor-log.txt").toString())) |
19 | | - LOGGER.level = Level.parse(args[0]) |
| 47 | + LOGGER.addHandler(FileHandler( |
| 48 | + args.getRequired<Path>("log_dir").resolve("supervisor-log.txt").toString() |
| 49 | + )) |
| 50 | + LOGGER.level = args.getRequired<Level>("log_level") |
20 | 51 | LOGGER.info { "Starting supervisor daemon -- PID $pid" } |
21 | 52 |
|
22 | 53 | var registry = LocateRegistry.getRegistry(port) |
|
0 commit comments