Search in sources :

Example 1 with DolphinServerAction

use of com.canoo.dp.impl.server.legacy.action.DolphinServerAction 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 2 with DolphinServerAction

use of com.canoo.dp.impl.server.legacy.action.DolphinServerAction in project dolphin-platform by canoo.

the class TestDolphinCommandHandler method testInvocation.

@Test
public void testInvocation() throws Exception {
    // Given:
    final DolphinTestConfiguration configuration = createDolphinTestConfiguration();
    final ServerModelStore serverModelStore = configuration.getServerModelStore();
    final ClientModelStore clientModelStore = configuration.getClientModelStore();
    final DolphinCommandHandler dolphinCommandHandler = new DolphinCommandHandler(configuration.getClientConnector());
    final String modelId = UUID.randomUUID().toString();
    clientModelStore.createModel(modelId, null, new ClientAttribute("myAttribute", "UNKNOWN"));
    configuration.getServerConnector().register(new DolphinServerAction() {

        @Override
        public void registerIn(ActionRegistry registry) {
            registry.register(TestChangeCommand.class, new CommandHandler() {

                @Override
                public void handleCommand(Command command, List response) {
                    serverModelStore.findPresentationModelById(modelId).getAttribute("myAttribute").setValue("Hello World");
                }
            });
        }
    });
    // When:
    dolphinCommandHandler.invokeDolphinCommand(new TestChangeCommand()).get();
    // Then:
    assertEquals(clientModelStore.findPresentationModelById(modelId).getAttribute("myAttribute").getValue(), "Hello World");
}
Also used : ClientAttribute(com.canoo.dp.impl.client.legacy.ClientAttribute) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) CommandHandler(com.canoo.dp.impl.server.legacy.communication.CommandHandler) DolphinCommandHandler(com.canoo.dp.impl.client.DolphinCommandHandler) ActionRegistry(com.canoo.dp.impl.server.legacy.communication.ActionRegistry) DolphinCommandHandler(com.canoo.dp.impl.client.DolphinCommandHandler) Command(com.canoo.dp.impl.remoting.legacy.communication.Command) List(java.util.List) ClientModelStore(com.canoo.dp.impl.client.legacy.ClientModelStore) DolphinServerAction(com.canoo.dp.impl.server.legacy.action.DolphinServerAction) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.dolphin.client.util.AbstractDolphinBasedTest)

Aggregations

Command (com.canoo.dp.impl.remoting.legacy.communication.Command)2 DolphinServerAction (com.canoo.dp.impl.server.legacy.action.DolphinServerAction)2 CommandHandler (com.canoo.dp.impl.server.legacy.communication.CommandHandler)2 AbstractDolphinBasedTest (com.canoo.dolphin.client.util.AbstractDolphinBasedTest)1 DolphinCommandHandler (com.canoo.dp.impl.client.DolphinCommandHandler)1 ClientAttribute (com.canoo.dp.impl.client.legacy.ClientAttribute)1 ClientModelStore (com.canoo.dp.impl.client.legacy.ClientModelStore)1 InterruptLongPollCommand (com.canoo.dp.impl.remoting.legacy.commands.InterruptLongPollCommand)1 ServerModelStore (com.canoo.dp.impl.server.legacy.ServerModelStore)1 ActionRegistry (com.canoo.dp.impl.server.legacy.communication.ActionRegistry)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Test (org.testng.annotations.Test)1