Search in sources :

Example 1 with ModuleCommandExtensions

use of org.infinispan.commands.module.ModuleCommandExtensions in project infinispan by infinispan.

the class ModuleProperties method loadModuleCommandHandlers.

public void loadModuleCommandHandlers(ClassLoader cl) {
    Collection<ModuleCommandExtensions> moduleCmdExtLoader = ServiceFinder.load(ModuleCommandExtensions.class, cl);
    if (moduleCmdExtLoader.iterator().hasNext()) {
        commandFactories = new HashMap<>(1);
        moduleCommands = new HashSet<>(1);
        for (ModuleCommandExtensions extension : moduleCmdExtLoader) {
            log.debugf("Loading module command extension SPI class: %s", extension);
            ModuleCommandFactory cmdFactory = extension.getModuleCommandFactory();
            Objects.requireNonNull(cmdFactory);
            for (Map.Entry<Byte, Class<? extends ReplicableCommand>> command : cmdFactory.getModuleCommands().entrySet()) {
                byte id = command.getKey();
                if (commandFactories.containsKey(id))
                    throw new IllegalArgumentException(String.format("Cannot use id %d for commands, as it is already in use by %s", id, commandFactories.get(id).getClass().getName()));
                commandFactories.put(id, cmdFactory);
                moduleCommands.add(command.getValue());
            }
        }
    } else {
        log.debug("No module command extensions to load");
        commandFactories = Collections.emptyMap();
    }
}
Also used : ModuleCommandFactory(org.infinispan.commands.module.ModuleCommandFactory) ModuleCommandExtensions(org.infinispan.commands.module.ModuleCommandExtensions) ReplicableCommand(org.infinispan.commands.ReplicableCommand) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 ReplicableCommand (org.infinispan.commands.ReplicableCommand)1 ModuleCommandExtensions (org.infinispan.commands.module.ModuleCommandExtensions)1 ModuleCommandFactory (org.infinispan.commands.module.ModuleCommandFactory)1