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

com.github.dockerjava.core.command.PullImageResultCallback Maven / Gradle / Ivy

There is a newer version: 3.4.2
Show newest version
/*
 * Created on 21.07.2015
 */
package com.github.dockerjava.core.command;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.dockerjava.api.DockerClientException;
import com.github.dockerjava.api.model.PullResponseItem;
import com.github.dockerjava.core.async.ResultCallbackTemplate;

/**
 *
 * @author marcus
 *
 */
public class PullImageResultCallback extends ResultCallbackTemplate {

    private final static Logger LOGGER = LoggerFactory.getLogger(PullImageResultCallback.class);

    private PullResponseItem latestItem = null;

    @Override
    public void onNext(PullResponseItem item) {
        this.latestItem = item;
        LOGGER.debug(item.toString());
    }

    /**
     * Awaits the image to be pulled successful.
     *
     * @throws DockerClientException
     *             if the pull fails.
     */
    public void awaitSuccess() {
        try {
            awaitCompletion();
        } catch (InterruptedException e) {
            throw new DockerClientException("", e);
        }

        if (latestItem == null) {
            throw new DockerClientException("Could not pull image");
        } else if (!latestItem.isPullSuccessIndicated()) {
            throw new DockerClientException("Could not pull image: " + latestItem.getError());
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy