Class AbstractManager

All Implemented Interfaces:
Direct Known Subclasses:
AbstractDatabaseManager, HttpManager, JeroMqManager, JmsManager, JndiManager, KafkaManager, MailManager, OutputStreamManager, WriterManager

public abstract class AbstractManager extends Object implements AutoCloseable
Abstract base class used to register managers.

This class implements AutoCloseable mostly to allow unit tests to be written safely and succinctly. While managers do need to allocate resources (usually on construction) and then free these resources, a manager is longer lived than other auto-closeable objects like streams. None the less, making a manager AutoCloseable forces readers to be aware of the pattern: allocate resources on construction and call close() at some point.

  • Field Details

    • LOGGER

      protected static final Logger LOGGER
      Allow subclasses access to the status logger without creating another instance.
    • count

      protected int count
      Number of Appenders using this manager.
  • Constructor Details

  • Method Details

    • close

      public void close()
      Called to signify that this Manager is no longer required by an Appender.
      Specified by:
      close in interface AutoCloseable
    • stop

      public boolean stop(long timeout, TimeUnit timeUnit)
    • getManager

      public static <M extends AbstractManager, T> M getManager(String name, ManagerFactory<M,T> factory, T data)
      Retrieves a Manager if it has been previously created or creates a new Manager.
      Type Parameters:
      M - The Type of the Manager to be created.
      T - The type of the Factory data.
      name - The name of the Manager to retrieve.
      factory - The Factory to use to create the Manager.
      data - An Object that should be passed to the factory when creating the Manager.
      A Manager with the specified name and type.
    • updateData

      public void updateData(Object data)
      Used by Log4j to update the Manager during reconfiguration. This method should be considered private. Implementations may not be thread safe. This method may be made protected in a future release.
      data - The data to update.
    • hasManager

      public static boolean hasManager(String name)
      Determines if a Manager with the specified name exists.
      name - The name of the Manager.
      True if the Manager exists, false otherwise.
    • narrow

      protected static <M extends AbstractManager> M narrow(Class<M> narrowClass, AbstractManager manager)
      Returns the specified manager, cast to the specified narrow type.
      Type Parameters:
      M - the narrow type
      narrowClass - the type to cast to
      manager - the manager object to return
      the specified manager, cast to the specified narrow type
      ConfigurationException - if the manager cannot be cast to the specified type, which only happens when the configuration has multiple incompatible appenders pointing to the same resource
      See Also:
    • logger

      protected static StatusLogger logger()
    • releaseSub

      protected boolean releaseSub(long timeout, TimeUnit timeUnit)
      May be overridden by managers to perform processing while the manager is being released and the lock is held. A timeout is passed for implementors to use as they see fit.
      timeout - timeout
      timeUnit - timeout time unit
      true if all resources were closed normally, false otherwise.
    • getCount

      protected int getCount()
    • getLoggerContext

      public LoggerContext getLoggerContext()
      Gets the logger context used to create this instance or null. The logger context is usually set when an appender creates a manager and that appender is given a Configuration. Not all appenders are given a Configuration by their factory method or builder.
      the logger context used to create this instance or null.
    • release

      @Deprecated public void release()
      In 2.7, use close().
      Called to signify that this Manager is no longer required by an Appender.
    • getName

      public String getName()
      Returns the name of the Manager.
      The name of the Manager.
    • getContentFormat

      public Map<String,String> getContentFormat()
      Provide a description of the content format supported by this Manager. Default implementation returns an empty (unspecified) Map.
      a Map of key/value pairs describing the Manager-specific content format, or an empty Map if no content format descriptors are specified.
    • getStrSubstitutor

      protected StrSubstitutor getStrSubstitutor()
      Gets my configuration's StrSubstitutor or null.
      my configuration's StrSubstitutor or null.
    • log

      protected void log(Level level, String message, Throwable throwable)
    • logDebug

      protected void logDebug(String message, Throwable throwable)
    • logError

      protected void logError(String message, Throwable throwable)
    • logWarn

      protected void logWarn(String message, Throwable throwable)