Search in sources :

Example 1 with DolphinRemotingException

use of com.canoo.platform.remoting.DolphinRemotingException in project dolphin-platform by canoo.

the class ClientContextImpl method disconnect.

@Override
public synchronized CompletableFuture<Void> disconnect() {
    final CompletableFuture<Void> result = new CompletableFuture<>();
    clientConfiguration.getBackgroundExecutor().execute(() -> {
        dolphinCommandHandler.invokeDolphinCommand(new DestroyContextCommand()).handle((Void aVoid, Throwable throwable) -> {
            clientConnector.disconnect();
            clientSessionStore.resetSession(endpoint);
            if (throwable != null) {
                result.completeExceptionally(new DolphinRemotingException("Can't disconnect", throwable));
            } else {
                result.complete(null);
            }
            return null;
        });
    });
    return result;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) DolphinRemotingException(com.canoo.platform.remoting.DolphinRemotingException) DestroyContextCommand(com.canoo.dp.impl.remoting.commands.DestroyContextCommand)

Example 2 with DolphinRemotingException

use of com.canoo.platform.remoting.DolphinRemotingException 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)

Aggregations

DestroyContextCommand (com.canoo.dp.impl.remoting.commands.DestroyContextCommand)2 DolphinRemotingException (com.canoo.platform.remoting.DolphinRemotingException)2 Command (com.canoo.dp.impl.remoting.legacy.communication.Command)1 CompletableFuture (java.util.concurrent.CompletableFuture)1