Java Code Examples for com.github.dockerjava.api.async.ResultCallback#onError()

The following examples show how to use com.github.dockerjava.api.async.ResultCallback#onError() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultInvocationBuilder.java    From docker-java with Apache License 2.0 6 votes vote down vote up
protected <T> void executeAndStream(
    DockerHttpClient.Request request,
    ResultCallback<T> callback,
    Consumer<DockerHttpClient.Response> sourceConsumer
) {
    Thread thread = new Thread(() -> {
        Thread streamingThread = Thread.currentThread();
        try (DockerHttpClient.Response response = execute(request)) {
            callback.onStart(() -> {
                streamingThread.interrupt();
                response.close();
            });

            sourceConsumer.accept(response);
            callback.onComplete();
        } catch (Exception e) {
            callback.onError(e);
        }
    }, "docker-java-stream-" + Objects.hashCode(request));
    thread.setDaemon(true);

    thread.start();
}
 
Example 2
Source File: AbstrAsyncDockerCmdExec.java    From docker-java with Apache License 2.0 5 votes vote down vote up
protected final Void execute(final CMD_T command, final ResultCallback<A_RES_T> resultCallback) {

        ResultCallback<A_RES_T> delegatingResultCallback = new ResultCallback<A_RES_T>() {

            @Override
            public void close() throws IOException {
                resultCallback.close();
                command.close();
            }

            @Override
            public void onStart(Closeable closeable) {
                resultCallback.onStart(closeable);
            }

            @Override
            public void onNext(A_RES_T object) {
                resultCallback.onNext(object);
            }

            @Override
            public void onError(Throwable throwable) {
                resultCallback.onError(throwable);
            }

            @Override
            public void onComplete() {
                resultCallback.onComplete();
                command.close();
            }
        };

        execute0(command, delegatingResultCallback);

        return null;
    }