package org.jeecqrs.commands.registry;

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;
import javax.ejb.Lock;
import javax.ejb.LockType;
import org.jeecqrs.commands.CommandHandlerRegistry;
import org.jeecqrs.commands.CommandHandler;

public class AbstractCommandHandlerRegistry<C> implements CommandHandlerRegistry<C> {

    private Logger log = Logger.getLogger(this.getClass().getName());

    private Map<Class<? extends C>, CommandHandler<? extends C>> handlers = new HashMap<>();

    @Override
    @Lock(LockType.READ)
    public <T> CommandHandler<T> commandHandlerFor(Class<T> clazz) {
        return lookup(clazz);
    }

    @Lock(LockType.WRITE)
    protected void register(
            Class<? extends C> clazz,
            CommandHandler<? extends C> handler) {
        log.info("Registering CommandHandler for class " + clazz.getCanonicalName() + ": "+ handler);
        if (lookup(clazz) != null)
            throw new IllegalStateException("Handler for " + clazz.getCanonicalName() + " already registered");
        handlers.put(clazz, handler);
    }

    protected <T> CommandHandler<T> lookup(Class<T> clazz) {
        return (CommandHandler < T >) handlers.get(clazz);
    }

}

@@ -76,19 +76,99 @@
 va.util.
-Map
+HashSet;%0Aimport java.util.Map;%0Aimport java.util.Set;%0Aimport java.util.logging.Level
 ;%0Aimport
@@ -348,16 +348,25 @@
 %0Apublic 
+abstract 
 class Ab
@@ -449,16 +449,22 @@
 private 
+final 
 Logger l
@@ -526,16 +526,22 @@
 private 
+final 
 Map%3CClas
@@ -571,26 +571,16 @@
 Handler%3C
-? extends 
 C%3E%3E hand
@@ -653,20 +653,16 @@
   public
- %3CT%3E
  Command
@@ -669,17 +669,17 @@
 Handler%3C
-T
+C
 %3E comman
@@ -692,25 +692,35 @@
 erFor(Class%3C
-T
+? extends C
 %3E clazz) %7B%0A 
@@ -875,26 +875,16 @@
 Handler%3C
-? extends 
 C%3E handl
@@ -905,13 +905,24 @@
 log.
-info(
+log(Level.INFO, 
 %22Reg
@@ -955,20 +955,56 @@
 r class 
-%22 + 
+%7B0%7D: %7B1%7D%22,%0A                new Object%5B%5D%7B
 clazz.ge
@@ -1023,24 +1023,17 @@
 me()
- + %22: %22+
+,
  handler
 );%0A 
@@ -1024,24 +1024,25 @@
 e(), handler
+%7D
 );%0A        i
@@ -1232,102 +1232,212 @@
     
-protected %3CT%3E CommandHandler%3CT%3E lookup(Class%3CT%3E clazz) %7B%0A        return (CommandHandler %3C T %3E)
+@Override%0A    public Set%3CCommandHandler%3CC%3E%3E allCommandHandlers() %7B%0A        return new HashSet%3C%3E(handlers.values());%0A    %7D%0A%0A    protected CommandHandler%3CC%3E lookup(Class%3C? extends C%3E clazz) %7B%0A        return
  han

Fix AbstractCommandHandlerRegistry