@@ -28,10 +28,12 @@ public class Container {
2828 private static final Logger LOG = Logger .getLogger (Container .class .getName ());
2929 private final DockerProtocol protocol ;
3030 private final ContainerId id ;
31+ private boolean running ;
3132
3233 public Container (DockerProtocol protocol , ContainerId id ) {
3334 this .protocol = Require .nonNull ("Protocol" , protocol );
3435 this .id = Require .nonNull ("Container id" , id );
36+ this .running = false ;
3537 LOG .info ("Created container " + id );
3638 }
3739
@@ -42,16 +44,20 @@ public ContainerId getId() {
4244 public void start () {
4345 LOG .info ("Starting " + getId ());
4446 protocol .startContainer (id );
47+ this .running = true ;
4548 }
4649
4750 public void stop (Duration timeout ) {
4851 Require .nonNull ("Timeout to wait for" , timeout );
4952
50- LOG .info ("Stopping " + getId ());
51- try {
52- protocol .stopContainer (id , timeout );
53- } catch (RuntimeException e ) {
54- LOG .log (Level .WARNING , "Unable to stop container: " + e .getMessage (), e );
53+ if (this .running ) {
54+ LOG .info ("Stopping " + getId ());
55+ try {
56+ protocol .stopContainer (id , timeout );
57+ this .running = false ;
58+ } catch (RuntimeException e ) {
59+ LOG .log (Level .WARNING , "Unable to stop container: " + e .getMessage (), e );
60+ }
5561 }
5662 }
5763
0 commit comments