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

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

      public static BoxRuntime getInstance(Boolean debugMode, String configPath, String runtimeHome)
      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
      configPath - The path to the configuration file to load as overrides
      runtimeHome - The path to the runtime home directory
      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
    • hasInstance

      public static Boolean hasInstance()
      Check if the runtime has been started
      Returns:
      true if the runtime has been started
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • getGlobalServiceKeys

      public Key[] 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

      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
    • 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)
      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:
      context - The context to execute the source in
      source - A string of the statement to execute
    • 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
    • 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