Package nl.vpro.jmx

Class MBeans

java.lang.Object
nl.vpro.jmx.MBeans

public class MBeans extends Object
Utilities to start jmx tasks in the background.
Since:
1.75
Author:
Michiel Meeuwissen
  • Field Details

    • DEFAULT_DURATION

      public static final Duration DEFAULT_DURATION
  • Constructor Details

    • MBeans

      public MBeans()
  • Method Details

    • isRunning

      public static boolean isRunning(String key)
    • cancel

      public static Future<String> cancel(String key)
    • returnString

      public static String returnString(@Nullable String key, @NonNull nl.vpro.logging.simple.StringSupplierSimpleLogger description, @Nullable Duration wait, @NonNull Consumer<nl.vpro.logging.simple.StringSupplierSimpleLogger> logger)
      Parameters:
      key - A key on which the job can be 'locked'.
      description - A supplier that before the job starts should describe the job. One can be created using e.g. multiLine(Logger, String, Object...) or singleLine(Logger, String, Object...)
      wait - How long to wait before returning with a message that the job is not yet finished, but still running. This may be null, in which case this will run nothing in the background
      logger - A job returning a String when ready. This string will be returned.
      Returns:
      The string to be used as a return value for a JMX operation
    • returnString

      public static String returnString(@NonNull String key, @NonNull nl.vpro.logging.simple.StringSupplierSimpleLogger description, @NonNull Consumer<nl.vpro.logging.simple.StringSupplierSimpleLogger> logger)
    • returnString

      public static String returnString(@NonNull nl.vpro.logging.simple.StringSupplierSimpleLogger description, @NonNull Duration wait, @NonNull Consumer<nl.vpro.logging.simple.StringSupplierSimpleLogger> logger)
      Defaulting version of {@link #returnString(String, StringSupplierSimpleLogger, Duration, Consumer)), with no key (meaning that jobs can be started concurrently.
    • returnString

      public static String returnString(@NonNull nl.vpro.logging.simple.StringSupplierSimpleLogger description, @NonNull Consumer<nl.vpro.logging.simple.StringSupplierSimpleLogger> logger)
      Defaulting version of {@link #returnString(String, StringSupplierSimpleLogger, Duration, Consumer)), with no key (meaning that jobs can be started concurrently.
    • returnMultilineString

      public static String returnMultilineString(@NonNull org.slf4j.Logger log, @NonNull Consumer<nl.vpro.logging.simple.StringSupplierSimpleLogger> logger)
    • returnString

      @Deprecated public static String returnString(@Nullable String key, @NonNull nl.vpro.logging.simple.StringSupplierSimpleLogger description, @NonNull Duration wait, @NonNull Callable<String> job)
      Deprecated.
    • returnString

      @Deprecated public static String returnString(@NonNull nl.vpro.logging.simple.StringSupplierSimpleLogger description, @NonNull Duration wait, @NonNull Callable<String> job)
      Deprecated.
      Defaulting version of {@link #returnString(String, StringSupplierSimpleLogger, Duration, Callable)), with no key (meaning that jobs can be started concurrently.
    • returnString

      @Deprecated public static String returnString(@NonNull Supplier<String> description, @NonNull Duration wait, @NonNull Callable<String> job)
      Deprecated.
    • returnString

      @Deprecated public static String returnString(@NonNull nl.vpro.logging.simple.StringSupplierSimpleLogger description, @NonNull Callable<String> job)
      Deprecated.
      Defaulting version of returnString(StringSupplierSimpleLogger, Duration, Callable) waiting for 5 seconds before time out.
    • singleLine

      public static nl.vpro.logging.simple.StringSupplierSimpleLogger singleLine(org.slf4j.Logger log, String message, Object... args)
      Parameters:
      log - Logger instance to log too
      message - Initial value of the string
      args - The arguments of the initial value
      Returns:
      a StringBuilderSimpleLogger representing a single line string (actually a MBeans.UpdatableString
    • multiLine

      public static nl.vpro.logging.simple.StringSupplierSimpleLogger multiLine(org.slf4j.Logger log, String message, Object... args)
      Parameters:
      log - Logger instance to log too
      message - First line of the string (logged as info)
      args - The arguments of the first line
      Returns:
      a StringBuilderSimpleLogger representing multiple lines actually a StringBuilderSimpleLogger
    • multiLine

      public static nl.vpro.logging.simple.StringSupplierSimpleLogger multiLine(nl.vpro.logging.simple.Level level, org.slf4j.Logger log, String message, Object... args)
    • multiLine

      public static nl.vpro.logging.simple.StringSupplierSimpleLogger multiLine(org.slf4j.Logger log)
      Parameters:
      log - Logger instance to log too
      Returns:
      a StringBuilderSimpleLogger representing multiple lines actually a StringBuilderSimpleLogger
    • isEmpty

      public static boolean isEmpty(String string)
      A 'visualvm' oriented check whether a string is 'empty'. i.e. not filled.

      The point being that also the string 'String' is considered empty, because that is the default value in visualvm, so that's the value when untouched.

      Since:
      2.7
    • isBlank

      public static boolean isBlank(String string)
      A 'visualvm' oriented check whether a string is 'blank'. i.e. not filled, or only filled with space.

      The point being that also the string 'String' is considered blank, because that is the default value in visualvm, so that's the value when untouched.

      Since:
      2.7
    • asBoolean

      public static boolean asBoolean(String string, boolean defaultValue)
      Since:
      4.0
    • registerBean

      public static <T> void registerBean(ObjectName name, T object)
      Since:
      2.10
    • registerBean

      public static ObjectName registerBean(Object object, String name)
    • unregister

      public static void unregister(ObjectName name)
      Since:
      2.10
    • getObjectName

      public static ObjectName getObjectName(String prefix, Object object)
      Since:
      2.10
    • getObjectNameWithName

      public static ObjectName getObjectNameWithName(Object object, String name)