The CommandMapper class implements a domain specific language (DSL) with next interfaces:
CommandCollection
CommandConfigurator
CommandDictionary
CommandExecutable
CommandUnmapper
which provides one method for mapping commands and they are run asynchronously or synchronously.
Statements
final CommandMapperDictionary commandMapperDictionary = CommandMapperDictionaryImpl.create(Executors.newSingleThreadExecutor());
final CommandMapper commandMapper = CommandMapper.create(commandMapperDictionary);
Configuration
this.commandMapper.one(true); //only one execution by command
Add Command Runnable
final String command = "commandRunnable";
final Runnable runnable = (Runnable) () -> { ... };
commandMapper.addCommand(command,runnable);
Add Command Callable
final String command = "commandCalable";
final Callable<T> callable = (Callable<T>) () -> { ... return (T)... ; };
commandMapper.addCommand(command,callable);
Execute Command
final String command = e.getActionCommand();
final T valueCompleted = commandMapper.execute(command);
ExecuteAsync Command
final String command = e.getActionCommand();
final CompletableFuture<T> completed = commandMapper.execute(command); //Here, the promise is in second plane.
T value = completed.get(); // Waiting to resolution of the promise
UnMapper Command
final String command = e.getActionCommand();
commandMapper.unMapper(command);
UnMapperAll Commands
commandMapper.unMapperAll();
Register Commands
final int size = commandMapper.size();