Class BoxRuntime
- All Implemented Interfaces:
Closeable,AutoCloseable
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected-------------------------------------------------------------------------- Constructor -------------------------------------------------------------------------- -
Method Summary
Modifier and TypeMethodDescriptionvoidAnnounce an event with the providedIStructof data short-hand forgetInterceptorService().announce()voidAnnounce an event with the providedIStructof data short-hand forgetInterceptorService().announce()voidAnnounce an event with the providedIStructof data short-hand forgetInterceptorService().announce()voidclose()Closeable interface methodvoidexecuteClass(Class<IBoxRunnable> targetClass, String templatePath, IBoxContext context, String[] args) Execute a single class by executing it's main method, else throw an exceptionvoidexecuteModule(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(String source, IBoxContext context, BoxSourceType type) Execute a single statement in a specific contextexecuteStatement(BoxScript scriptRunnable, IBoxContext context) Execute a single statement in a specific contextvoidexecuteTemplate(String templatePath) Execute a single template in its own contextvoidexecuteTemplate(String templatePath, String[] args) Execute a single template in its own contextvoidexecuteTemplate(String templatePath, IBoxContext context) Execute a single template in an existing context.voidexecuteTemplate(String templatePath, IBoxContext context, String[] args) Execute a single template in an existing context.voidexecuteTemplate(URL templateURL) Execute a single template in its own context using a of the template to executionvoidexecuteTemplate(URL templateURL, IBoxContext context) Execute a single template in an existing context using a of the template to executionvoidexecuteTemplate(BoxTemplate template) Execute a single template in its own context using an already-loaded template runnablevoidexecuteTemplate(BoxTemplate template, String templatePath, IBoxContext context) Execute a single template in an existing context using an already-loaded template runnablevoidexecuteTemplate(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 global class locator serviceGet the CLI Options that were used to start the runtime.Get the component serviceGet the configurationGet the datasource manager for this runtime.Get the function servicegetGlobalService(String name) Alias to use stringsgetGlobalService(Key name) Get a global service from the runtimeKey[]Get the keys of all loaded global servicesstatic BoxRuntimeGet the singleton instance.static BoxRuntimegetInstance(Boolean debugMode) Get or startup a BoxLang Runtime instance.static BoxRuntimegetInstance(Boolean debugMode, String configPath) Get or startup a BoxLang Runtime instance.static BoxRuntimegetInstance(Boolean debugMode, String configPath, String runtimeHome) Get or startup a BoxLang Runtime instance.static BoxRuntimegetInstance(Boolean debugMode, String configPath, String runtimeHome, CLIOptions options) Get or startup a BoxLang Runtime instance.static BoxRuntimegetInstance(String configPath, String runtimeHome) Get or startup a BoxLang Runtime instance.static BoxRuntimegetInstance(CLIOptions options) Get or startup a BoxLang Runtime instance.Get the interceptor serviceGet the logging 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.propertiesbooleanhasGlobalService(String name) Alias to use stringsbooleanhasGlobalService(Key name) Has a global service been setstatic BooleanCheck if the runtime has been startedbooleanCheck if the runtime is in CLI mode or notVerifies if the runtime is in debug modebooleanCheck if the runtime is in jar mode or notParse a script file This is a passthrough to the Boxpiler parse methodParse a script string expression This is a passthrough to the Boxpiler parse method Defaults to BoxScript source type.parse(String code, BoxSourceType sourceType) Parse a script string This is a passthrough to the Boxpiler parse methodvoidprintSourceAST(String source) Parse source string and print AST as JSONvoidprintTranspiledJavaCode(String filePath) Print the transpiled Java code for a given source file.putGlobalService(String name, IService service) Alias to use stringsputGlobalService(Key name, IService service) Put a global service into the runtime If a service for this key was already set, return the original value.voidregisterFileExtensions(String... extensions) Register new file extensions with the runtimeremoveGlobalService(String name) Alias to use stringsremoveGlobalService(Key name) Remove a global service from the runtimevoidshutdown()Shut down the runtime gracefullyvoidShut down the runtime with the option to force it
-
Field Details
-
timerUtil
The timer utility class
-
-
Constructor Details
-
BoxRuntime
protected BoxRuntime()-------------------------------------------------------------------------- Constructor --------------------------------------------------------------------------
-
-
Method Details
-
getInstance
Get or startup a BoxLang Runtime instance.A very simple variation for NON CLI applications using just the debug mode.
- Parameters:
debugMode- True if the runtime should be started in debug mode- Returns:
- A BoxRuntime instance
-
getInstance
Get or startup a BoxLang Runtime instance.Another variation for NON-cli applications using just the debug mode and a config override.
- 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 or startup a BoxLang Runtime instance.This is for NON-cli applications using just a runtime home directory and config path. The debug mode will be identified by ENV or configuration.
- Parameters:
configPath- The path to the configuration file to load as overridesruntimeHome- The path to the runtime home directory where all the runtime assets are stored- Returns:
- A BoxRuntime instance
-
getInstance
Get or startup a BoxLang Runtime instance.This method is used exclusively to start a CLI runtime instance.
- Parameters:
options- The CLI Options that were used to start the runtime or null if not started via CLI- Returns:
- A BoxRuntime instance
-
getInstance
Get or startup a BoxLang Runtime instance.This variation doesn't use the CLIOptions as most likely this method is used by NON-CLI applications.
- 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 where all the runtime assets are stored- Returns:
- A BoxRuntime instance
-
getInstance
public static BoxRuntime getInstance(Boolean debugMode, String configPath, String runtimeHome, CLIOptions options) Get or startup a BoxLang Runtime instance.This method uses all the possible parameters to start the runtime.
- 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 where all the runtime assets are storedoptions- The CLI Options that were used to start the runtime or null if not started via CLI- Returns:
- A BoxRuntime instance
-
getInstance
Get the singleton instance. This can be null if the runtime has not been started yet.- Returns:
- BoxRuntime instance or null if not started
-
hasInstance
Check if the runtime has been started- Returns:
- true if the runtime has been started
-
getClassLocator
Get the global class locator service -
getAsyncService
Get the async service- Returns:
AsyncServiceor null if the runtime has not started
-
getCacheService
Get the cache service- Returns:
CacheServiceor null if the runtime has not started
-
getSchedulerService
Get the scheduler service- Returns:
SchedulerServiceor null if the runtime has not started
-
getFunctionService
Get the function service- Returns:
FunctionServiceor null if the runtime has not started
-
getComponentService
Get the component service- Returns:
ComponentServiceor null if the runtime has not started
-
getInterceptorService
Get the interceptor service- Returns:
InterceptorServiceor null if the runtime has not started
-
getApplicationService
Get the application service- Returns:
ApplicationServiceor null if the runtime has not started
-
getModuleService
Get the module service- Returns:
ModuleServiceor null if the runtime has not started
-
getDataSourceService
Get the datasource manager for this runtime.- Returns:
DatasourceServiceor null if the runtime has not started
-
getLoggingService
Get the logging service -
getRuntimeLoader
Get runtime class loader- Returns:
DynamicClassLoaderor 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:
Configurationor 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
-
getCliOptions
Get the CLI Options that were used to start the runtime. This can be null if not started via CLI- Returns:
- The CLI Options or null if not started via CLI
-
inCLIMode
public boolean inCLIMode()Check if the runtime is in CLI mode or not- Returns:
- true if in CLI mode, false otherwise
-
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 providedIStructof data short-hand forgetInterceptorService().announce()- Parameters:
state- The Key state to announcedata- The data to announce
-
announce
Announce an event with the providedIStructof data short-hand forgetInterceptorService().announce()- Parameters:
state- The state to announcedata- The data to announce
-
announce
Announce an event with the providedIStructof 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:
closein interfaceAutoCloseable- Specified by:
closein 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
-
getGlobalService
Alias to use strings -
hasGlobalService
Has a global service been set- Parameters:
name- The name of the service to check- Returns:
- true if the service exists
-
hasGlobalService
Alias to use strings -
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
-
putGlobalService
Alias to use strings -
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
-
removeGlobalService
Alias to use strings -
getGlobalServiceKeys
Get the keys of all loaded global services -
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
-
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 intype- The type of source 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:
scriptRunnable- A runnable boxlang script to executecontext- The context to execute the source in- Returns:
- The result of the execution, if any, or null
-
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 intype- The type of source to execute. Available options are: BOXSCRIPT, BOXTEMPLATE, CFSCRIPT, CFTEMPLATE- Returns:
- The result of the execution, if any, or null
-
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
-
parse
Parse a script file This is a passthrough to the Boxpiler parse method- Parameters:
file- source file to parse- Returns:
- a ParsingResult containing the AST with a BoxScript as root and the list of errors (if any)
- Throws:
IOException- See Also:
-
parse
Parse a script string This is a passthrough to the Boxpiler parse method- Parameters:
code- source of the expression to parsesourceType- the type of source to parse. Available options are: BOXSCRIPT, BOXTEMPLATE, CFSCRIPT, CFTEMPLATE- Returns:
- a ParsingResult containing the AST with a BoxExpr as root and the list of errors (if any)
- Throws:
IOException- See Also:
-
parse
Parse a script string expression This is a passthrough to the Boxpiler parse method Defaults to BoxScript source type. If you want to parse another type, use the other method- Parameters:
code- source of the expression to parse- Returns:
- a ParsingResult containing the AST with a BoxExpr as root and the list of errors (if any)
- Throws:
IOException- See Also:
-