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