Class LoggingServiceListener

java.lang.Object
com.google.common.util.concurrent.Service.Listener
org.graylog2.utilities.LoggingServiceListener

public class LoggingServiceListener extends com.google.common.util.concurrent.Service.Listener
This class is a convenience listener for Service instances so that service lifecycle changes can easily be logged without having to manually write listeners everywhere.
It allows adding an action that is run when the service transitions into Service.State.RUNNING as that is the most common case. If you need additional, or more complex listeners, add a new instance in addition to this simple class.
  • Constructor Details

    • LoggingServiceListener

      public LoggingServiceListener(String serviceName, String id)
      Creates a new logging listener for the service name and an id.
      Parameters:
      serviceName - the concise name describing the service being listened to (e.g. "Input" or "Cache")
      id - the unique id of the service instance, useful if there are more than one running.
    • LoggingServiceListener

      public LoggingServiceListener(String serviceName, String id, @NotNull @NotNull org.slf4j.Logger logger)
    • LoggingServiceListener

      public LoggingServiceListener(String serviceName, String id, @Nullable Runnable action, @NotNull @NotNull org.slf4j.Logger logger)
  • Method Details

    • starting

      public void starting()
      Overrides:
      starting in class com.google.common.util.concurrent.Service.Listener
    • running

      public void running()
      Overrides:
      running in class com.google.common.util.concurrent.Service.Listener
    • stopping

      public void stopping(com.google.common.util.concurrent.Service.State from)
      Overrides:
      stopping in class com.google.common.util.concurrent.Service.Listener
    • terminated

      public void terminated(com.google.common.util.concurrent.Service.State from)
      Overrides:
      terminated in class com.google.common.util.concurrent.Service.Listener
    • failed

      public void failed(com.google.common.util.concurrent.Service.State from, Throwable failure)
      Overrides:
      failed in class com.google.common.util.concurrent.Service.Listener