Package org.rapidcontext.core.proc
Class CallContext
java.lang.Object
org.rapidcontext.core.proc.CallContext
A procedure call context. Each procedure call occurs within a
specific call context that contains the environment, library and
currently used adapter connections. The context also keeps track
of the call stack and other information relevant to the procedure
call.
- Version:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The attribute used for storing the execution end time.static final String
The attribute used for storing the error message.static final String
The attribute used for storing the log string buffer.static final String
The attribute used for storing the execution root procedure.static final String
The attribute used for storing the progress ratio.static final String
The attribute used for storing the result data.static final String
The attribute used for storing call source information.static final String
The attribute used for storing the execution start time.static final String
The attribute used for storing the trace flag.static final String
The attribute used for storing the user information.static final int
The maximum number of characters to store in the log buffer. -
Constructor Summary
ConstructorsConstructorDescriptionCallContext
(Storage storage, Environment env, Library library) Creates a new procedure call context. -
Method Summary
Modifier and TypeMethodDescriptionDeprecated, for removal: This API element is subject to removal in a future version.Replaced with org.rapidcontext.core.type.Procedure signature.Deprecated, for removal: This API element is subject to removal in a future version.Replaced with org.rapidcontext.core.type.Procedure signature.Calls a procedure with the specified arguments.Calls a procedure with the specified arguments.static void
checkAccess
(String path, String permission) Checks if the currently authenticated user has the specified access permission to a storage path.static void
checkInternalAccess
(String path) Checks if the currently authenticated user has internal access to a storage path.static void
checkReadAccess
(String path) Checks if the currently authenticated user has read access to a storage path.static void
checkSearchAccess
(String path) Checks if the currently authenticated user has search access to a storage path.static void
checkWriteAccess
(String path) Checks if the currently authenticated user has write access to a storage path.void
connectionReleaseAll
(boolean commit) Releases all reserved adapter connections.connectionReserve
(String id, String permission) Reserves a connection channel.Executes a procedure with the specified name and arguments.getAttribute
(String name) Returns a call attribute value.Returns the procedure call stack.Returns the connectivity environment used by this context.Returns the local procedure call interceptor.Returns the procedure library used by this context.Returns the data storage used by this context.void
Interrupts the current procedure call.boolean
Checks if the call has been interrupted.boolean
Checks if this call context has call trace logging enabled.void
Logs the specified message to the log if tracing is enabled.void
Logs the specified call to the log if tracing is enabled.void
Logs the specified call to the log if tracing is enabled.void
Logs the specified call error to the log if tracing is enabled.void
logResponse
(Object obj) Logs the specified call response to the log if tracing is enabled.readPermission
(int depth) Returns the permission required to read a path at the current call stack height.void
releaseAll
(boolean commit) Releases all currently reserved adapter connections.void
Deprecated, for removal: This API element is subject to removal in a future version.Replaced with org.rapidcontext.core.type.Procedure signature.void
Reserves all adapter connections needed for executing the specified procedure.void
setAttribute
(String name, Object value) Sets a call attribute value.void
Sets the local procedure call interceptor, overriding the default library procedure call interceptor for calls in this context.
-
Field Details
-
ATTRIBUTE_PROCEDURE
The attribute used for storing the execution root procedure. This attribute value is automatically stored by the execute() method.- See Also:
-
ATTRIBUTE_START_TIME
The attribute used for storing the execution start time. This attribute value is automatically stored by the execute() method.- See Also:
-
ATTRIBUTE_END_TIME
The attribute used for storing the execution end time. This attribute value is automatically stored by the execute() method.- See Also:
-
ATTRIBUTE_PROGRESS
The attribute used for storing the progress ratio. The progress value should be a double between 0.0 and 1.0, corresponding to the "percent complete" of the overall call. It is generally only safe to set this value for a top-level procedure, i.e. when the call stack height is one (1).- See Also:
-
ATTRIBUTE_USER
The attribute used for storing the user information.- See Also:
-
ATTRIBUTE_SOURCE
The attribute used for storing call source information.- See Also:
-
ATTRIBUTE_RESULT
The attribute used for storing the result data.- See Also:
-
ATTRIBUTE_ERROR
The attribute used for storing the error message.- See Also:
-
ATTRIBUTE_TRACE
The attribute used for storing the trace flag.- See Also:
-
ATTRIBUTE_LOG_BUFFER
The attribute used for storing the log string buffer.- See Also:
-
MAX_LOG_LENGTH
public static final int MAX_LOG_LENGTHThe maximum number of characters to store in the log buffer.- See Also:
-
-
Constructor Details
-
CallContext
Creates a new procedure call context.- Parameters:
storage
- the data storage to useenv
- the environment to uselibrary
- the procedure library to use
-
-
Method Details
-
getStorage
Returns the data storage used by this context.- Returns:
- the data storage used by this context
-
getEnvironment
Returns the connectivity environment used by this context.- Returns:
- the connectivity environment
-
getLibrary
Returns the procedure library used by this context.- Returns:
- the procedure library
-
getInterceptor
Returns the local procedure call interceptor. If no local interceptor has been set, the library procedure call interceptor will be returned instead.- Returns:
- the call interceptor to use
-
setInterceptor
Sets the local procedure call interceptor, overriding the default library procedure call interceptor for calls in this context.- Parameters:
i
- the interceptor to use
-
getAttribute
Returns a call attribute value.- Parameters:
name
- the attribute name- Returns:
- the call attribute value, or null if not defined
-
setAttribute
Sets a call attribute value.- Parameters:
name
- the attribute namevalue
- the attribute value
-
getCallStack
Returns the procedure call stack.- Returns:
- the procedure call stack
-
readPermission
Returns the permission required to read a path at the current call stack height. If the current call stack height is less or equal to the specified depth, a normal read permission is returned. Otherwise an internal permission is returned.- Parameters:
depth
- the max stack depth for read permission- Returns:
- the permission required for reading (read or internal)
- See Also:
-
checkAccess
Checks if the currently authenticated user has the specified access permission to a storage path.- Parameters:
path
- the object storage pathpermission
- the requested permission- Throws:
ProcedureException
- if the current user didn't have the requested access permission
-
checkInternalAccess
Checks if the currently authenticated user has internal access to a storage path.- Parameters:
path
- the object storage path- Throws:
ProcedureException
- if the current user didn't have internal access
-
checkReadAccess
Checks if the currently authenticated user has read access to a storage path.- Parameters:
path
- the object storage path- Throws:
ProcedureException
- if the current user didn't have read access
-
checkSearchAccess
Checks if the currently authenticated user has search access to a storage path.- Parameters:
path
- the object storage path- Throws:
ProcedureException
- if the current user didn't have search access
-
checkWriteAccess
Checks if the currently authenticated user has write access to a storage path.- Parameters:
path
- the object storage path- Throws:
ProcedureException
- if the current user didn't have write access
-
isInterrupted
public boolean isInterrupted()Checks if the call has been interrupted. Once a call has been interrupted the procedure call chain will be stopped as soon as possible. Any further procedure calls in this call context will terminate immediately with an error.- Returns:
- true if this call has been interrupted, or false otherwise
- See Also:
-
interrupt
public void interrupt()Interrupts the current procedure call. Once a call has been interrupted the procedure call chain will be stopped as soon as possible. Any further procedure calls in this call context will terminate immediately with an error.- See Also:
-
execute
Executes a procedure with the specified name and arguments. This is a convenience method for performing a procedure lookup and proper calls to reserve(), call() and releaseAll(). Before execution all required resources will be reserved, and once the execution terminates they will be released (if at the bottom of the call stack). The arguments must be specified in the same order as in the default bindings for the procedure.- Parameters:
name
- the procedure nameargs
- the call arguments- Returns:
- the result of the call, or null if the call produced no result
- Throws:
ProcedureException
- if the call execution caused an error
-
reserve
Deprecated, for removal: This API element is subject to removal in a future version.Replaced with org.rapidcontext.core.type.Procedure signature.Reserves all adapter connections needed for executing the specified procedure. The reservation will be forwarded to the current call interceptor. Any connection or procedure in the default procedure bindings will be reserved recursively in this call context.- Parameters:
proc
- the procedure definition- Throws:
ProcedureException
- if the connections couldn't be reserved
-
reserve
Reserves all adapter connections needed for executing the specified procedure. The reservation will be forwarded to the current call interceptor. Any connection or procedure in the default procedure bindings will be reserved recursively in this call context.- Parameters:
proc
- the procedure definition- Throws:
ProcedureException
- if the connections couldn't be reserved
-
releaseAll
public void releaseAll(boolean commit) Releases all currently reserved adapter connections. The release will be forwarded to the current call interceptor. Each reserved connection will either be committed or rolled back, depending on the commit flag.- Parameters:
commit
- the commit (or rollback) flag
-
call
@Deprecated(forRemoval=true) public Object call(Procedure proc, Object[] args) throws ProcedureException Deprecated, for removal: This API element is subject to removal in a future version.Replaced with org.rapidcontext.core.type.Procedure signature.Calls a procedure with the specified arguments. The call will be forwarded to the current call interceptor. The arguments must be specified in the same order as in the default bindings for the procedure. All the required arguments must be provided and all connections must already have been reserved. Use execute() when a procedure is to be called from outside a prepared call context.- Parameters:
proc
- the procedure definitionargs
- the call arguments- Returns:
- the call bindings
- Throws:
ProcedureException
- if the argument binding failed
-
call
Calls a procedure with the specified arguments. The call will be forwarded to the current call interceptor. The arguments must be specified in the same order as in the default bindings for the procedure. All the required arguments must be provided and all connections must already have been reserved. Use execute() when a procedure is to be called from outside a prepared call context.- Parameters:
proc
- the procedure definitionargs
- the call arguments- Returns:
- the call bindings
- Throws:
ProcedureException
- if the argument binding failed
-
call
@Deprecated(forRemoval=true) public Object call(Procedure proc, Bindings bindings) throws ProcedureException Deprecated, for removal: This API element is subject to removal in a future version.Replaced with org.rapidcontext.core.type.Procedure signature.Calls a procedure with the specified arguments. The call will be forwarded to the current call interceptor. All the required arguments must be provided and all connections must already have been reserved. Use execute() when a procedure is to be called from outside a prepared call context.- Parameters:
proc
- the procedure definitionbindings
- the bindings to use- Returns:
- the result of the call, or null if the call produced no result
- Throws:
ProcedureException
- if the call execution caused an error- See Also:
-
call
Calls a procedure with the specified arguments. The call will be forwarded to the current call interceptor. All the required arguments must be provided and all connections must already have been reserved. Use execute() when a procedure is to be called from outside a prepared call context.- Parameters:
proc
- the procedure definitionbindings
- the bindings to use- Returns:
- the result of the call, or null if the call produced no result
- Throws:
ProcedureException
- if the call execution caused an error- See Also:
-
connectionReserve
Reserves a connection channel. The reserved channel will be stored in this context until all channels are released.- Parameters:
id
- the connection identifierpermission
- the required permission level- Returns:
- the reserved connection channel
- Throws:
ProcedureException
- if the channel couldn't be reserved- See Also:
-
connectionReleaseAll
public void connectionReleaseAll(boolean commit) Releases all reserved adapter connections. The connections will either be committed or rolled back, depending on the commit flag.- Parameters:
commit
- the commit (or rollback) flag- See Also:
-
isTracing
public boolean isTracing()Checks if this call context has call trace logging enabled.- Returns:
- true if call trace logging is enabled, or false otherwise
-
log
Logs the specified message to the log if tracing is enabled.- Parameters:
message
- the message text
-
logCall
Logs the specified call to the log if tracing is enabled.- Parameters:
proc
- the procedure namebindings
- the procedure call bindings- Throws:
ProcedureException
- if the call logging caused an error
-
logCall
Logs the specified call to the log if tracing is enabled.- Parameters:
name
- the procedure or object methodargs
- the arguments, or null for none
-
logResponse
Logs the specified call response to the log if tracing is enabled.- Parameters:
obj
- the call response
-
logError
Logs the specified call error to the log if tracing is enabled.- Parameters:
e
- the exception to log
-