1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.surefire.api.booter;
20
21 import java.util.HashMap;
22 import java.util.Map;
23
24 import org.apache.maven.surefire.api.stream.AbstractStreamDecoder.Segment;
25
26 import static java.nio.charset.StandardCharsets.US_ASCII;
27 import static java.util.Objects.requireNonNull;
28
29
30
31
32
33
34
35 public enum MasterProcessCommand {
36 RUN_CLASS("run-testclass", String.class),
37 TEST_SET_FINISHED("testset-finished", Void.class),
38 SKIP_SINCE_NEXT_TEST("skip-since-next-test", Void.class),
39 SHUTDOWN("shutdown", String.class),
40
41
42 NOOP("noop", Void.class),
43 BYE_ACK("bye-ack", Void.class);
44
45
46 public static final Map<Segment, MasterProcessCommand> COMMAND_TYPES = segmentsToCmds();
47
48 private final String opcode;
49 private final byte[] opcodeBinary;
50 private final Class<?> dataType;
51
52 MasterProcessCommand(String opcode, Class<?> dataType) {
53 this.opcode = requireNonNull(opcode, "value cannot be null");
54 opcodeBinary = opcode.getBytes(US_ASCII);
55 this.dataType = requireNonNull(dataType, "dataType cannot be null");
56 }
57
58 public byte[] getOpcodeBinary() {
59 return opcodeBinary;
60 }
61
62 public int getOpcodeLength() {
63 return opcodeBinary.length;
64 }
65
66 public Class<?> getDataType() {
67 return dataType;
68 }
69
70 public boolean hasDataType() {
71 return dataType != Void.class;
72 }
73
74 @Override
75 public String toString() {
76 return opcode;
77 }
78
79 private static Map<Segment, MasterProcessCommand> segmentsToCmds() {
80 Map<Segment, MasterProcessCommand> commands = new HashMap<>();
81 for (MasterProcessCommand command : MasterProcessCommand.values()) {
82 byte[] array = command.toString().getBytes(US_ASCII);
83 commands.put(new Segment(array, 0, array.length), command);
84 }
85 return commands;
86 }
87 }