Search in sources :

Example 1 with ValueChangedCommand

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);
}
Also used : Command(com.canoo.dp.impl.remoting.legacy.communication.Command) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) PresentationModelDeletedCommand(com.canoo.dp.impl.remoting.legacy.communication.PresentationModelDeletedCommand) ChangeAttributeMetadataCommand(com.canoo.dp.impl.remoting.legacy.communication.ChangeAttributeMetadataCommand) ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand)

Example 2 with ValueChangedCommand

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;
}
Also used : ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand)

Example 3 with ValueChangedCommand

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\"}]"));
}
Also used : ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) Test(org.testng.annotations.Test)

Example 4 with ValueChangedCommand

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));
}
Also used : ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) CallActionCommand(com.canoo.dp.impl.remoting.commands.CallActionCommand) Command(com.canoo.dp.impl.remoting.legacy.communication.Command) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) EmptyCommand(com.canoo.dp.impl.remoting.legacy.communication.EmptyCommand) ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) Test(org.testng.annotations.Test)

Example 5 with ValueChangedCommand

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));
}
Also used : ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) CallActionCommand(com.canoo.dp.impl.remoting.commands.CallActionCommand) Command(com.canoo.dp.impl.remoting.legacy.communication.Command) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) EmptyCommand(com.canoo.dp.impl.remoting.legacy.communication.EmptyCommand) ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) Test(org.testng.annotations.Test)

Aggregations

ValueChangedCommand (com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand)25 Test (org.testng.annotations.Test)22 CreatePresentationModelCommand (com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand)13 Command (com.canoo.dp.impl.remoting.legacy.communication.Command)12 EmptyCommand (com.canoo.dp.impl.remoting.legacy.communication.EmptyCommand)11 CallActionCommand (com.canoo.dp.impl.remoting.commands.CallActionCommand)9 ClientAttribute (com.canoo.dp.impl.client.legacy.ClientAttribute)4 ChangeAttributeMetadataCommand (com.canoo.dp.impl.remoting.legacy.communication.ChangeAttributeMetadataCommand)3 PresentationModelDeletedCommand (com.canoo.dp.impl.remoting.legacy.communication.PresentationModelDeletedCommand)3 CommandAndHandler (com.canoo.dp.impl.client.legacy.communication.CommandAndHandler)2 InterruptLongPollCommand (com.canoo.dp.impl.remoting.legacy.commands.InterruptLongPollCommand)2 StartLongPollCommand (com.canoo.dp.impl.remoting.legacy.commands.StartLongPollCommand)2 AttributeMetadataChangedCommand (com.canoo.dp.impl.remoting.legacy.communication.AttributeMetadataChangedCommand)2 DeletePresentationModelCommand (com.canoo.dp.impl.remoting.legacy.communication.DeletePresentationModelCommand)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 ArrayList (java.util.ArrayList)2 JsonParseException (com.google.gson.JsonParseException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1