Search in sources :

Example 1 with ModuleCommandFactory

use of org.infinispan.commands.module.ModuleCommandFactory 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)

Example 2 with ModuleCommandFactory

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

the class InfinispanRegionFactory method getCacheCommandFactory.

private CacheCommandFactory getCacheCommandFactory() {
    final GlobalComponentRegistry globalCr = manager.getGlobalComponentRegistry();
    final Map<Byte, ModuleCommandFactory> factories = globalCr.getComponent("org.infinispan.modules.command.factories");
    for (ModuleCommandFactory factory : factories.values()) {
        if (factory instanceof CacheCommandFactory) {
            return (CacheCommandFactory) factory;
        }
    }
    throw log.cannotInstallCommandFactory();
}
Also used : ModuleCommandFactory(org.infinispan.commands.module.ModuleCommandFactory) CacheCommandFactory(org.infinispan.hibernate.cache.commons.util.CacheCommandFactory) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry)

Example 3 with ModuleCommandFactory

use of org.infinispan.commands.module.ModuleCommandFactory in project hibernate-orm by hibernate.

the class InfinispanRegionFactory method getCacheCommandFactory.

private CacheCommandFactory getCacheCommandFactory() {
    final GlobalComponentRegistry globalCr = manager.getGlobalComponentRegistry();
    final Map<Byte, ModuleCommandFactory> factories = (Map<Byte, ModuleCommandFactory>) globalCr.getComponent("org.infinispan.modules.command.factories");
    for (ModuleCommandFactory factory : factories.values()) {
        if (factory instanceof CacheCommandFactory) {
            return (CacheCommandFactory) factory;
        }
    }
    throw log.cannotInstallCommandFactory();
}
Also used : ModuleCommandFactory(org.infinispan.commands.module.ModuleCommandFactory) CacheCommandFactory(org.hibernate.cache.infinispan.util.CacheCommandFactory) GlobalComponentRegistry(org.infinispan.factories.GlobalComponentRegistry) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ModuleCommandFactory (org.infinispan.commands.module.ModuleCommandFactory)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 GlobalComponentRegistry (org.infinispan.factories.GlobalComponentRegistry)2 CacheCommandFactory (org.hibernate.cache.infinispan.util.CacheCommandFactory)1 ReplicableCommand (org.infinispan.commands.ReplicableCommand)1 ModuleCommandExtensions (org.infinispan.commands.module.ModuleCommandExtensions)1 CacheCommandFactory (org.infinispan.hibernate.cache.commons.util.CacheCommandFactory)1