Skip to content

Commit

Permalink
#296 events() first sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Feb 22, 2019
1 parent fac7af6 commit 530404b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/amihaiemil/docker/DockerSystem.java
Expand Up @@ -26,6 +26,7 @@
package com.amihaiemil.docker;

import java.io.IOException;
import java.io.Reader;

/**
* Docker System API entry point.
Expand All @@ -45,4 +46,13 @@ public interface DockerSystem {
DiskSpaceInfo diskUsage()
throws IOException, UnexpectedResponseException;

/**
* Follow the events on the server in real time.
* @return The events {@link Reader}.
* @throws IOException If an I/O error occurs.
* @throws UnexpectedResponseException If the API responds with an
* unexpected status.
*/
Reader events()
throws IOException, UnexpectedResponseException;
}
17 changes: 17 additions & 0 deletions src/main/java/com/amihaiemil/docker/RtDockerSystem.java
Expand Up @@ -30,6 +30,7 @@
import org.apache.http.client.methods.HttpGet;

import java.io.IOException;
import java.io.Reader;
import java.net.URI;

/**
Expand Down Expand Up @@ -91,4 +92,20 @@ public DiskSpaceInfo diskUsage()
}
}

@Override
public Reader events() throws IOException, UnexpectedResponseException {
final HttpGet monitor = new HttpGet(
this.baseUri.toString() + "/events"
);
return this.client.execute(
monitor,
new ReadStream(
new MatchStatus(
monitor.getURI(),
HttpStatus.SC_OK
)
)
);
}

}

0 comments on commit 530404b

Please sign in to comment.