Package ortus.boxlang.runtime
Class BoxRuntime
java.lang.Object
ortus.boxlang.runtime.BoxRuntime
- All Implemented Interfaces:
Closeable
,AutoCloseable
Represents the top level runtime container for box lang. Config, global scopes, mappings, threadpools, etc all go here.
All threads, requests, invocations, etc share this.
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
-------------------------------------------------------------------------- Constructor -------------------------------------------------------------------------- -
Method Summary
Modifier and TypeMethodDescriptionvoid
Announce an event with the providedIStruct
of data short-hand forgetInterceptorService()
.announce()void
Announce an event with the providedIStruct
of data short-hand forgetInterceptorService()
.announce()void
Announce an event with the providedIStruct
of data short-hand forgetInterceptorService()
.announce()void
close()
Closeable interface methodvoid
executeClass
(Class<IBoxRunnable> targetClass, String templatePath, IBoxContext context, String[] args) Execute a single class by executing it's main method, else throw an exceptionvoid
executeModule
(String module, String[] args) Execute a target module main methodexecuteSource
(InputStream sourceStream) Execute a source strings from an input streamexecuteSource
(InputStream sourceStream, IBoxContext context) This is our REPL (Read-Eval-Print-Loop) method that allows for interactive BoxLang executionexecuteSource
(String source) Execute a source stringexecuteSource
(String source, IBoxContext context) Execute a source stringexecuteSource
(String source, IBoxContext context, BoxSourceType type) Execute a source stringexecuteStatement
(String source) Execute a single statementexecuteStatement
(String source, IBoxContext context) Execute a single statement in a specific contextexecuteStatement
(BoxScript scriptRunnable, IBoxContext context) Execute a single statement in a specific contextvoid
executeTemplate
(String templatePath) Execute a single template in its own contextvoid
executeTemplate
(String templatePath, String[] args) Execute a single template in its own contextvoid
executeTemplate
(String templatePath, IBoxContext context) Execute a single template in an existing context.void
executeTemplate
(String templatePath, IBoxContext context, String[] args) Execute a single template in an existing context.void
executeTemplate
(URL templateURL) Execute a single template in its own context using a of the template to executionvoid
executeTemplate
(URL templateURL, IBoxContext context) Execute a single template in an existing context using a of the template to executionvoid
executeTemplate
(BoxTemplate template) Execute a single template in its own context using an already-loaded template runnablevoid
executeTemplate
(BoxTemplate template, IBoxContext context) Execute a single template in an existing context using an already-loaded template runnableGet the application serviceGet the async serviceGet the cache serviceGet the component serviceGet the configurationGet the datasource manager for this runtime.Get the function servicegetGlobalService
(Key name) Get a global service from the runtimeKey[]
Get the keys of all loaded global servicesstatic BoxRuntime
Get the singleton instance.static BoxRuntime
getInstance
(Boolean debugMode) Get the singleton instance.static BoxRuntime
getInstance
(Boolean debugMode, String configPath) Get the singleton instance.static BoxRuntime
getInstance
(Boolean debugMode, String configPath, String runtimeHome) Get the singleton instance.Get the interceptor serviceGet the module serviceGet the runtime contextGet the runtime file extensions registered in the runtimeGet the runtime home directoryGet runtime class loaderGet the scheduler serviceGet the start time of the runtimeGet a Struct of version information from the version.propertiesboolean
hasGlobalService
(Key name) Has a global service been setstatic Boolean
Check if the runtime has been startedVerifies if the runtime is in debug modeboolean
Check if the runtime is in jar mode or notvoid
printSourceAST
(String source) Parse source string and print AST as JSONvoid
printTranspiledJavaCode
(String filePath) Print the transpiled Java code for a given source file.putGlobalService
(Key name, IService service) Put a global service into the runtime If a service for this key was already set, return the original value.void
registerFileExtensions
(String... extensions) Register new file extensions with the runtimeremoveGlobalService
(Key name) Remove a global service from the runtimevoid
shutdown()
Shut down the runtime gracefullyvoid
Shut down the runtime with the option to force itvoid
Switch the runtime to generate bytecode directly via ASMvoid
Switch the runtime to generate java source and compile via the JDK
-
Field Details
-
timerUtil
The timer utility class
-
-
Constructor Details
-
BoxRuntime
protected BoxRuntime()-------------------------------------------------------------------------- Constructor --------------------------------------------------------------------------
-
-
Method Details
-
getInstance
Get the singleton instance. This method is in charge of starting the runtime if it has not been started yet. This can be null if the runtime has not been started yet.- Parameters:
debugMode
- true if the runtime should be started in debug mode- Returns:
- A BoxRuntime instance
-
getInstance
Get the singleton instance. This method is in charge of starting the runtime if it has not been started yet. This can be null if the runtime has not been started yet.- Parameters:
debugMode
- true if the runtime should be started in debug modeconfigPath
- The path to the configuration file to load as overrides- Returns:
- A BoxRuntime instance
-
getInstance
Get the singleton instance. This method is in charge of starting the runtime if it has not been started yet. This can be null if the runtime has not been started yet.- Parameters:
debugMode
- true if the runtime should be started in debug modeconfigPath
- The path to the configuration file to load as overridesruntimeHome
- The path to the runtime home directory- Returns:
- A BoxRuntime instance
-
getInstance
Get the singleton instance. This can be null if the runtime has not been started yet.- Returns:
- BoxRuntime
-
hasInstance
Check if the runtime has been started- Returns:
- true if the runtime has been started
-
getAsyncService
Get the async service- Returns:
AsyncService
or null if the runtime has not started
-
getCacheService
Get the cache service- Returns:
CacheService
or null if the runtime has not started
-
getSchedulerService
Get the scheduler service- Returns:
SchedulerService
or null if the runtime has not started
-
getFunctionService
Get the function service- Returns:
FunctionService
or null if the runtime has not started
-
getComponentService
Get the component service- Returns:
ComponentService
or null if the runtime has not started
-
getInterceptorService
Get the interceptor service- Returns:
InterceptorService
or null if the runtime has not started
-
getApplicationService
Get the application service- Returns:
ApplicationService
or null if the runtime has not started
-
getModuleService
Get the module service- Returns:
ModuleService
or null if the runtime has not started
-
getDataSourceService
Get the datasource manager for this runtime.- Returns:
DatasourceService
or null if the runtime has not started
-
getRuntimeLoader
Get runtime class loader- Returns:
DynamicClassLoader
or null if the runtime has not started
-
getRuntimeFileExtensions
Get the runtime file extensions registered in the runtime- Returns:
- A set of file extensions
-
registerFileExtensions
Register new file extensions with the runtime- Parameters:
extensions
- A list of extensions to incorporate into the runtime
-
getRuntimeContext
Get the runtime context- Returns:
- The runtime context
-
getConfiguration
Get the configuration- Returns:
Configuration
or null if the runtime has not started
-
getStartTime
Get the start time of the runtime- Returns:
- the runtime start time, or null if not started
-
getRuntimeHome
Get the runtime home directory- Returns:
- the runtime home directory, or null if not started
-
inDebugMode
Verifies if the runtime is in debug mode- Returns:
- true if the runtime is in debug mode, or null if not started
-
inJarMode
public boolean inJarMode()Check if the runtime is in jar mode or not- Returns:
- true if in jar mode, false otherwise
-
announce
Announce an event with the providedIStruct
of data short-hand forgetInterceptorService()
.announce()- Parameters:
state
- The Key state to announcedata
- The data to announce
-
announce
Announce an event with the providedIStruct
of data short-hand forgetInterceptorService()
.announce()- Parameters:
state
- The state to announcedata
- The data to announce
-
announce
Announce an event with the providedIStruct
of data short-hand forgetInterceptorService()
.announce()- Parameters:
state
- The Key state to announcedata
- The data to announce
-
shutdown
public void shutdown()Shut down the runtime gracefully -
close
public void close()Closeable interface method- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
shutdown
Shut down the runtime with the option to force it -
getGlobalService
Get a global service from the runtime- Parameters:
name
- The name of the service to get- Returns:
- The service or null if not found
-
hasGlobalService
Has a global service been set- Parameters:
name
- The name of the service to check- Returns:
- true if the service exists
-
putGlobalService
Put a global service into the runtime If a service for this key was already set, return the original value.- Parameters:
name
- The name of the service to setservice
- The service to set
-
removeGlobalService
Remove a global service from the runtime- Parameters:
name
- The name of the service to remove- Returns:
- The service that was removed, or null if it was not found
-
getGlobalServiceKeys
Get the keys of all loaded global services -
useJavaBoxpiler
public void useJavaBoxpiler()Switch the runtime to generate java source and compile via the JDK -
useASMBoxPiler
public void useASMBoxPiler()Switch the runtime to generate bytecode directly via ASM -
getVersionInfo
Get a Struct of version information from the version.properties -
executeTemplate
Execute a single template in its own context- Parameters:
templatePath
- The absolute path to the template to execute
-
executeTemplate
Execute a single template in its own context- Parameters:
templatePath
- The absolute path to the template to executeargs
- The arguments to pass to the template
-
executeTemplate
Execute a single template in an existing context. This can be a template or a class accoding to its extensionIf it's a template the args will be stored in the request scope If it's a class the args will be passed to the main method
- Parameters:
templatePath
- The absolute path to the template to executecontext
- The context to execute the template in
-
executeTemplate
Execute a single template in an existing context. This can be a template or a class accoding to its extensionIf it's a template the args will be stored in the request scope If it's a class the args will be passed to the main method
- Parameters:
templatePath
- The absolute path to the template to executecontext
- The context to execute the template inargs
- The arguments to pass to the template
-
executeTemplate
Execute a single template in an existing context using a of the template to execution- Parameters:
templateURL
- A URL location to executioncontext
- The context to execute the template in
-
executeTemplate
Execute a single template in its own context using a of the template to execution- Parameters:
templateURL
- A URL location to execution
-
executeTemplate
Execute a single template in its own context using an already-loaded template runnable- Parameters:
template
- A template to execute
-
executeModule
Execute a target module main method- Parameters:
module
- The module to executeargs
- The arguments to pass to the module- Throws:
BoxRuntimeException
- if the module does not existBoxRuntimeException
- If the module is not executable, meaning it doesn't have a main method
-
executeClass
public void executeClass(Class<IBoxRunnable> targetClass, String templatePath, IBoxContext context, String[] args) Execute a single class by executing it's main method, else throw an exception- Parameters:
targetClass
- The class to executetemplatePath
- The path to the templatecontext
- The context to execute the class inargs
- The array of arguments to pass to the main method
-
executeTemplate
Execute a single template in an existing context using an already-loaded template runnable- Parameters:
template
- A template to executecontext
- The context to execute the template in
-
executeStatement
Execute a single statement- Parameters:
source
- A string of the statement to execute
-
executeStatement
Execute a single statement in a specific context- Parameters:
source
- A string of the statement to executecontext
- The context to execute the source in
-
executeStatement
Execute a single statement in a specific context- Parameters:
context
- The context to execute the source insource
- A string of the statement to execute
-
executeSource
Execute a source string- Parameters:
source
- A string of source to execute- Returns:
- The result of the execution
-
executeSource
Execute a source string- Parameters:
source
- A string of source to executecontext
- The context to execute the source in- Returns:
- The result of the execution
-
executeSource
Execute a source strings from an input stream- Parameters:
sourceStream
- An input stream to read- Returns:
- The result of the execution
-
executeSource
Execute a source string- Parameters:
source
- A string of source to executecontext
- The context to execute the source in
-
executeSource
This is our REPL (Read-Eval-Print-Loop) method that allows for interactive BoxLang execution- Parameters:
sourceStream
- An input stream to readcontext
- The context to execute the source in
-
printTranspiledJavaCode
Print the transpiled Java code for a given source file. This is useful for debugging and understanding how the BoxLang code is transpiled to Java.- Parameters:
filePath
- The path to the source file
-
printSourceAST
Parse source string and print AST as JSON- Parameters:
source
- A string of source to parse and print AST for
-