Class BackgroundCompiler
java.lang.Object
com.comphenix.protocol.reflect.compiler.BackgroundCompiler
Compiles structure modifiers on a background thread.
This is necessary as we cannot block the main thread.
- Author:
- Kristian
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic doubleThe default fraction of perm gen space after which the background compiler will be disabled.static ReportTypestatic ReportTypestatic intstatic StringThe default format for the name of new worker threads. -
Constructor Summary
ConstructorsConstructorDescriptionBackgroundCompiler(ClassLoader loader, ErrorReporter reporter)Initialize a background compiler.BackgroundCompiler(ClassLoader loader, ErrorReporter reporter, ExecutorService executor)Initialize a background compiler utilizing the given thread pool. -
Method Summary
Modifier and TypeMethodDescription<TKey> voidaddListener(StructureModifier<TKey> uncompiled, CompileListener<TKey> listener)Add a compile listener if we are still waiting for the structure modifier to be compiled.Retrieve the current structure compiler.doubleRetrieve the fraction of perm gen space used after which the background compiler will be disabled.static BackgroundCompilerRetrieves the current background compiler.booleanRetrieve whether or not the background compiler is enabled.<TKey> voidscheduleCompilation(StructureModifier<TKey> uncompiled, CompileListener<TKey> listener)Ensure that the given structure modifier is eventually compiled.voidscheduleCompilation(Map<Class,StructureModifier> cache, Class key)Ensure that the indirectly given structure modifier is eventually compiled.voidsetDisablePermGenFraction(double fraction)Set the fraction of perm gen space used after which the background compiler will be disabled.voidsetEnabled(boolean enabled)Sets whether or not the background compiler is enabled.static voidsetInstance(BackgroundCompiler backgroundCompiler)Sets the single background compiler we're using.voidClean up after ourselves using the default timeout.voidshutdownAll(long timeout, TimeUnit unit)Clean up after ourselves.
-
Field Details
-
REPORT_CANNOT_COMPILE_STRUCTURE_MODIFIER
-
REPORT_CANNOT_SCHEDULE_COMPILATION
-
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_GENThe default fraction of perm gen space after which the background compiler will be disabled.- See Also:
- Constant Field Values
-
-
Constructor Details
-
BackgroundCompiler
Initialize a background compiler.Uses the default
THREAD_FORMATto name worker threads.- Parameters:
loader- - class loader from Bukkit.reporter- - current error reporter.
-
BackgroundCompiler
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
Retrieves the current background compiler.- Returns:
- Current background compiler.
-
setInstance
Sets the single background compiler we're using.- Parameters:
backgroundCompiler- - current background compiler, or NULL if the library is not loaded.
-
scheduleCompilation
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
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
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
Retrieve the current structure compiler.- Returns:
- Current structure compiler.
-