use of com.canoo.dp.impl.server.legacy.communication.CommandHandler in project dolphin-platform by canoo.
the class ServerConnector method receive.
/**
* doesn't fail on missing commands
*/
public List<Command> receive(final Command command) {
Assert.requireNonNull(command, "command");
LOG.trace("Received command of type {}", command.getClass().getSimpleName());
// collecting parameter pattern
List<Command> response = new LinkedList();
if (!(command instanceof InterruptLongPollCommand)) {
// signal commands must not update thread-confined state
for (DolphinServerAction it : dolphinServerActions) {
// todo: can be deleted as soon as all action refer to the SMS
it.setDolphinResponse(response);
}
serverModelStore.setCurrentResponse(response);
}
List<CommandHandler> actions = registry.getActionsFor(command.getClass());
if (actions.isEmpty()) {
LOG.warn("There is no server action registered for received command type {}, known commands types are {}", command.getClass().getSimpleName(), registry.getActions().keySet());
return response;
}
// copying the list of actions allows an Action to unregister itself
// avoiding ConcurrentModificationException to be thrown by the loop
List<CommandHandler> actionsCopy = new ArrayList<CommandHandler>();
actionsCopy.addAll(actions);
try {
for (CommandHandler action : actionsCopy) {
action.handleCommand(command, response);
}
} catch (Exception exception) {
throw exception;
}
return response;
}
use of com.canoo.dp.impl.server.legacy.communication.CommandHandler in project dolphin-platform by canoo.
the class DolphinContext method registerCommand.
protected <T extends Command> void registerCommand(final ActionRegistry registry, final Class<T> commandClass, final Consumer<T> handler) {
Assert.requireNonNull(registry, "registry");
Assert.requireNonNull(commandClass, "commandClass");
Assert.requireNonNull(handler, "handler");
registry.register(commandClass, new CommandHandler() {
@Override
public void handleCommand(final Command command, final List response) {
LOG.trace("Handling {} for DolphinContext {}", commandClass.getSimpleName(), getId());
handler.accept((T) command);
}
});
}
use of com.canoo.dp.impl.server.legacy.communication.CommandHandler in project dolphin-platform by canoo.
the class TestDolphinCommandHandler method testInvocation.
@Test
public void testInvocation() throws Exception {
// Given:
final DolphinTestConfiguration configuration = createDolphinTestConfiguration();
final ServerModelStore serverModelStore = configuration.getServerModelStore();
final ClientModelStore clientModelStore = configuration.getClientModelStore();
final DolphinCommandHandler dolphinCommandHandler = new DolphinCommandHandler(configuration.getClientConnector());
final String modelId = UUID.randomUUID().toString();
clientModelStore.createModel(modelId, null, new ClientAttribute("myAttribute", "UNKNOWN"));
configuration.getServerConnector().register(new DolphinServerAction() {
@Override
public void registerIn(ActionRegistry registry) {
registry.register(TestChangeCommand.class, new CommandHandler() {
@Override
public void handleCommand(Command command, List response) {
serverModelStore.findPresentationModelById(modelId).getAttribute("myAttribute").setValue("Hello World");
}
});
}
});
// When:
dolphinCommandHandler.invokeDolphinCommand(new TestChangeCommand()).get();
// Then:
assertEquals(clientModelStore.findPresentationModelById(modelId).getAttribute("myAttribute").getValue(), "Hello World");
}
Aggregations