use of com.canoo.dp.impl.remoting.legacy.communication.Command 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.remoting.legacy.communication.Command in project dolphin-platform by canoo.
the class TestOptimizedJsonCodec method shouldEncodeTwoStandardCodecCommands.
@Test
public void shouldEncodeTwoStandardCodecCommands() {
final Command command = createCommand();
final String actual = OptimizedJsonCodec.getInstance().encode(Arrays.asList(command, command));
final String expected = createCommandJsonString();
assertThat(actual, is("[" + expected + "," + expected + "]"));
}
use of com.canoo.dp.impl.remoting.legacy.communication.Command in project dolphin-platform by canoo.
the class TestOptimizedJsonCodec method shouldDecodeValueChangedCommandWithLong.
@Test
public void shouldDecodeValueChangedCommandWithLong() {
final List<Command> commands = OptimizedJsonCodec.getInstance().decode("[{\"a_id\":\"3357S\",\"v\":987654321234567890,\"id\":\"ValueChanged\"}]");
final ValueChangedCommand command = (ValueChangedCommand) commands.get(0);
assertThat(command.getAttributeId(), is("3357S"));
assertThat(((Number) command.getNewValue()).longValue(), is(987654321234567890L));
}
use of com.canoo.dp.impl.remoting.legacy.communication.Command in project dolphin-platform by canoo.
the class TestOptimizedJsonCodec method shouldDecodeValueChangedCommandWithBigDecimal.
@Test
public void shouldDecodeValueChangedCommandWithBigDecimal() {
final List<Command> commands = OptimizedJsonCodec.getInstance().decode("[{\"a_id\":\"3357S\",\"v\":2.7182,\"id\":\"ValueChanged\"}]");
final ValueChangedCommand command = (ValueChangedCommand) commands.get(0);
assertThat(command.getAttributeId(), is("3357S"));
assertThat(((Number) command.getNewValue()).doubleValue(), is(2.7182));
}
use of com.canoo.dp.impl.remoting.legacy.communication.Command in project dolphin-platform by canoo.
the class TestOptimizedJsonCodec method shouldDecodeValueChangedCommandWithUuid.
@Test
public void shouldDecodeValueChangedCommandWithUuid() {
final List<Command> commands = OptimizedJsonCodec.getInstance().decode("[{\"a_id\":\"3357S\",\"v\":\"{4b9e93fd-3738-4fe6-b2a4-1fea8d2e0dc4}\",\"id\":\"ValueChanged\"}]");
final ValueChangedCommand command = (ValueChangedCommand) commands.get(0);
assertThat(command.getAttributeId(), is("3357S"));
assertThat(command.getNewValue().toString(), is("{4b9e93fd-3738-4fe6-b2a4-1fea8d2e0dc4}"));
}
Aggregations