Search in sources :

Example 21 with Command

use of com.canoo.dp.impl.remoting.legacy.communication.Command in project dolphin-platform by canoo.

the class OptimizedJsonCodec method decode.

@Override
public List<Command> decode(final String transmitted) {
    Assert.requireNonNull(transmitted, "transmitted");
    LOG.trace("Decoding message: {}", transmitted);
    try {
        final JsonArray array = (JsonArray) new JsonParser().parse(transmitted);
        final List<Command> commands = new ArrayList<>(array.size());
        for (final JsonElement jsonElement : array) {
            final JsonObject command = (JsonObject) jsonElement;
            final JsonPrimitive idElement = command.getAsJsonPrimitive("id");
            if (idElement == null) {
                throw new RuntimeException("Can not encode command without id!");
            }
            String id = idElement.getAsString();
            LOG.trace("Decoding command: {}", id);
            final CommandTranscoder<?> encoder = transcoders.get(id);
            if (encoder == null) {
                throw new RuntimeException("Can not encode command of type " + id + ". No matching encoder found!");
            }
            final Command convertedCommand = encoder.decode(command);
            Assert.requireNonNull(convertedCommand, "convertedCommand");
            commands.add(convertedCommand);
        }
        LOG.debug("Decoded command list with {} commands", commands.size());
        return commands;
    } catch (Exception ex) {
        throw new JsonParseException("Illegal JSON detected", ex);
    }
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JsonParseException(com.google.gson.JsonParseException) JsonParseException(com.google.gson.JsonParseException) JsonArray(com.google.gson.JsonArray) Command(com.canoo.dp.impl.remoting.legacy.communication.Command) JsonElement(com.google.gson.JsonElement) JsonParser(com.google.gson.JsonParser)

Example 22 with Command

use of com.canoo.dp.impl.remoting.legacy.communication.Command in project dolphin-platform by canoo.

the class ClientConnectorTests method testValueChange_noQualifier.

@Test
public void testValueChange_noQualifier() {
    ClientAttribute attribute = new ClientAttribute("attr", "initialValue");
    clientModelStore.registerAttribute(attribute);
    attributeChangeListener.propertyChange(new PropertyChangeEvent(attribute, Attribute.VALUE_NAME, attribute.getValue(), "newValue"));
    syncAndWaitUntilDone();
    assertCommandsTransmitted(2);
    Assert.assertEquals("initialValue", attribute.getValue());
    boolean valueChangedCommandFound = false;
    for (Command c : clientConnector.getTransmittedCommands()) {
        if (c instanceof ValueChangedCommand) {
        }
        valueChangedCommandFound = true;
    }
    Assert.assertTrue(valueChangedCommandFound);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) InterruptLongPollCommand(com.canoo.dp.impl.remoting.legacy.commands.InterruptLongPollCommand) Command(com.canoo.dp.impl.remoting.legacy.communication.Command) StartLongPollCommand(com.canoo.dp.impl.remoting.legacy.commands.StartLongPollCommand) ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) PresentationModelDeletedCommand(com.canoo.dp.impl.remoting.legacy.communication.PresentationModelDeletedCommand) AttributeMetadataChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.AttributeMetadataChangedCommand) DeletePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.DeletePresentationModelCommand) EmptyCommand(com.canoo.dp.impl.remoting.legacy.communication.EmptyCommand) ChangeAttributeMetadataCommand(com.canoo.dp.impl.remoting.legacy.communication.ChangeAttributeMetadataCommand) ClientAttribute(com.canoo.dp.impl.client.legacy.ClientAttribute) ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) Test(org.testng.annotations.Test)

Example 23 with Command

use of com.canoo.dp.impl.remoting.legacy.communication.Command in project dolphin-platform by canoo.

the class ClientConnectorTests method testValueChange_withQualifier.

@Test
public void testValueChange_withQualifier() {
    syncDone = new CountDownLatch(1);
    ClientAttribute attribute = new ClientAttribute("attr", "initialValue", "qualifier");
    clientModelStore.registerAttribute(attribute);
    attributeChangeListener.propertyChange(new PropertyChangeEvent(attribute, Attribute.VALUE_NAME, attribute.getValue(), "newValue"));
    syncAndWaitUntilDone();
    assertCommandsTransmitted(3);
    Assert.assertEquals("newValue", attribute.getValue());
    boolean valueChangedCommandFound = false;
    for (Command c : clientConnector.getTransmittedCommands()) {
        if (c instanceof ValueChangedCommand) {
        }
        valueChangedCommandFound = true;
    }
    Assert.assertTrue(valueChangedCommandFound);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) InterruptLongPollCommand(com.canoo.dp.impl.remoting.legacy.commands.InterruptLongPollCommand) Command(com.canoo.dp.impl.remoting.legacy.communication.Command) StartLongPollCommand(com.canoo.dp.impl.remoting.legacy.commands.StartLongPollCommand) ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) CreatePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand) PresentationModelDeletedCommand(com.canoo.dp.impl.remoting.legacy.communication.PresentationModelDeletedCommand) AttributeMetadataChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.AttributeMetadataChangedCommand) DeletePresentationModelCommand(com.canoo.dp.impl.remoting.legacy.communication.DeletePresentationModelCommand) EmptyCommand(com.canoo.dp.impl.remoting.legacy.communication.EmptyCommand) ChangeAttributeMetadataCommand(com.canoo.dp.impl.remoting.legacy.communication.ChangeAttributeMetadataCommand) ClientAttribute(com.canoo.dp.impl.client.legacy.ClientAttribute) ValueChangedCommand(com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.testng.annotations.Test)

Example 24 with Command

use of com.canoo.dp.impl.remoting.legacy.communication.Command in project dolphin-platform by canoo.

the class TestOptimizedJsonCodec method shouldEncodeSingleCreatePresentationModelCommand.

@Test
public void shouldEncodeSingleCreatePresentationModelCommand() {
    final Command command = createCPMCommand();
    final String actual = OptimizedJsonCodec.getInstance().encode(Collections.singletonList(command));
    assertThat(actual, is("[" + createCPMCommandString() + "]"));
}
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) Test(org.testng.annotations.Test)

Example 25 with Command

use of com.canoo.dp.impl.remoting.legacy.communication.Command in project dolphin-platform by canoo.

the class TestOptimizedJsonCodec method testQualifierSupport.

@Test
public void testQualifierSupport() {
    final String input = "[{\"id\":\"ChangeAttributeMetadata\",\"a_id\":\"79S\",\"n\":\"qualifier\",\"v\":\"237fb6b9-32d5-4feb-9679-57f1dd7cc7a2\"},{\"id\":\"ChangeAttributeMetadata\",\"a_id\":\"81S\",\"n\":\"qualifier\",\"v\":\"0e36799a-e501-4af4-a2f0-04b98897a1de\"}]";
    final List<Command> commands = OptimizedJsonCodec.getInstance().decode(input);
    Assert.assertNotNull(commands);
    for (Command command : commands) {
        Assert.assertNotNull(command);
    }
}
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) Test(org.testng.annotations.Test)

Aggregations

Command (com.canoo.dp.impl.remoting.legacy.communication.Command)43 CreatePresentationModelCommand (com.canoo.dp.impl.remoting.legacy.communication.CreatePresentationModelCommand)25 ValueChangedCommand (com.canoo.dp.impl.remoting.legacy.communication.ValueChangedCommand)23 Test (org.testng.annotations.Test)22 EmptyCommand (com.canoo.dp.impl.remoting.legacy.communication.EmptyCommand)19 CallActionCommand (com.canoo.dp.impl.remoting.commands.CallActionCommand)18 StartLongPollCommand (com.canoo.dp.impl.remoting.legacy.commands.StartLongPollCommand)10 InterruptLongPollCommand (com.canoo.dp.impl.remoting.legacy.commands.InterruptLongPollCommand)8 ChangeAttributeMetadataCommand (com.canoo.dp.impl.remoting.legacy.communication.ChangeAttributeMetadataCommand)8 ArrayList (java.util.ArrayList)8 PresentationModelDeletedCommand (com.canoo.dp.impl.remoting.legacy.communication.PresentationModelDeletedCommand)7 CreateContextCommand (com.canoo.dp.impl.remoting.commands.CreateContextCommand)5 LinkedList (java.util.LinkedList)5 ServerModelStore (com.canoo.dp.impl.server.legacy.ServerModelStore)4 ClientAttribute (com.canoo.dp.impl.client.legacy.ClientAttribute)3 ClientModelStore (com.canoo.dp.impl.client.legacy.ClientModelStore)3 DestroyContextCommand (com.canoo.dp.impl.remoting.commands.DestroyContextCommand)3 AttributeMetadataChangedCommand (com.canoo.dp.impl.remoting.legacy.communication.AttributeMetadataChangedCommand)3 DeletePresentationModelCommand (com.canoo.dp.impl.remoting.legacy.communication.DeletePresentationModelCommand)3 CommandHandler (com.canoo.dp.impl.server.legacy.communication.CommandHandler)3