@SuppressWarnings("unchecked") @NotNull public <R extends ServerResult> P4CommandRunner.ActionAnswer<R> perform( @NotNull ServerConfig config, @NotNull P4CommandRunner.ServerAction<R> action) { ServerActionRunner<?> runner = serverActionRunners.get(action.getCmd()); if (runner == null) { throw new IllegalStateException("command not supported: " + action.getCmd()); } return ((ServerActionRunner<R>) runner).perform(config, action); }
@SuppressWarnings("unchecked") @NotNull @Override public <R extends ServerResult> ActionAnswer<R> perform( @NotNull ServerConfig config, @NotNull ServerAction<R> action) { switch (action.getCmd()) { case LOGIN: return (ActionAnswer<R>) login(config, (LoginAction) action); case CREATE_JOB: return (ActionAnswer<R>) createJob(config, (CreateJobAction) action); default: throw new IllegalStateException("Incompatible class: should match " + ServerActionCmd.class); } }
@NotNull static State getState(String sourceId, @NotNull P4CommandRunner.ServerAction<?> action) { State ret = new State(); ret.sourceId = sourceId; ret.actionId = action.getActionId(); ret.serverActionCmd = action.getCmd(); ret.clientActionCmd = null; ret.data = new PrimitiveMap(); switch (action.getCmd()) { case CREATE_JOB: ret.data.putP4Job("job", ((CreateJobAction) action).getJob()); break; case LOGIN: throw new IllegalArgumentException("Should not attempt to store a submit action"); default: throw new IllegalArgumentException("Unknown server cmd " + action.getCmd()); } return ret; }
@NotNull private CurateResult curateServerActions( @NotNull P4CommandRunner.ServerAction<?> added, @NotNull P4CommandRunner.ServerAction<?> existing) { switch (added.getCmd()) { case CREATE_JOB: if (existing.getCmd() == P4CommandRunner.ServerActionCmd.CREATE_JOB) { if (((CreateJobAction) added).getJob().getJobId().equals( ((CreateJobAction) existing).getJob().getJobId())) { // Duplicate add of the same job ID if (LOG.isDebugEnabled()) { LOG.debug("Remove duplicate action `create job " + ((CreateJobAction) added).getJob().getJobId() + "`"); } return KEEP_EXISTING_REMOVE_ADDED_STOP; } } return KEEP_BOTH_CONTINUE; case LOGIN: // Shouldn't ever be in the pending list... LOG.warn("Purging LOGIN actions from list; should never have been added"); return KEEP_EXISTING_REMOVE_ADDED_STOP; default: return KEEP_BOTH_CONTINUE; } }
private void renderActionChoice(ActionChoice value) { final String text = value.when( (c) -> c.getCmd().name().toLowerCase().replace('_', ' '), (s) -> s.getCmd().name().toLowerCase().replace('_', ' ') ); append(text, PENDING_ACTION_STYLE); String[] params = value.getDisplayParameters(); if (params.length > 0) { boolean first = true; for (String param : params) { if (first) { append(" (", PENDING_ACTION_SEPARATOR_STYLE); first = false; } else { append(", ", PENDING_ACTION_SEPARATOR_STYLE); } append(param, PENDING_ACTION_PARAMETER_STYLE); } append(")", PENDING_ACTION_SEPARATOR_STYLE); } }
@Override public String toString() { return client != null ? ("ClientAction(" + client.getCmd() + ")") : ("ServerAction(" + server.getCmd() + ")"); }