Search in sources :

Example 1 with Command

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

the class DolphinPlatformHttpClientConnector method transmit.

public List<Command> transmit(final List<Command> commands) throws DolphinRemotingException {
    Assert.requireNonNull(commands, "commands");
    if (disconnecting.get()) {
        LOG.warn("Canceled communication based on disconnect");
        return Collections.emptyList();
    }
    // block if diconnect is called in other thread (poll / release)
    for (Command command : commands) {
        if (command instanceof DestroyContextCommand) {
            disconnecting.set(true);
        }
    }
    try {
        final String data = codec.encode(commands);
        final String receivedContent = client.request(servletUrl, RequestMethod.POST).withContent(data, HttpHeaderConstants.JSON_MIME_TYPE).readString().execute().get().getContent();
        return codec.decode(receivedContent);
    } catch (final Exception e) {
        throw new DolphinRemotingException("Error in remoting layer", e);
    }
}
Also used : DolphinRemotingException(com.canoo.platform.remoting.DolphinRemotingException) DestroyContextCommand(com.canoo.dp.impl.remoting.commands.DestroyContextCommand) Command(com.canoo.dp.impl.remoting.legacy.communication.Command) DestroyContextCommand(com.canoo.dp.impl.remoting.commands.DestroyContextCommand) DolphinRemotingException(com.canoo.platform.remoting.DolphinRemotingException)

Example 2 with Command

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

the class DefaultModelSynchronizer method onAdded.

@Override
public void onAdded(final ClientPresentationModel model) {
    final Command command = CreatePresentationModelCommand.makeFrom(model);
    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)

Example 3 with Command

use of com.canoo.dp.impl.remoting.legacy.communication.Command 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 4 with Command

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

the class AbstractClientConnector method processResults.

protected void processResults(final List<? extends Command> response, final List<CommandAndHandler> commandsAndHandlers) {
    if (LOG.isDebugEnabled() && response.size() > 0) {
        StringBuffer buffer = new StringBuffer();
        for (Command command : response) {
            buffer.append(command.getClass().getSimpleName());
            buffer.append(", ");
        }
        LOG.trace("Processing {} commands from server: {}", response.size(), buffer.substring(0, buffer.length() - 2));
    } else {
        LOG.trace("Processing {} commands from server", response.size());
    }
    for (Command serverCommand : response) {
        dispatchHandle(serverCommand);
    }
    OnFinishedHandler callback = commandsAndHandlers.get(0).getHandler();
    if (callback != null) {
        LOG.trace("Handling registered callback");
        try {
            callback.onFinished();
        } catch (Exception e) {
            LOG.error("Error in handling callback", e);
            throw e;
        }
    }
}
Also used : StartLongPollCommand(com.canoo.dp.impl.remoting.legacy.commands.StartLongPollCommand) InterruptLongPollCommand(com.canoo.dp.impl.remoting.legacy.commands.InterruptLongPollCommand) Command(com.canoo.dp.impl.remoting.legacy.communication.Command) DolphinRemotingException(com.canoo.platform.remoting.DolphinRemotingException)

Example 5 with Command

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

the class InMemoryClientConnector method transmit.

@Override
public List<Command> transmit(final List<Command> commands) {
    LOG.trace("transmitting {} commands", commands.size());
    if (serverConnector == null) {
        LOG.warn("no server connector wired for in-memory connector");
        return Collections.EMPTY_LIST;
    }
    if (sleepMillis > 0) {
        try {
            Thread.sleep(sleepMillis);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    List<Command> result = new LinkedList<Command>();
    for (Command command : commands) {
        LOG.trace("processing {}", command);
        // there is no need for encoding since we are in-memory
        result.addAll(serverConnector.receive(command));
    }
    return result;
}
Also used : Command(com.canoo.dp.impl.remoting.legacy.communication.Command) LinkedList(java.util.LinkedList)

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