Class Loader

java.lang.Object
ch.grengine.engine.Loader
All Implemented Interfaces:
Closeable, AutoCloseable

public class Loader extends Object implements Closeable
Wrapper for a SourceClassLoader that can only be used by the Engine that created it.
Since:
1.0
Author:
Alain Stalder, Made in Switzerland.
  • Constructor Details

    • Loader

      public Loader(EngineId engineId, long number, boolean isAttached, SourceClassLoader sourceClassLoader)
      constructor, with default class releaser.
      Parameters:
      engineId - the engine ID, used to authenticate the caller in some instance methods
      number - the loader number
      isAttached - whether the loader is attached to the engine or not
      sourceClassLoader - the SourceClassLoader to use for loading classes
      Throws:
      NullPointerException - if any of the arguments is null
      Since:
      1.0
    • Loader

      public Loader(EngineId engineId, long number, boolean isAttached, ClassReleaser classReleaser, SourceClassLoader sourceClassLoader)
      constructor, with given class releaser.
      Parameters:
      engineId - the engine ID, used to authenticate the caller in some instance methods
      number - the loader number
      isAttached - whether the loader is attached to the engine or not
      classReleaser - the class releaser
      sourceClassLoader - the SourceClassLoader to use for loading classes
      Throws:
      NullPointerException - if any of the arguments is null
      Since:
      1.1
  • Method Details

    • getSourceClassLoader

      public SourceClassLoader getSourceClassLoader(EngineId engineId)
      gets the source class loader (if the engine ID matches).
      Parameters:
      engineId - engine ID
      Returns:
      source class loader
      Throws:
      IllegalArgumentException - if the engine ID does not match
      Since:
      1.0
    • setSourceClassLoader

      public void setSourceClassLoader(EngineId engineId, SourceClassLoader sourceClassLoader)
      sets the source class loader (if the engine ID matches).
      Parameters:
      engineId - engine ID
      sourceClassLoader - source class loader
      Throws:
      IllegalArgumentException - if the engine ID does not match
      Since:
      1.0
    • getNumber

      public long getNumber()
      gets the loader number.
      Returns:
      loader number
      Since:
      1.0
    • isAttached

      public boolean isAttached()
      gets whether the loader is attached to the engine or not.
      Returns:
      whether the loader is attached to the engine or not
      Since:
      1.0
    • equals

      public boolean equals(Object obj)
      two loaders are equal if and only if their loader number and their engine ID are equal.
      Overrides:
      equals in class Object
      Since:
      1.0
    • hashCode

      public int hashCode()
      implementation based on loader number and engine ID.
      Overrides:
      hashCode in class Object
      Since:
      1.0
    • toString

      public String toString()
      returns a string suitable for logging.
      Overrides:
      toString in class Object
      Returns:
      a string suitable for logging
      Since:
      1.0
    • close

      public void close()
      release metadata for all classed ever loaded using this loader.

      Allows to remove metadata associated by Groovy (or Java) with a class, which is often necessary to get on-the-fly garbage collection.

      Generally call only when really done using this loader and all loaded classes; subsequently trying to use this loader or its classes results generally in undefined behavior.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Since:
      1.1