|
| 1 | +/** |
| 2 | + * Copyright (c) 2018-2020, Mihai Emil Andronache |
| 3 | + * All rights reserved. |
| 4 | + * Redistribution and use in source and binary forms, with or without |
| 5 | + * modification, are permitted provided that the following conditions are met: |
| 6 | + * 1)Redistributions of source code must retain the above copyright notice, |
| 7 | + * this list of conditions and the following disclaimer. |
| 8 | + * 2)Redistributions in binary form must reproduce the above copyright notice, |
| 9 | + * this list of conditions and the following disclaimer in the documentation |
| 10 | + * and/or other materials provided with the distribution. |
| 11 | + * 3)Neither the name of docker-java-api nor the names of its |
| 12 | + * contributors may be used to endorse or promote products derived from |
| 13 | + * this software without specific prior written permission. |
| 14 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 15 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 17 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 18 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 19 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 20 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 21 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 22 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 23 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 24 | + * POSSIBILITY OF SUCH DAMAGE. |
| 25 | + */ |
| 26 | +package com.amihaiemil.docker; |
| 27 | + |
| 28 | +import javax.json.JsonObject; |
| 29 | +import java.io.IOException; |
| 30 | +import java.time.LocalDateTime; |
| 31 | +import java.util.Map; |
| 32 | +import java.util.function.Supplier; |
| 33 | +import java.util.stream.Stream; |
| 34 | + |
| 35 | +/** |
| 36 | + * Events API. |
| 37 | + * @author Mihai Andronache (amihaiemil@gmail.com) |
| 38 | + * @version $Id$ |
| 39 | + * @since 0.0.13 |
| 40 | + */ |
| 41 | +public interface Events { |
| 42 | + |
| 43 | + /** |
| 44 | + * Show events created since the specified timestamp, |
| 45 | + * then stream new events. |
| 46 | + * @param timestamp Given timestamp. |
| 47 | + * @return Filtered Events. |
| 48 | + */ |
| 49 | + Events since(final LocalDateTime timestamp); |
| 50 | + |
| 51 | + /** |
| 52 | + * Show events created until the specified timestamp, |
| 53 | + * then stop streaming. |
| 54 | + * @param timestamp Given timestamp. |
| 55 | + * @return Filtered Events. |
| 56 | + */ |
| 57 | + Events until(final LocalDateTime timestamp); |
| 58 | + |
| 59 | + /** |
| 60 | + * Filter these Events. |
| 61 | + * @param filter Supplier of filters. |
| 62 | + * @return Filtered Events. |
| 63 | + * @see <a href="https://docs.docker.com/engine/api/v1.40/#operation/SystemEvents">Docker API Docs</a> |
| 64 | + */ |
| 65 | + Events filter(final Supplier<Map<String, Iterable<String>>> filter); |
| 66 | + |
| 67 | + /** |
| 68 | + * Start monitoring these events. Pay attention:<br><br> |
| 69 | + * The Stream is <b>infinite</b>, which means you have to specify a |
| 70 | + * <b>limit</b> before calling a terminal operation on it. Otherwise, |
| 71 | + * your terminal operation will run until the Server closes the connection. |
| 72 | + * Example: |
| 73 | + * <pre> |
| 74 | + * final Docker docker = ...; |
| 75 | + * final List<JsonObject> firstTen = docker.events().monitor() |
| 76 | + * .limit(10).collect(Collectors.toList()); |
| 77 | + * //It will wait for and return the first 10 real-time events |
| 78 | + * //from the server. |
| 79 | + * </pre> |
| 80 | + * @throws IOException If there is any I/O problem. |
| 81 | + * @throws UnexpectedResponseException If the response is not 200 OK. |
| 82 | + * @return Stream of events. |
| 83 | + */ |
| 84 | + Stream<JsonObject> monitor() |
| 85 | + throws IOException, UnexpectedResponseException; |
| 86 | + |
| 87 | + /** |
| 88 | + * Docker where these events came from. |
| 89 | + * @return Docker. |
| 90 | + */ |
| 91 | + Docker docker(); |
| 92 | +} |
0 commit comments