All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dockerjava.jaxrs.AbstrAsyncDockerCmdExec Maven / Gradle / Ivy

There is a newer version: 3.4.0
Show newest version
package com.github.dockerjava.jaxrs;

import java.io.Closeable;
import java.io.IOException;

import javax.ws.rs.client.WebTarget;

import com.github.dockerjava.api.async.ResultCallback;
import com.github.dockerjava.api.command.AsyncDockerCmd;
import com.github.dockerjava.api.command.DockerCmdAsyncExec;
import com.github.dockerjava.core.DockerClientConfig;
import com.github.dockerjava.jaxrs.async.AbstractCallbackNotifier;

public abstract class AbstrAsyncDockerCmdExec, A_RES_T> extends
        AbstrDockerCmdExec implements DockerCmdAsyncExec {

    public AbstrAsyncDockerCmdExec(WebTarget baseResource, DockerClientConfig dockerClientConfig) {
        super(baseResource, dockerClientConfig);
    }

    @Override
    public Void exec(CMD_T command, ResultCallback resultCallback) {
        return execute(command, resultCallback);
    }

    protected final Void execute(final CMD_T command, final ResultCallback resultCallback) {

        ResultCallback delegatingResultCallback = new ResultCallback() {

            @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();
            }
        };

        AbstractCallbackNotifier callbackNotifier = callbackNotifier(command, delegatingResultCallback);

        AbstractCallbackNotifier.startAsyncProcessing(callbackNotifier);

        return null;
    }

    protected abstract AbstractCallbackNotifier callbackNotifier(CMD_T command,
            ResultCallback resultCallback);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy