[server] Mapping grid roles to launchers as enum values without conversion to strings
Stoppable launch(PrintStream out);
}
- private static Map<String, Function<String[], GridItemLauncher>> LAUNCHERS = buildLaunchers();
+ private static Map<GridRole, Function<String[], GridItemLauncher>> LAUNCHERS = buildLaunchers();
public static void main(String[] args) {
new GridLauncherV3().launch(args);
@@ -118,12 +118,12 @@ private GridItemLauncher buildLauncher(String[] args) {
}
GridRole gridRole = GridRole.get(role);
- if (gridRole == null || LAUNCHERS.get(gridRole.toString()) == null) {
+ if (gridRole == null || LAUNCHERS.get(gridRole) == null) {
printInfoAboutRoles(role);
return null;
}
- return LAUNCHERS.get(gridRole.toString()).apply(args);
+ return LAUNCHERS.get(gridRole).apply(args);
}
private void printInfoAboutRoles(String roleCommandLineArg) {
@@ -208,7 +208,7 @@ private static void configureLogging(String log, boolean debug) {
}
}
- private static Map<String, Function<String[], GridItemLauncher>> buildLaunchers() {
+ private static Map<GridRole, Function<String[], GridItemLauncher>> buildLaunchers() {
BiConsumer<JCommander, PrintStream> usage = (commander, out) -> {
StringBuilder toPrint = new StringBuilder();
commander.usage(toPrint);
@@ -222,11 +222,8 @@ private static void configureLogging(String log, boolean debug) {
buildInfo.getBuildRevision()));
};
- ImmutableMap.Builder<String, Function<String[], GridItemLauncher>> launchers =
- ImmutableMap.<String, Function<String[], GridItemLauncher>>builder()
- .put(GridRole.NOT_GRID.toString(), (args) -> new GridItemLauncher() {
- @Override
- public Stoppable launch(PrintStream out) {
+ return ImmutableMap.<GridRole, Function<String[], GridItemLauncher>>builder()
+ .put(GridRole.NOT_GRID, (args) -> out -> {
StandaloneCliOptions options = new StandaloneCliOptions();
JCommander commander = options.parse(args);
@@ -253,12 +250,9 @@ public Stoppable launch(PrintStream out) {
SeleniumServer server = new SeleniumServer(configuration);
server.boot();
return server;
- }
})
- .put(GridRole.HUB.toString(), (args) -> new GridItemLauncher() {
- @Override
- public Stoppable launch(PrintStream out) {
+ .put(GridRole.HUB, (args) -> out -> {
GridHubCliOptions options = new GridHubCliOptions();
JCommander commander = options.parse(args);
@@ -285,12 +279,9 @@ public Stoppable launch(PrintStream out) {
Hub hub = new Hub(configuration);
hub.start();
return hub;
- }
})
- .put(GridRole.NODE.toString(), (args) -> new GridItemLauncher() {
- @Override
- public Stoppable launch(PrintStream out) {
+ .put(GridRole.NODE, (args) -> out -> {
GridNodeCliOptions options = new GridNodeCliOptions();
JCommander commander = options.parse(args);
@@ -325,9 +316,7 @@ public Stoppable launch(PrintStream out) {
remote.startRegistrationProcess();
}
return server;
- }
- });
-
- return launchers.build();
+ })
+ .build();
}
}
