X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 49 additions & 7 deletions src/main/java/com/github/dockerjava/api/DockerClient.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,52 @@
package com.github.dockerjava.api;

import java.io.*;

import com.github.dockerjava.api.command.*;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import com.github.dockerjava.api.async.ResultCallback;
import com.github.dockerjava.api.command.AttachContainerCmd;
import com.github.dockerjava.api.command.AuthCmd;
import com.github.dockerjava.api.command.BuildImageCmd;
import com.github.dockerjava.api.command.CommitCmd;
import com.github.dockerjava.api.command.ContainerDiffCmd;
import com.github.dockerjava.api.command.CopyFileFromContainerCmd;
import com.github.dockerjava.api.command.CreateContainerCmd;
import com.github.dockerjava.api.command.CreateImageCmd;
import com.github.dockerjava.api.command.EventsCmd;
import com.github.dockerjava.api.command.ExecCreateCmd;
import com.github.dockerjava.api.command.ExecStartCmd;
import com.github.dockerjava.api.command.InfoCmd;
import com.github.dockerjava.api.command.InspectContainerCmd;
import com.github.dockerjava.api.command.InspectExecCmd;
import com.github.dockerjava.api.command.InspectImageCmd;
import com.github.dockerjava.api.command.KillContainerCmd;
import com.github.dockerjava.api.command.ListContainersCmd;
import com.github.dockerjava.api.command.ListImagesCmd;
import com.github.dockerjava.api.command.LogContainerCmd;
import com.github.dockerjava.api.command.PauseContainerCmd;
import com.github.dockerjava.api.command.PingCmd;
import com.github.dockerjava.api.command.PullImageCmd;
import com.github.dockerjava.api.command.PushImageCmd;
import com.github.dockerjava.api.command.RemoveContainerCmd;
import com.github.dockerjava.api.command.RemoveImageCmd;
import com.github.dockerjava.api.command.RestartContainerCmd;
import com.github.dockerjava.api.command.SaveImageCmd;
import com.github.dockerjava.api.command.SearchImagesCmd;
import com.github.dockerjava.api.command.StartContainerCmd;
import com.github.dockerjava.api.command.StatsCmd;
import com.github.dockerjava.api.command.StopContainerCmd;
import com.github.dockerjava.api.command.TagImageCmd;
import com.github.dockerjava.api.command.TopContainerCmd;
import com.github.dockerjava.api.command.UnpauseContainerCmd;
import com.github.dockerjava.api.command.VersionCmd;
import com.github.dockerjava.api.command.WaitContainerCmd;
import com.github.dockerjava.api.model.AuthConfig;
import com.github.dockerjava.api.model.Event;
import com.github.dockerjava.api.model.Frame;
import com.github.dockerjava.api.model.Identifier;
import com.github.dockerjava.api.model.Statistics;

// https://godoc.org/github.com/fsouza/go-dockerclient
public interface DockerClient extends Closeable {
Expand Down Expand Up @@ -72,13 +114,13 @@ public interface DockerClient extends Closeable {

public WaitContainerCmd waitContainerCmd(String containerId);

public AttachContainerCmd attachContainerCmd(String containerId);
public AttachContainerCmd attachContainerCmd(String containerId, ResultCallback<Frame> resultCallback);

public ExecStartCmd execStartCmd(String containerId);

public InspectExecCmd inspectExecCmd(String execId);

public LogContainerCmd logContainerCmd(String containerId);
public LogContainerCmd logContainerCmd(String containerId, ResultCallback<Frame> resultCallback);

public CopyFileFromContainerCmd copyFileFromContainerCmd(String containerId, String resource);

Expand Down Expand Up @@ -106,9 +148,9 @@ public interface DockerClient extends Closeable {

public UnpauseContainerCmd unpauseContainerCmd(String containerId);

public EventsCmd eventsCmd(EventCallback eventCallback);
public EventsCmd eventsCmd(ResultCallback<Event> resultCallback);

public StatsCmd statsCmd(StatsCallback statsCallback);
public StatsCmd statsCmd(ResultCallback<Statistics> resultCallback);

@Override
public void close() throws IOException;
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/github/dockerjava/api/async/ResultCallback.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.github.dockerjava.api.async;

import java.io.Closeable;

/**
* Result callback
*/
public interface ResultCallback<RES_T> extends Closeable {
/**
* Called when the async processing starts. The passed {@link Closeable} can be used to close/interrupt the
* processing
*/
void onStart(Closeable closeable);

/** Called when an async result event occurs */
void onNext(RES_T object);

/** Called when an exception occurs while processing */
void onError(Throwable throwable);

/** Called when processing was finished either by reaching the end or by aborting it */
void onComplete();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Created on 17.06.2015
*/
package com.github.dockerjava.api.command;

import com.github.dockerjava.api.async.ResultCallback;

/**
*
*
* @author marcus
*
*/
public interface AsyncDockerCmd<CMD_T extends DockerCmd<RES_T>, A_RES_T, RES_T> extends DockerCmd<RES_T> {

public ResultCallback<A_RES_T> getResultCallback();

public CMD_T withResultCallback(ResultCallback<A_RES_T> resultCallback);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.NotFoundException;
import com.github.dockerjava.api.model.Frame;

/**
* Attach to container
*
*
* @param logs
* - true or false, includes logs. Defaults to false.
*
*
* @param followStream
* - true or false, return stream. Defaults to false.
* @param stdout
Expand All @@ -20,7 +21,7 @@
* @param timestamps
* - true or false, if true, print timestamps for every log line. Defaults to false.
*/
public interface AttachContainerCmd extends DockerCmd<InputStream> {
public interface AttachContainerCmd extends AsyncDockerCmd<AttachContainerCmd, Frame, Void> {

public String getContainerId();

Expand Down Expand Up @@ -64,14 +65,14 @@ public interface AttachContainerCmd extends DockerCmd<InputStream> {

/**
* Its the responsibility of the caller to consume and/or close the {@link InputStream} to prevent connection leaks.
*
*
* @throws NotFoundException
* No such container
*/
@Override
public InputStream exec() throws NotFoundException;
public Void exec() throws NotFoundException;

public static interface Exec extends DockerCmdExec<AttachContainerCmd, InputStream> {
public static interface Exec extends DockerCmdExec<AttachContainerCmd, Void> {
}

}
}
16 changes: 0 additions & 16 deletions src/main/java/com/github/dockerjava/api/command/EventCallback.java

This file was deleted.

10 changes: 3 additions & 7 deletions src/main/java/com/github/dockerjava/api/command/EventsCmd.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.dockerjava.api.command;

import java.util.concurrent.ExecutorService;
import com.github.dockerjava.api.model.Event;

/**
* Get events
Expand All @@ -10,7 +10,7 @@
* @param until
* - Stream events until this timestamp
*/
public interface EventsCmd extends DockerCmd<ExecutorService> {
public interface EventsCmd extends AsyncDockerCmd<EventsCmd, Event, Void> {
public EventsCmd withSince(String since);

public EventsCmd withUntil(String until);
Expand All @@ -19,10 +19,6 @@ public interface EventsCmd extends DockerCmd<ExecutorService> {

public String getUntil();

public EventCallback getEventCallback();

public EventsCmd withEventCallback(EventCallback eventCallback);

public static interface Exec extends DockerCmdExec<EventsCmd, ExecutorService> {
public static interface Exec extends DockerCmdExec<EventsCmd, Void> {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.NotFoundException;
import com.github.dockerjava.api.model.Frame;

import java.io.InputStream;

/**
* Get container logs
*
*
* @param followStream
* - true or false, return stream. Defaults to false.
* @param stdout
Expand All @@ -18,12 +19,8 @@
* - true or false, if true, print timestamps for every log line. Defaults to false.
* @param tail
* - `all` or `<number>`, Output specified number of lines at the end of logs
*
* Consider wrapping any input stream you get with a frame reader to make reading frame easier.
*
* @see com.github.dockerjava.core.command.FrameReader
*/
public interface LogContainerCmd extends DockerCmd<InputStream> {
public interface LogContainerCmd extends AsyncDockerCmd<LogContainerCmd, Frame, Void> {

public String getContainerId();

Expand Down Expand Up @@ -69,14 +66,14 @@ public interface LogContainerCmd extends DockerCmd<InputStream> {

/**
* Its the responsibility of the caller to consume and/or close the {@link InputStream} to prevent connection leaks.
*
*
* @throws NotFoundException
* No such container
*/
@Override
public InputStream exec() throws NotFoundException;
public Void exec() throws NotFoundException;

public static interface Exec extends DockerCmdExec<LogContainerCmd, InputStream> {
public static interface Exec extends DockerCmdExec<LogContainerCmd, Void> {
}

}
}
16 changes: 0 additions & 16 deletions src/main/java/com/github/dockerjava/api/command/StatsCallback.java

This file was deleted.

15 changes: 5 additions & 10 deletions src/main/java/com/github/dockerjava/api/command/StatsCmd.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
package com.github.dockerjava.api.command;

import java.util.concurrent.ExecutorService;
import com.github.dockerjava.api.model.Statistics;

/**
* Get stats
*
* Get container stats. The result of {@link Statistics} is handled asynchronously because the docker remote API will
* block when a container is stopped until the container is up again.
*/
public interface StatsCmd extends DockerCmd<ExecutorService> {
public interface StatsCmd extends AsyncDockerCmd<StatsCmd, Statistics, Void> {
public StatsCmd withContainerId(String containerId);

public String getContainerId();

public StatsCmd withStatsCallback(StatsCallback statsCallback);

public StatsCallback getStatsCallback();

public static interface Exec extends DockerCmdExec<StatsCmd, ExecutorService> {
public static interface Exec extends DockerCmdExec<StatsCmd, Void> {
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.github.dockerjava.api.model;

public enum StreamType {
STDIN, STDOUT, STDERR
STDIN, STDOUT, STDERR, RAW
}
Loading
X Tutup