use of com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand in project dolphin-platform by canoo.
the class DefaultModelSynchronizer method onPropertyChanged.
@Override
public void onPropertyChanged(final PropertyChangeEvent evt) {
final Command command = new ValueChangedCommand(((Attribute) evt.getSource()).getId(), evt.getNewValue());
send(command);
}
use of com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand in project dolphin-platform by canoo.
the class BlindCommandBatcher method wasMerged.
protected boolean wasMerged(final List<CommandAndHandler> blindCommands, final CommandAndHandler val) {
if (!mergeValueChanges) {
return false;
}
if (!shallWeEvenTryToMerge) {
return false;
}
if (blindCommands.isEmpty()) {
return false;
}
if (val.getCommand() == null) {
return false;
}
if (!(val.getCommand() instanceof ValueChangedCommand)) {
return false;
}
final ValueChangedCommand valCmd = (ValueChangedCommand) val.getCommand();
shallWeEvenTryToMerge = true;
if (blindCommands.get(blindCommands.size() - 1).getCommand() instanceof ValueChangedCommand) {
ValueChangedCommand valueChangedCommand = (ValueChangedCommand) blindCommands.get(blindCommands.size() - 1).getCommand();
if (valCmd.getAttributeId().equals(valueChangedCommand.getAttributeId())) {
LOG.trace("merging value changed command for attribute {} with new values {} -> {}", valueChangedCommand.getAttributeId(), valueChangedCommand.getNewValue(), valCmd.getNewValue());
valueChangedCommand.setNewValue(valCmd.getNewValue());
return true;
}
}
return false;
}
use of com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand in project dolphin-platform by canoo.
the class TestOptimizedJsonCodec method shouldEncodeValueChangedCommandWithDoubles.
@Test
public void shouldEncodeValueChangedCommandWithDoubles() {
final ValueChangedCommand command = new ValueChangedCommand();
command.setNewValue(2.7182);
command.setAttributeId("3357S");
final String actual = OptimizedJsonCodec.getInstance().encode(Collections.<Command>singletonList(command));
assertThat(actual, is("[{\"a_id\":\"3357S\",\"v\":2.7182,\"id\":\"ValueChanged\"}]"));
}
use of com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand 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.ValueChangedCommand 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));
}
Aggregations