|
16 | 16 |
|
17 | 17 | package org.springframework.messaging.simp.stomp; |
18 | 18 |
|
19 | | -import java.util.Arrays; |
20 | | -import java.util.Collection; |
21 | | -import java.util.HashMap; |
22 | | -import java.util.Map; |
23 | | - |
24 | 19 | import org.springframework.messaging.simp.SimpMessageType; |
25 | 20 |
|
26 | 21 | /** |
|
32 | 27 | public enum StompCommand { |
33 | 28 |
|
34 | 29 | // client |
35 | | - CONNECT, |
36 | | - STOMP, |
37 | | - DISCONNECT, |
38 | | - SUBSCRIBE, |
39 | | - UNSUBSCRIBE, |
40 | | - SEND, |
41 | | - ACK, |
42 | | - NACK, |
43 | | - BEGIN, |
44 | | - COMMIT, |
45 | | - ABORT, |
| 30 | + CONNECT(SimpMessageType.CONNECT, 0), |
| 31 | + STOMP(SimpMessageType.CONNECT, 0), |
| 32 | + DISCONNECT(SimpMessageType.DISCONNECT, 0), |
| 33 | + SUBSCRIBE(SimpMessageType.SUBSCRIBE, 3), |
| 34 | + UNSUBSCRIBE(SimpMessageType.UNSUBSCRIBE, 2), |
| 35 | + SEND(SimpMessageType.MESSAGE, 13), |
| 36 | + ACK(SimpMessageType.OTHER, 0), |
| 37 | + NACK(SimpMessageType.OTHER, 0), |
| 38 | + BEGIN(SimpMessageType.OTHER, 0), |
| 39 | + COMMIT(SimpMessageType.OTHER, 0), |
| 40 | + ABORT(SimpMessageType.OTHER, 0), |
46 | 41 |
|
47 | 42 | // server |
48 | | - CONNECTED, |
49 | | - MESSAGE, |
50 | | - RECEIPT, |
51 | | - ERROR; |
52 | | - |
53 | | - |
54 | | - private static Map<StompCommand, SimpMessageType> messageTypes = new HashMap<>(); |
55 | | - static { |
56 | | - messageTypes.put(StompCommand.CONNECT, SimpMessageType.CONNECT); |
57 | | - messageTypes.put(StompCommand.STOMP, SimpMessageType.CONNECT); |
58 | | - messageTypes.put(StompCommand.SEND, SimpMessageType.MESSAGE); |
59 | | - messageTypes.put(StompCommand.MESSAGE, SimpMessageType.MESSAGE); |
60 | | - messageTypes.put(StompCommand.SUBSCRIBE, SimpMessageType.SUBSCRIBE); |
61 | | - messageTypes.put(StompCommand.UNSUBSCRIBE, SimpMessageType.UNSUBSCRIBE); |
62 | | - messageTypes.put(StompCommand.DISCONNECT, SimpMessageType.DISCONNECT); |
| 43 | + CONNECTED(SimpMessageType.OTHER, 0), |
| 44 | + MESSAGE(SimpMessageType.MESSAGE, 15), |
| 45 | + RECEIPT(SimpMessageType.OTHER, 0), |
| 46 | + ERROR(SimpMessageType.OTHER, 12); |
| 47 | + |
| 48 | + private static final int DESTINATION_REQUIRED = 1; |
| 49 | + private static final int SUBSCRIPTION_ID_REQUIRED = 2; |
| 50 | + private static final int CONTENT_LENGTH_REQUIRED = 4; |
| 51 | + private static final int BODY_ALLOWED = 8; |
| 52 | + |
| 53 | + private final SimpMessageType simpMessageType; |
| 54 | + private final int flags; |
| 55 | + |
| 56 | + StompCommand(final SimpMessageType simpMessageType, final int flags) { |
| 57 | + this.simpMessageType = simpMessageType; |
| 58 | + this.flags = flags; |
63 | 59 | } |
64 | 60 |
|
65 | | - private static Collection<StompCommand> destinationRequired = Arrays.asList(SEND, SUBSCRIBE, MESSAGE); |
66 | | - private static Collection<StompCommand> subscriptionIdRequired = Arrays.asList(SUBSCRIBE, UNSUBSCRIBE, MESSAGE); |
67 | | - private static Collection<StompCommand> contentLengthRequired = Arrays.asList(SEND, MESSAGE, ERROR); |
68 | | - private static Collection<StompCommand> bodyAllowed = Arrays.asList(SEND, MESSAGE, ERROR); |
69 | | - |
70 | | - |
71 | | - |
72 | 61 | public SimpMessageType getMessageType() { |
73 | | - SimpMessageType type = messageTypes.get(this); |
74 | | - return (type != null) ? type : SimpMessageType.OTHER; |
| 62 | + return simpMessageType; |
75 | 63 | } |
76 | 64 |
|
77 | 65 | public boolean requiresDestination() { |
78 | | - return destinationRequired.contains(this); |
| 66 | + return (flags & DESTINATION_REQUIRED) != 0; |
79 | 67 | } |
80 | 68 |
|
81 | 69 | public boolean requiresSubscriptionId() { |
82 | | - return subscriptionIdRequired.contains(this); |
| 70 | + return (flags & SUBSCRIPTION_ID_REQUIRED) != 0; |
83 | 71 | } |
84 | 72 |
|
85 | 73 | public boolean requiresContentLength() { |
86 | | - return contentLengthRequired.contains(this); |
| 74 | + return (flags & CONTENT_LENGTH_REQUIRED) != 0; |
87 | 75 | } |
88 | 76 |
|
89 | 77 | public boolean isBodyAllowed() { |
90 | | - return bodyAllowed.contains(this); |
| 78 | + return (flags & BODY_ALLOWED) != 0; |
91 | 79 | } |
92 | 80 |
|
93 | 81 | } |
|
0 commit comments