Class BackgroundCompiler

java.lang.Object
com.comphenix.protocol.reflect.compiler.BackgroundCompiler

public class BackgroundCompiler extends Object
Compiles structure modifiers on a background thread.

This is necessary as we cannot block the main thread.

Author:
Kristian
  • Field Details

    • REPORT_CANNOT_COMPILE_STRUCTURE_MODIFIER

      public static final ReportType REPORT_CANNOT_COMPILE_STRUCTURE_MODIFIER
    • REPORT_CANNOT_SCHEDULE_COMPILATION

      public static final ReportType REPORT_CANNOT_SCHEDULE_COMPILATION
    • THREAD_FORMAT

      public static final String THREAD_FORMAT
      The default format for the name of new worker threads.
      See Also:
      Constant Field Values
    • SHUTDOWN_DELAY_MS

      public static final int SHUTDOWN_DELAY_MS
      See Also:
      Constant Field Values
    • DEFAULT_DISABLE_AT_PERM_GEN

      public static final double DEFAULT_DISABLE_AT_PERM_GEN
      The default fraction of perm gen space after which the background compiler will be disabled.
      See Also:
      Constant Field Values
  • Constructor Details

    • BackgroundCompiler

      public BackgroundCompiler(ClassLoader loader, ErrorReporter reporter)
      Initialize a background compiler.

      Uses the default THREAD_FORMAT to name worker threads.

      Parameters:
      loader - - class loader from Bukkit.
      reporter - - current error reporter.
    • BackgroundCompiler

      public BackgroundCompiler(ClassLoader loader, ErrorReporter reporter, ExecutorService executor)
      Initialize a background compiler utilizing the given thread pool.
      Parameters:
      loader - - class loader from Bukkit.
      reporter - - current error reporter.
      executor - - thread pool we'll use.
  • Method Details

    • getInstance

      public static BackgroundCompiler getInstance()
      Retrieves the current background compiler.
      Returns:
      Current background compiler.
    • setInstance

      public static void setInstance(BackgroundCompiler backgroundCompiler)
      Sets the single background compiler we're using.
      Parameters:
      backgroundCompiler - - current background compiler, or NULL if the library is not loaded.
    • scheduleCompilation

      public void scheduleCompilation(Map<Class,​StructureModifier> cache, Class key)
      Ensure that the indirectly given structure modifier is eventually compiled.
      Parameters:
      cache - - store of structure modifiers.
      key - - key of the structure modifier to compile.
    • scheduleCompilation

      public <TKey> void scheduleCompilation(StructureModifier<TKey> uncompiled, CompileListener<TKey> listener)
      Ensure that the given structure modifier is eventually compiled.
      Type Parameters:
      TKey - Type
      Parameters:
      uncompiled - - structure modifier to compile.
      listener - - listener responsible for responding to the compilation.
    • addListener

      public <TKey> void addListener(StructureModifier<TKey> uncompiled, CompileListener<TKey> listener)
      Add a compile listener if we are still waiting for the structure modifier to be compiled.
      Type Parameters:
      TKey - Type
      Parameters:
      uncompiled - - the structure modifier that may get compiled.
      listener - - the listener to invoke in that case.
    • shutdownAll

      public void shutdownAll()
      Clean up after ourselves using the default timeout.
    • shutdownAll

      public void shutdownAll(long timeout, TimeUnit unit)
      Clean up after ourselves.
      Parameters:
      timeout - - the maximum time to wait.
      unit - - the time unit of the timeout argument.
    • isEnabled

      public boolean isEnabled()
      Retrieve whether or not the background compiler is enabled.
      Returns:
      TRUE if it is enabled, FALSE otherwise.
    • setEnabled

      public void setEnabled(boolean enabled)
      Sets whether or not the background compiler is enabled.
      Parameters:
      enabled - - TRUE to enable it, FALSE otherwise.
    • getDisablePermGenFraction

      public double getDisablePermGenFraction()
      Retrieve the fraction of perm gen space used after which the background compiler will be disabled.
      Returns:
      The fraction after which the background compiler is disabled.
    • setDisablePermGenFraction

      public void setDisablePermGenFraction(double fraction)
      Set the fraction of perm gen space used after which the background compiler will be disabled.
      Parameters:
      fraction - - the maximum use of perm gen space.
    • getCompiler

      public StructureCompiler getCompiler()
      Retrieve the current structure compiler.
      Returns:
      Current structure compiler.