public class ContainerStateObserverImpl extends Object implements ContainerStateObserver
ContainerStateObserver interface by
starting a scheduled job that retrieves a list of containers and their status
using the given ContainerManager. If a container has the status
"exited" and can be found in the internal list of monitored containers, the
ContainerTerminationCallback.notifyTermination(String, int) methods
of all registered callbacks are called.
Created by Timofey Ermilov on 01/09/16.| Modifier and Type | Field and Description |
|---|---|
private static org.slf4j.Logger |
LOGGER |
private ContainerManager |
manager
The
ContainerManager class that is used to retrieve information about
containers. |
private List<String> |
monitoredContainers
Internal list of monitored Docker containers.
|
private int |
repeatInterval
The time interval in which the checking of containers is performed.
|
private List<ContainerTerminationCallback> |
terminationCallbacks
List of termination callbacks that are called if one of the monitored
containers was terminated.
|
private Timer |
timer
The
Timer used to regularly check the state of container. |
private static List<String> |
unfinishedTaskStates |
| Constructor and Description |
|---|
ContainerStateObserverImpl(ContainerManager manager,
int repeatInterval)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addObservedContainer(String containerId)
Adds the container with the given container Id to the list of observed
containers.
|
void |
addTerminationCallback(ContainerTerminationCallback callback)
Adds the callback that will be notified using
ContainerTerminationCallback.notifyTermination(String, int) |
List<String> |
getObservedContainers()
Returns the list of observed containers.
|
void |
removedObservedContainer(String containerId)
Removes the container with the given container Id from the list of
observed containers.
|
void |
removeTerminationCallback(ContainerTerminationCallback callback)
Removes the callback that will be notified using
ContainerTerminationCallback.notifyTermination(String, int) |
void |
startObserving()
Start observing the state of containers
|
void |
stopObserving()
Stop observing the state of containers
|
private static final org.slf4j.Logger LOGGER
private List<String> monitoredContainers
private List<ContainerTerminationCallback> terminationCallbacks
private ContainerManager manager
ContainerManager class that is used to retrieve information about
containers.private int repeatInterval
public ContainerStateObserverImpl(ContainerManager manager, int repeatInterval)
manager - The ContainerManager class that is used to retrieve
information about containers.repeatInterval - The time interval in which the checking of containers is
performed.public void startObserving()
ContainerStateObserverstartObserving in interface ContainerStateObserverpublic void stopObserving()
ContainerStateObserverstopObserving in interface ContainerStateObserverpublic void addTerminationCallback(ContainerTerminationCallback callback)
ContainerStateObserverContainerTerminationCallback.notifyTermination(String, int)addTerminationCallback in interface ContainerStateObservercallback - the class that should be called if a container terminatespublic void removeTerminationCallback(ContainerTerminationCallback callback)
ContainerStateObserverContainerTerminationCallback.notifyTermination(String, int)removeTerminationCallback in interface ContainerStateObservercallback - the class that should be called if a container terminatespublic void addObservedContainer(String containerId)
ContainerStateObserveraddObservedContainer in interface ContainerStateObservercontainerId - the Id of the container that should be observedpublic void removedObservedContainer(String containerId)
ContainerStateObserverremovedObservedContainer in interface ContainerStateObservercontainerId - the Id of the container that should be removedpublic List<String> getObservedContainers()
ContainerStateObservergetObservedContainers in interface ContainerStateObserverCopyright © 2017–2018. All rights reserved.