package org.jeecqrs.commands.registry;

import java.util.Iterator;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import org.jeecqrs.commands.CommandHandler;

/**
 *
 */
public class AutoDiscoverCommandHandlerRegistry<C> extends AbstractCommandHandlerRegistry<C> {

    private Logger log = Logger.getLogger(AutoDiscoverCommandHandlerRegistry.class.getName());

    @Inject
    private Instance<CommandHandler> handlerInstances;

    @PostConstruct
    public void startup() {
        log.info("Scanning command handlers");
	Iterator<CommandHandler> it = handlerInstances.iterator();
        if (!it.hasNext()) {
            log.warning("No CommandHandlers found");
        }
	while (it.hasNext()) {
            CommandHandler h = it.next();
            log.fine("Discovered CommandHandler: "+ h);
            this.register(h.handledCommandType(), h);
	}
    }
    
}

@@ -496,16 +496,19 @@
 dHandler
+%3CC%3E
 %3E handle
@@ -519,16 +519,16 @@
 tances;%0A
-
 %0A    @Po
@@ -642,15 +642,25 @@
 dler
+%3CC%3E
 %3E it = 
+select(
 hand
@@ -675,18 +675,8 @@
 nces
-.iterator(
 );%0A 
@@ -692,34 +692,32 @@
  (!it.hasNext())
- %7B
 %0A            log
@@ -758,18 +758,8 @@
 %22);%0A
-        %7D%0A
 %09whi
@@ -934,16 +934,16 @@
 h);%0A
-
 %09%7D%0A    %7D
 %0A   
@@ -938,16 +938,150 @@
 %09%7D%0A    %7D
+%0A%0A    protected Iterator%3CCommandHandler%3CC%3E%3E select(Instance%3CCommandHandler%3CC%3E%3E instances) %7B%0A        return instances.iterator();%0A    %7D
 %0A    %0A%7D%0A

Add selection option for instances of CommandHandlers