Package org.rapidcontext.core.proc
Class Library
java.lang.Object
org.rapidcontext.core.proc.Library
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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addBuiltIn
(Procedure proc) 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
deleteProcedure
(String name) Removes a procedure from the storage (if possible).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 procedure call interceptor.Returns the procedure usage metrics.getProcedure
(String name) Returns a loaded procedure.String[]
Returns an array with the names of all loaded procedures.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.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.boolean
Checks if all calls to a procedure should be traced.loadProcedure
(String name) 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
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.void
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
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.
-
Field Details
-
PATH_PROC
The procedure object storage path.
-
-
Constructor Details
-
Library
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 namecls
- the procedure implementation class- Throws:
ProcedureException
- if the procedure type was already registered
-
unregisterType
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, 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, 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, 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
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
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, 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, 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
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
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 typedata
- the procedure data object- Returns:
- the procedure stored
- Throws:
ProcedureException
- if the procedure couldn't be created or written to the data store
-
deleteProcedure
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
Returns the procedure call interceptor.- Returns:
- the procedure call interceptor
-
setInterceptor
Sets the procedure call interceptor, overriding the default.- Parameters:
i
- the procedure call interceptor to use
-
isTracing
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
Sets or clears the call tracing for a procedure.- Parameters:
name
- the name of the procedureenabled
- true to enabled tracing, false to disable
-
getMetrics
Returns the procedure usage metrics.- Returns:
- the procedure usage metrics
-
report
Reports procedure usage metrics for a single call.- Parameters:
proc
- the procedure executedstart
- the start time (in millis)success
- the success flagerror
- the optional error message
-