Search in sources :

Example 1 with InterruptLongPollCommand

use of com.canoo.dp.impl.remoting.legacy.commands.InterruptLongPollCommand 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)

Aggregations

InterruptLongPollCommand (com.canoo.dp.impl.remoting.legacy.commands.InterruptLongPollCommand)1 Command (com.canoo.dp.impl.remoting.legacy.communication.Command)1 DolphinServerAction (com.canoo.dp.impl.server.legacy.action.DolphinServerAction)1 CommandHandler (com.canoo.dp.impl.server.legacy.communication.CommandHandler)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1