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();
}
}
Aggregations