Class BoxRuntime

java.lang.Object
ortus.boxlang.runtime.BoxRuntime
All Implemented Interfaces:
Closeable, AutoCloseable

public class BoxRuntime extends Object implements Closeable
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 Details

    • timerUtil

      public static final Timer timerUtil
      The timer utility class
  • Constructor Details

    • BoxRuntime

      protected BoxRuntime()
      -------------------------------------------------------------------------- Constructor --------------------------------------------------------------------------
  • Method Details

    • getInstance

      public static BoxRuntime getInstance(Boolean debugMode)
      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

      public static BoxRuntime getInstance(Boolean debugMode, String configPath)
      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 mode
      configPath - The path to the configuration file to load as overrides
      Returns:
      A BoxRuntime instance
    • getInstance

      public static BoxRuntime getInstance(String configPath, String runtimeHome)
      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 overrides
      runtimeHome - The path to the runtime home directory where all the runtime assets are stored
      Returns:
      A BoxRuntime instance
    • getInstance

      public static BoxRuntime getInstance(CLIOptions options)
      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

      public static BoxRuntime getInstance(Boolean debugMode, String configPath, String runtimeHome)
      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 mode
      configPath - The path to the configuration file to load as overrides
      runtimeHome - 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 mode
      configPath - The path to the configuration file to load as overrides
      runtimeHome - The path to the runtime home directory where all the runtime assets are stored
      options - The CLI Options that were used to start the runtime or null if not started via CLI
      Returns:
      A BoxRuntime instance
    • getInstance

      public static BoxRuntime 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

      public static Boolean hasInstance()
      Check if the runtime has been started
      Returns:
      true if the runtime has been started
    • getClassLocator

      public ClassLocator getClassLocator()
      Get the global class locator service
    • getAsyncService

      public AsyncService getAsyncService()
      Get the async service
      Returns:
      AsyncService or null if the runtime has not started
    • getCacheService

      public CacheService getCacheService()
      Get the cache service
      Returns:
      CacheService or null if the runtime has not started
    • getSchedulerService

      public SchedulerService getSchedulerService()
      Get the scheduler service
      Returns:
      SchedulerService or null if the runtime has not started
    • getFunctionService

      public FunctionService getFunctionService()
      Get the function service
      Returns:
      FunctionService or null if the runtime has not started
    • getComponentService

      public ComponentService getComponentService()
      Get the component service
      Returns:
      ComponentService or null if the runtime has not started
    • getInterceptorService

      public InterceptorService getInterceptorService()
      Get the interceptor service
      Returns:
      InterceptorService or null if the runtime has not started
    • getApplicationService

      public ApplicationService getApplicationService()
      Get the application service
      Returns:
      ApplicationService or null if the runtime has not started
    • getModuleService

      public ModuleService getModuleService()
      Get the module service
      Returns:
      ModuleService or null if the runtime has not started
    • getDataSourceService

      public DatasourceService getDataSourceService()
      Get the datasource manager for this runtime.
      Returns:
      DatasourceService or null if the runtime has not started
    • getLoggingService

      public LoggingService getLoggingService()
      Get the logging service
    • getRuntimeLoader

      public DynamicClassLoader getRuntimeLoader()
      Get runtime class loader
      Returns:
      DynamicClassLoader or null if the runtime has not started
    • getRuntimeFileExtensions

      public Set<String> getRuntimeFileExtensions()
      Get the runtime file extensions registered in the runtime
      Returns:
      A set of file extensions
    • registerFileExtensions

      public void registerFileExtensions(String... extensions)
      Register new file extensions with the runtime
      Parameters:
      extensions - A list of extensions to incorporate into the runtime
    • getRuntimeContext

      public IBoxContext getRuntimeContext()
      Get the runtime context
      Returns:
      The runtime context
    • getConfiguration

      public Configuration getConfiguration()
      Get the configuration
      Returns:
      Configuration or null if the runtime has not started
    • getStartTime

      public Instant getStartTime()
      Get the start time of the runtime
      Returns:
      the runtime start time, or null if not started
    • getRuntimeHome

      public Path getRuntimeHome()
      Get the runtime home directory
      Returns:
      the runtime home directory, or null if not started
    • inDebugMode

      public Boolean inDebugMode()
      Verifies if the runtime is in debug mode
      Returns:
      true if the runtime is in debug mode, or null if not started
    • getCliOptions

      public CLIOptions 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

      public void announce(Key state, IStruct data)
      Announce an event with the provided IStruct of data short-hand for getInterceptorService().announce()
      Parameters:
      state - The Key state to announce
      data - The data to announce
    • announce

      public void announce(String state, IStruct data)
      Announce an event with the provided IStruct of data short-hand for getInterceptorService().announce()
      Parameters:
      state - The state to announce
      data - The data to announce
    • announce

      public void announce(BoxEvent state, IStruct data)
      Announce an event with the provided IStruct of data short-hand for getInterceptorService().announce()
      Parameters:
      state - The Key state to announce
      data - The data to announce
    • shutdown

      public void shutdown()
      Shut down the runtime gracefully
    • close

      public void close()
      Closeable interface method
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • shutdown

      public void shutdown(Boolean force)
      Shut down the runtime with the option to force it
    • getGlobalService

      public IService getGlobalService(Key name)
      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

      public IService getGlobalService(String name)
      Alias to use strings
    • hasGlobalService

      public boolean hasGlobalService(Key name)
      Has a global service been set
      Parameters:
      name - The name of the service to check
      Returns:
      true if the service exists
    • hasGlobalService

      public boolean hasGlobalService(String name)
      Alias to use strings
    • putGlobalService

      public IService 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.
      Parameters:
      name - The name of the service to set
      service - The service to set
    • putGlobalService

      public IService putGlobalService(String name, IService service)
      Alias to use strings
    • removeGlobalService

      public IService removeGlobalService(Key name)
      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

      public IService removeGlobalService(String name)
      Alias to use strings
    • getGlobalServiceKeys

      public Key[] getGlobalServiceKeys()
      Get the keys of all loaded global services
    • getVersionInfo

      public IStruct getVersionInfo()
      Get a Struct of version information from the version.properties
    • executeTemplate

      public void executeTemplate(String templatePath)
      Execute a single template in its own context
      Parameters:
      templatePath - The absolute path to the template to execute
    • executeTemplate

      public void executeTemplate(String templatePath, String[] args)
      Execute a single template in its own context
      Parameters:
      templatePath - The absolute path to the template to execute
      args - The arguments to pass to the template
    • executeTemplate

      public void executeTemplate(String templatePath, IBoxContext context)
      Execute a single template in an existing context. This can be a template or a class accoding to its extension

      If 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 execute
      context - The context to execute the template in
    • executeTemplate

      public void executeTemplate(String templatePath, IBoxContext context, String[] args)
      Execute a single template in an existing context. This can be a template or a class accoding to its extension

      If 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 execute
      context - The context to execute the template in
      args - The arguments to pass to the template
    • executeTemplate

      public void executeTemplate(URL templateURL, IBoxContext context)
      Execute a single template in an existing context using a of the template to execution
      Parameters:
      templateURL - A URL location to execution
      context - The context to execute the template in
    • executeTemplate

      public void executeTemplate(URL templateURL)
      Execute a single template in its own context using a of the template to execution
      Parameters:
      templateURL - A URL location to execution
    • executeTemplate

      public void executeTemplate(BoxTemplate template)
      Execute a single template in its own context using an already-loaded template runnable
      Parameters:
      template - A template to execute
    • executeModule

      public void executeModule(String module, String[] args)
      Execute a target module main method
      Parameters:
      module - The module to execute
      args - The arguments to pass to the module
      Throws:
      BoxRuntimeException - if the module does not exist
      BoxRuntimeException - 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 execute
      templatePath - The path to the template
      context - The context to execute the class in
      args - The array of arguments to pass to the main method
    • executeTemplate

      public void executeTemplate(BoxTemplate template, IBoxContext context)
      Execute a single template in an existing context using an already-loaded template runnable
      Parameters:
      template - A template to execute
      context - The context to execute the template in
    • executeTemplate

      public void executeTemplate(BoxTemplate template, String templatePath, IBoxContext context)
      Execute a single template in an existing context using an already-loaded template runnable
      Parameters:
      template - A template to execute
      context - The context to execute the template in
    • executeStatement

      public Object executeStatement(String source)
      Execute a single statement
      Parameters:
      source - A string of the statement to execute
    • executeStatement

      public Object executeStatement(String source, IBoxContext context, BoxSourceType type)
      Execute a single statement in a specific context
      Parameters:
      source - A string of the statement to execute
      context - The context to execute the source in
      type - The type of source to execute
    • executeStatement

      public Object executeStatement(String source, IBoxContext context)
      Execute a single statement in a specific context
      Parameters:
      source - A string of the statement to execute
      context - The context to execute the source in
    • executeStatement

      public Object executeStatement(BoxScript scriptRunnable, IBoxContext context)
      Execute a single statement in a specific context
      Parameters:
      scriptRunnable - A runnable boxlang script to execute
      context - The context to execute the source in
      Returns:
      The result of the execution, if any, or null
    • executeSource

      public Object executeSource(String source)
      Execute a source string
      Parameters:
      source - A string of source to execute
      Returns:
      The result of the execution
    • executeSource

      public Object executeSource(String source, IBoxContext context)
      Execute a source string
      Parameters:
      source - A string of source to execute
      context - The context to execute the source in
      Returns:
      The result of the execution
    • executeSource

      public Object executeSource(InputStream sourceStream)
      Execute a source strings from an input stream
      Parameters:
      sourceStream - An input stream to read
      Returns:
      The result of the execution
    • executeSource

      public Object executeSource(String source, IBoxContext context, BoxSourceType type)
      Execute a source string
      Parameters:
      source - A string of source to execute
      context - The context to execute the source in
      type - The type of source to execute. Available options are: BOXSCRIPT, BOXTEMPLATE, CFSCRIPT, CFTEMPLATE
      Returns:
      The result of the execution, if any, or null
    • executeSource

      public Object executeSource(InputStream sourceStream, IBoxContext context)
      This is our REPL (Read-Eval-Print-Loop) method that allows for interactive BoxLang execution
      Parameters:
      sourceStream - An input stream to read
      context - The context to execute the source in
    • printTranspiledJavaCode

      public void printTranspiledJavaCode(String filePath)
      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

      public void printSourceAST(String source)
      Parse source string and print AST as JSON
      Parameters:
      source - A string of source to parse and print AST for
    • parse

      public ParsingResult parse(File file)
      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

      public ParsingResult parse(String code, BoxSourceType sourceType)
      Parse a script string This is a passthrough to the Boxpiler parse method
      Parameters:
      code - source of the expression to parse
      sourceType - 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

      public ParsingResult parse(String code)
      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: