Class Library

java.lang.Object
org.rapidcontext.core.proc.Library

public class Library extends Object
A procedure library. This class contains the set of loaded and built-in procedures. The library automatically loads and caches procedures found in the data store. If the procedure content in the data store is modified, the library cache must be cleared or inconsistencies will result.
Version:
1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Path
    The procedure object storage path.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Library(Storage storage)
    Creates a new procedure library.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Built-in procedures should be initialized via the 'className' property on a proper stored (serialized) object.
    void
    Clears the cache of loaded procedures from the library.
    void
    Removes a procedure from the storage (if possible).
    static Bindings
    Deprecated, for removal: This API element is subject to removal in a future version.
    Check the storage subtypes to 'type/procedure' instead of this.
    Returns the procedure call interceptor.
    Returns the procedure usage metrics.
    Returns a loaded procedure.
    Returns an array with the names of all loaded procedures.
    static String[]
    Deprecated, for removal: This API element is subject to removal in a future version.
    Check the storage subtypes to 'type/procedure' instead of this.
    boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    Built-in procedures are managed as storable objects, so this method is no longer reliable.
    boolean
    Checks if all calls to a procedure should be traced.
    Loads (or reloads) a procedure from the data store to the cache.
    void
    Loads built-in procedures via storage types.
    static void
    registerType(String type, Class<?> cls)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use a storage subtype to 'type/procedure' instead of manually registering here.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Built-in procedures should be managed as proper stored (serialized) objects.
    void
    report(Procedure proc, long start, boolean success, String error)
    Reports procedure usage metrics for a single call.
    void
    Sets the procedure call interceptor, overriding the default.
    void
    setTracing(String name, boolean enabled)
    Sets or clears the call tracing for a procedure.
    storeProcedure(String id, String type, Dict data)
    Stores a procedure to the data store.
    static void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use a storage subtype to 'type/procedure' instead of manually registering here.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • PATH_PROC

      public static final Path PATH_PROC
      The procedure object storage path.
  • Constructor Details

    • Library

      public Library(Storage storage)
      Creates a new procedure library.
      Parameters:
      storage - the data storage to use
  • Method Details

    • registerType

      @Deprecated(forRemoval=true) public static void registerType(String type, Class<?> cls) throws ProcedureException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use a storage subtype to 'type/procedure' instead of manually registering here. Storage types are automatically managed.
      Registers a procedure type name. All add-on procedures should register their unique type names with this method. Normally each procedure class has one type name, but alias names are permitted.
      Parameters:
      type - the unique procedure type name
      cls - the procedure implementation class
      Throws:
      ProcedureException - if the procedure type was already registered
    • unregisterType

      @Deprecated(forRemoval=true) public static void unregisterType(String type)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use a storage subtype to 'type/procedure' instead of manually registering here. Storage types are automatically managed.
      Unregisters a procedure type name. All add-on procedures that are created via plug-ins should call this method when the plug-in unloads.
      Parameters:
      type - the unique procedure type name
    • getTypes

      @Deprecated(forRemoval=true) public static String[] getTypes()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Check the storage subtypes to 'type/procedure' instead of this.
      Returns an array with all the registered procedure type names.
      Returns:
      an array with all procedure type names
    • getDefaultBindings

      @Deprecated(forRemoval=true) public static Bindings getDefaultBindings(String type)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Check the storage subtypes to 'type/procedure' instead of this.
      Returns the default bindings for a registered procedure type. This function will instantiate a new empty procedure of the specified type and return the bindings thus created.
      Parameters:
      type - the unique procedure type name
      Returns:
      the default bindings for the procedure type, or null if the procedure creation failed
    • hasBuiltIn

      @Deprecated(forRemoval=true) public boolean hasBuiltIn(String name)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Built-in procedures are managed as storable objects, so this method is no longer reliable.
      Checks if the specified procedure name is a registered built-in procedure.
      Parameters:
      name - the procedure name
      Returns:
      true if the procedure is a built-in procedure, or false otherwise
    • getProcedureNames

      public String[] getProcedureNames() throws ProcedureException
      Returns an array with the names of all loaded procedures.
      Returns:
      an array with the names of all loaded procedures
      Throws:
      ProcedureException - if the procedures couldn't be listed
    • getProcedure

      public Procedure getProcedure(String name) throws ProcedureException
      Returns a loaded procedure.
      Parameters:
      name - the procedure name
      Returns:
      the procedure object
      Throws:
      ProcedureException - if the procedure couldn't be found, or failed to load correctly
    • refreshAliases

      public void refreshAliases()
      Loads built-in procedures via storage types. This method is safe to call repeatedly (after each plug-in load).
    • addBuiltIn

      @Deprecated(forRemoval=true) public void addBuiltIn(Procedure proc) throws ProcedureException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Built-in procedures should be initialized via the 'className' property on a proper stored (serialized) object.
      Adds a new built-in procedure to the library.
      Parameters:
      proc - the procedure definition
      Throws:
      ProcedureException - if an identically named procedure already exists
    • removeBuiltIn

      @Deprecated(forRemoval=true) public void removeBuiltIn(String name)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Built-in procedures should be managed as proper stored (serialized) objects.
      Removes a built-in procedure from the library.
      Parameters:
      name - the procedure name
    • clearCache

      public void clearCache()
      Clears the cache of loaded procedures from the library. The procedure cache is continuously built up each time a procedure is accessed.
    • loadProcedure

      public Procedure loadProcedure(String name) throws ProcedureException
      Loads (or reloads) a procedure from the data store to the cache.
      Parameters:
      name - the procedure name
      Returns:
      the procedure loaded
      Throws:
      ProcedureException - if the procedure couldn't be loaded
    • storeProcedure

      public Procedure storeProcedure(String id, String type, Dict data) throws ProcedureException
      Stores a procedure to the data store. The procedure is created from the specified data object, stored to the data store and also placed in the library cache.
      Parameters:
      id - the procedure name (object id)
      type - the procedure type
      data - the procedure data object
      Returns:
      the procedure stored
      Throws:
      ProcedureException - if the procedure couldn't be created or written to the data store
    • deleteProcedure

      public void deleteProcedure(String name) throws ProcedureException
      Removes a procedure from the storage (if possible). Normally, only procedures in the local plug-in can be removed this way. Built-in procedures will remain unaffected by this.
      Parameters:
      name - the name of the procedure
      Throws:
      ProcedureException - if an error occurred while removing the procedure from storage
    • getInterceptor

      public Interceptor getInterceptor()
      Returns the procedure call interceptor.
      Returns:
      the procedure call interceptor
    • setInterceptor

      public void setInterceptor(Interceptor i)
      Sets the procedure call interceptor, overriding the default.
      Parameters:
      i - the procedure call interceptor to use
    • isTracing

      public boolean isTracing(String name)
      Checks if all calls to a procedure should be traced.
      Parameters:
      name - the name of the procedure
      Returns:
      true if all calls should be traced, or false otherwise
    • setTracing

      public void setTracing(String name, boolean enabled)
      Sets or clears the call tracing for a procedure.
      Parameters:
      name - the name of the procedure
      enabled - true to enabled tracing, false to disable
    • getMetrics

      public Metrics getMetrics()
      Returns the procedure usage metrics.
      Returns:
      the procedure usage metrics
    • report

      public void report(Procedure proc, long start, boolean success, String error)
      Reports procedure usage metrics for a single call.
      Parameters:
      proc - the procedure executed
      start - the start time (in millis)
      success - the success flag
      error - the optional error message