Search in sources :

Example 6 with Command

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;
}
Also used : InterruptLongPollCommand(com.canoo.dp.impl.remoting.legacy.commands.InterruptLongPollCommand) Command(com.canoo.dp.impl.remoting.legacy.communication.Command) InterruptLongPollCommand(com.canoo.dp.impl.remoting.legacy.commands.InterruptLongPollCommand) ArrayList(java.util.ArrayList) CommandHandler(com.canoo.dp.impl.server.legacy.communication.CommandHandler) LinkedList(java.util.LinkedList) DolphinServerAction(com.canoo.dp.impl.server.legacy.action.DolphinServerAction)

Example 7 with Command

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 + "]"));
}
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 8 with Command

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));
}
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 9 with Command

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));
}
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 10 with Command

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}"));
}
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

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