1 package org.lsst.ccs.bus;
2
3 import java.io.Serializable;
4
5
6
7
8
9
10
11
12
13
14 public class Bus<T extends BusPayload> implements Serializable {
15
16 public static final Bus<LogEvent> LOG = new Bus<LogEvent>("LOG", 0);
17 public static final Bus<Status> STATUS = new Bus<Status>("STATUS", 1);
18 public static final Bus<CommandBusMessage> COMMAND = new Bus<CommandBusMessage>("COMMAND", 2);
19 private static final Bus[] vals = {LOG, STATUS, COMMAND};
20 private static final long serialVersionUID = -5478704370712583354L;
21
22 private String name;
23 private int ordinal;
24
25 private Bus(String name, int ordinal) {
26 this.name = name;
27 this.ordinal = ordinal;
28 }
29
30 public String toString() {
31 return this.name;
32 }
33
34 public int ordinal() {
35 return this.ordinal;
36 }
37
38
39
40
41
42
43 public static Bus valueOf(String str) {
44
45 String upperStr = str != null ? str.toUpperCase() : str;
46 switch (upperStr) {
47 case "COMMAND":
48 return COMMAND;
49 case "STATUS":
50 return STATUS;
51 case "LOG":
52 return LOG;
53 default:
54 throw new IllegalArgumentException(str);
55
56 }
57 }
58
59
60
61
62 public static Bus[] values() {
63 return vals;
64 }
65 }