Implementing classes should invoke this method once their service has started. It will cause the service to transition from State#STARTING to State#RUNNING. @throws IllegalStateException if the service is not State#STARTING.
()
| 339 | |
| 340 | |
| 341 | protected final void notifyStarted() { |
| 342 | monitor.enter(); |
| 343 | try { |
| 344 | // We have to examine the internal state of the snapshot here to properly handle the stop |
| 345 | // while starting case. |
| 346 | if (snapshot.state != STARTING) { |
| 347 | IllegalStateException failure = new IllegalStateException("Cannot notifyStarted() when the service is " + snapshot.state); |
| 348 | notifyFailed(failure); |
| 349 | throw failure; |
| 350 | } |
| 351 | if (snapshot.shutdownWhenStartupFinishes) { |
| 352 | snapshot = new StateSnapshot(STOPPING); |
| 353 | // We don't call listeners here because we already did that when we set the |
| 354 | // shutdownWhenStartupFinishes flag. |
| 355 | doStop(); |
| 356 | } else { |
| 357 | snapshot = new StateSnapshot(RUNNING); |
| 358 | running(); |
| 359 | } |
| 360 | } finally { |
| 361 | monitor.leave(); |
| 362 | executeListeners(); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Implementing classes should invoke this method once their service has stopped. It will cause |
no test coverage detected