package org.mitallast.queue.stomp;

import com.google.inject.Inject;
import io.netty.handler.codec.stomp.StompCommand;
import io.netty.handler.codec.stomp.StompFrame;
import org.mitallast.queue.common.component.AbstractComponent;
import org.mitallast.queue.common.settings.Settings;
import org.mitallast.queue.stomp.transport.StompSession;

import java.util.HashMap;
import java.util.Map;

/**
 * @link http://stomp.github.io/stomp-specification-1.2.html#Protocol_Overview
 */
public class StompController extends AbstractComponent {

    private final Map<StompCommand, StompHandler> handlers = new HashMap<>();

    @Inject
    public StompController(Settings settings) {
        super(settings);
    }

    public synchronized void registerHandler(StompCommand command, StompHandler handler) {
        handlers.put(command, handler);
    }

    public void dispatchRequest(StompSession session, StompFrame request) {
        StompHandler handler = handlers.get(request.command());
        handler.handleRequest(session, request);
    }
}

@@ -338,57 +338,8 @@
 n;%0A%0A
-import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 /**%0A
@@ -494,32 +494,8 @@
 vate
- final Map%3CStompCommand,
  Sto
@@ -503,17 +503,18 @@
 pHandler
-%3E
+%5B%5D
  handler
@@ -525,19 +525,50 @@
 new 
-HashMap%3C%3E()
+StompHandler%5BStompCommand.values().length%5D
 ;%0A%0A 
@@ -769,29 +769,37 @@
 lers
-.put(
+%5B
 command
-,
+.ordinal()%5D =
  handler
 );%0A 
@@ -794,17 +794,16 @@
  handler
-)
 ;%0A    %7D%0A
@@ -922,13 +922,9 @@
 lers
-.get(
+%5B
 requ
@@ -936,17 +936,27 @@
 ommand()
-)
+.ordinal()%5D
 ;%0A      

optimize stomp controller