Skip to content

Commit

Permalink
Improve performance of StompCommand.getMessageType()
Browse files Browse the repository at this point in the history
Closes SPR-14636
  • Loading branch information
dreis2211 committed Aug 28, 2016
1 parent 57cb7c7 commit e9555cf
Showing 1 changed file with 20 additions and 31 deletions.
Expand Up @@ -18,8 +18,6 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.springframework.messaging.simp.SimpMessageType;

Expand All @@ -32,46 +30,37 @@
public enum StompCommand {

// client
CONNECT,
STOMP,
DISCONNECT,
SUBSCRIBE,
UNSUBSCRIBE,
SEND,
ACK,
NACK,
BEGIN,
COMMIT,
ABORT,
CONNECT(SimpMessageType.CONNECT),
STOMP(SimpMessageType.CONNECT),
DISCONNECT(SimpMessageType.DISCONNECT),
SUBSCRIBE(SimpMessageType.SUBSCRIBE),
UNSUBSCRIBE(SimpMessageType.UNSUBSCRIBE),
SEND(SimpMessageType.MESSAGE),
ACK(null),
NACK(null),
BEGIN(null),
COMMIT(null),
ABORT(null),

// server
CONNECTED,
MESSAGE,
RECEIPT,
ERROR;


private static Map<StompCommand, SimpMessageType> messageTypes = new HashMap<>();
static {
messageTypes.put(StompCommand.CONNECT, SimpMessageType.CONNECT);
messageTypes.put(StompCommand.STOMP, SimpMessageType.CONNECT);
messageTypes.put(StompCommand.SEND, SimpMessageType.MESSAGE);
messageTypes.put(StompCommand.MESSAGE, SimpMessageType.MESSAGE);
messageTypes.put(StompCommand.SUBSCRIBE, SimpMessageType.SUBSCRIBE);
messageTypes.put(StompCommand.UNSUBSCRIBE, SimpMessageType.UNSUBSCRIBE);
messageTypes.put(StompCommand.DISCONNECT, SimpMessageType.DISCONNECT);
}
CONNECTED(null),
MESSAGE(SimpMessageType.MESSAGE),
RECEIPT(null),
ERROR(null);

private static Collection<StompCommand> destinationRequired = Arrays.asList(SEND, SUBSCRIBE, MESSAGE);
private static Collection<StompCommand> subscriptionIdRequired = Arrays.asList(SUBSCRIBE, UNSUBSCRIBE, MESSAGE);
private static Collection<StompCommand> contentLengthRequired = Arrays.asList(SEND, MESSAGE, ERROR);
private static Collection<StompCommand> bodyAllowed = Arrays.asList(SEND, MESSAGE, ERROR);

private SimpMessageType simpMessageType;

StompCommand(SimpMessageType simpMessageType) {
this.simpMessageType = simpMessageType;
}

public SimpMessageType getMessageType() {
SimpMessageType type = messageTypes.get(this);
return (type != null) ? type : SimpMessageType.OTHER;
return (simpMessageType != null) ? simpMessageType : SimpMessageType.OTHER;
}

public boolean requiresDestination() {
Expand Down

0 comments on commit e9555cf

Please sign in to comment.