Class RexxEngine

java.lang.Object
org.apache.bsf.util.BSFEngineImpl
org.rexxla.bsf.engines.rexx.RexxEngine
All Implemented Interfaces:
PropertyChangeListener, EventListener, org.apache.bsf.BSFEngine

public class RexxEngine extends org.apache.bsf.util.BSFEngineImpl
This class manages the calls from Java via JNI to Open Object Rexx (ooRexx).
------------------------ Apache Version 2.0 license -------------------------
    Copyright (C) 2001-2025 Rony G. Flatscher

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
 ----------------------------------------------------------------------------- 
Version:
850, 20250827
Author:
Rony G. Flatscher (WU-Wien/Wirtschaftsuniversität Wien, http://www.wu-wien.ac.at/english)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
    Will be set to true, if terminate() used JNI to successfully terminate the Rexx interpreter instance.
    protected boolean
    If terminate() was invoked, then this instance must not be used anymore.
    protected long
     
    protected static String
    The PARSE VERSION string of the currently ooRexx interpreter in use.
    static final String
    Version string indicating version of this class (majorVersion*100+minorVersion concatenated with a dot and the sorted date of last change.

    Fields inherited from class org.apache.bsf.util.BSFEngineImpl

    classLoader, classPath, declaredBeans, lang, mgr, tempDir
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    apply(String source, int lineNo, int columnNo, Object oscript, Vector vArgNames, Vector vArgs)
    Applies (evaluates) a piece of Rexx code (can be a whole program as well) with Java-supplied arguments and returns the result.
    call(Object object, String name, Object[] args)
    Calls (executes) a Rexx program which code has been supplied before via an invocation of "apply()", "exec()" or "eval()" with the Java-supplied arguments and returns the result.
    call(Object object, String name, Object[] args, Object scope)
    Call version that allows for supplying a Rexx class serving as the scope for the method invocation (new in ooRexx 5.0, cf.
    call(RexxProxy proxy, Object javaObject, String methodName, String methodDescriptor, Object[] args)
    Allows forwarding a messages to a RexxProxy using the supplied methodName the supplied arguments, if any.
    call(RexxProxy proxy, Method methodObject, Object[] args)
    Allows forwarding a messages to a RexxProxy using the method name of the supplied methodObject object with the supplied arguments, if any.
    void
    declareBean(org.apache.bsf.BSFDeclaredBean bean)
    Saves the supplied bean in engineDeclaredBeans which will be looked up by RexxAndJava.lookupBean() if a bean with the supplied name is not present in RexxAndJava's registry.
    eval(String source, int lineNo, int columnNo, Object oscript)
    Evaluates (executes) a piece of Rexx code (can be a whole program as well) without any Java-supplied arguments and returns the result.
    Getter method.
    Get the ooRexx .environment directory.
    long
    Returns the identifier of this RexxEngine.
    long
    (Copied from the ooRexx rexxpg.pdf documentation) "Returns the version of the interpreter.
    long
    (Copied from the ooRexx rexxpg.pdf documentation) "Returns the language level of the interpreter.
    static String
    Getter method.
    Get the ooRexx .local directory.
    Get the ooRexx .nil object.
    boolean
    Returns the current value of resetLocalBeforeTerminate
    static boolean
    Returns the current value of resetLocalBeforeTerminateDefault
    Getter method.
    org.rexxla.bsf.engines.rexx.RexxAndJava
    Returns the RexxAndJava instance that is used for interfacing with Rexx.
    static String
    Returns the string indicating which major ooRexx version and compilation date fixed the Terminate() problem.
    boolean
    Returns the current value of TerminateOnSeparateThread
    static boolean
    Returns the current value of TerminateOnSeparateThreadDefault
    void
    Halt (raise the HALT condition) all Rexx threads of this engine's peer Rexx interperter instance (using the new ooRExx 4.0 APIs).
    int
    halt(String tid)
    Allow halting an individual Rexx thread (raising the HALT condition) having the given thread ID.
    void
    initialize(org.apache.bsf.BSFManager mgr, String lang, Vector declaredBeans)
    Initializes the Rexx engine and causes the external functions 'BSF' and 'BSFPollEvents' to be registered with the Rexx interpreter.
    boolean
    Returns the current value of resetLocalBeforeTerminate
    static boolean
    Returns the current value of resetLocalBeforeTerminateDefault
    boolean
    Getter method for field bTerminated.
    boolean
    Returns the current value of TerminateOnSeparateThread
    static boolean
    Returns the current value of TerminateOnSeparateThreadDefault
    protected static boolean
    Determines whether the ooRexx version string indicates an interpretr that has Terminate() fixed.
    lookupBean(String beanName)
    Allow lookup of BSFRegistry entries.
    procEnvironment(int t, String n, String v)
     
    This method registers an object with the given beanName that gets created automatically in the BSF registry, if not registered yet.
    registerBean(String beanName, Object object)
    This method registers an object with the given beanName with the BSF registry, if not registered yet.
    protected void
    Setter method.
    protected void
    setId(long newValue)
    Allows to set the id value which will be used starting with BSF4ooReex850 as it became possible to get the ooRexx Rexx interpreter identifier using .context~interpreter.
    void
    setResetLocalBeforeTerminate(boolean newValue)
    Determines whether RexxEngine.terminate() executes on the current thread or on a separate thread.
    static void
    Determines whether RexxEngine.terminate() executes on the current thread (default) or on a separate thread.
    static void
    Allows to set the string indicating which major ooRexx version and compilation date fixed the Terminate() problem.
    void
    setTerminateOnSeparateThread(boolean newValue)
    Determines whether RexxEngine.terminate() executes on the current thread or on a separate thread.
    static void
    Determines whether RexxEngine.terminate() executes on the current thread (default) or on a separate thread.
    void
    Waits until all Rexx threads of this engine's Rexx interpreter instance peer have terminated (using the new ooRExx 4.0 APIs); this method must be called from the same thread that created the Rexx interpreter instance (i.e.
    void
    undeclareBean(org.apache.bsf.BSFDeclaredBean bean)
    Removes the supplied bean from engineDeclaredBeans.
    boolean
    This method allows for unregistering Beans, taking into account reference counters.

    Methods inherited from class org.apache.bsf.util.BSFEngineImpl

    compileApply, compileExpr, compileScript, exec, iexec, propertyChange

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • version

      public static final String version
      Version string indicating version of this class (majorVersion*100+minorVersion concatenated with a dot and the sorted date of last change.
      See Also:
    • bTerminated

      protected boolean bTerminated
      If terminate() was invoked, then this instance must not be used anymore.
    • bJNITerminated

      protected boolean bJNITerminated
      Will be set to true, if terminate() used JNI to successfully terminate the Rexx interpreter instance.
      Since:
      2013-06-25
    • languageVersionString

      protected static String languageVersionString
      The PARSE VERSION string of the currently ooRexx interpreter in use.
    • id

      protected long id
  • Constructor Details

    • RexxEngine

      public RexxEngine()
  • Method Details

    • isTerminated

      public boolean isTerminated()
      Getter method for field bTerminated.
      Returns:
      true, if Rexx engine got successfully terminated, false
    • getTerminateFixed

      public static String getTerminateFixed()
      Returns the string indicating which major ooRexx version and compilation date fixed the Terminate() problem.
      Returns:
      current string
    • setTerminateFixed

      public static void setTerminateFixed(String newValue)
      Allows to set the string indicating which major ooRexx version and compilation date fixed the Terminate() problem.
      Parameters:
      newValue - a string consisting of the major ooRexx version, a white space and a compilation date
    • setTerminateOnSeparateThreadDefault

      public static void setTerminateOnSeparateThreadDefault(boolean newValue)
      Determines whether RexxEngine.terminate() executes on the current thread (default) or on a separate thread. ooRexx 5 with RFE 806. fixed a memory leak for the price of abmysal performance (appr. a slow down of 50x).
      Parameters:
      newValue -
    • isTerminateOnSeparateThreadDefault

      public static boolean isTerminateOnSeparateThreadDefault()
      Returns the current value of TerminateOnSeparateThreadDefault
      Returns:
      current setting
    • getTerminateOnSeparateThreadDefault

      public static boolean getTerminateOnSeparateThreadDefault()
      Returns the current value of TerminateOnSeparateThreadDefault
      Returns:
      current setting
    • setTerminateOnSeparateThread

      public void setTerminateOnSeparateThread(boolean newValue)
      Determines whether RexxEngine.terminate() executes on the current thread or on a separate thread. ooRexx 5 with RFE 806. fixed a memory leak for the price of abmysal performance (appr. a slow down of 50x).
      Parameters:
      newValue -
    • isTerminateOnSeparateThread

      public boolean isTerminateOnSeparateThread()
      Returns the current value of TerminateOnSeparateThread
      Returns:
      current setting
    • getTerminateOnSeparateThread

      public boolean getTerminateOnSeparateThread()
      Returns the current value of TerminateOnSeparateThread
      Returns:
      current setting
    • setResetLocalBeforeTerminateDefault

      public static void setResetLocalBeforeTerminateDefault(boolean newValue)
      Determines whether RexxEngine.terminate() executes on the current thread (default) or on a separate thread. ooRexx 5 with RFE 806. fixed a memory leak for the price of abmysal performance (appr. a slow down of 50x).
      Parameters:
      newValue -
    • isResetLocalBeforeTerminateDefault

      public static boolean isResetLocalBeforeTerminateDefault()
      Returns the current value of resetLocalBeforeTerminateDefault
      Returns:
      current setting
    • getResetLocalBeforeTerminateDefault

      public static boolean getResetLocalBeforeTerminateDefault()
      Returns the current value of resetLocalBeforeTerminateDefault
      Returns:
      current setting
    • setResetLocalBeforeTerminate

      public void setResetLocalBeforeTerminate(boolean newValue)
      Determines whether RexxEngine.terminate() executes on the current thread or on a separate thread. ooRexx 5 with RFE 806. fixed a memory leak for the price of abmysal performance (appr. a slow down of 50x).
      Parameters:
      newValue -
    • isResetLocalBeforeTerminate

      public boolean isResetLocalBeforeTerminate()
      Returns the current value of resetLocalBeforeTerminate
      Returns:
      current setting
    • getResetLocalBeforeTerminate

      public boolean getResetLocalBeforeTerminate()
      Returns the current value of resetLocalBeforeTerminate
      Returns:
      current setting
    • getLanguageVersionString

      public static String getLanguageVersionString()
      Getter method.
      Returns:
      returns the PARSE VERSION string of the currently ooRexx interpreter in use.
    • isTerminationFixed

      protected static boolean isTerminationFixed()
      Determines whether the ooRexx version string indicates an interpretr that has Terminate() fixed.
    • get_rii_ID

      public String get_rii_ID()
      Getter method.
      Returns:
      the RexxInterpreter instance ID
    • set_rii_ID

      protected void set_rii_ID(String rii_ID)
      Setter method. Only meant to be used by Java4Rexx.java.
    • getRexxConfiguration

      public RexxConfiguration getRexxConfiguration()
      Getter method.
      Returns:
      the RexxConfiguration object of this Rexx engine
    • getId

      public long getId()
      Returns the identifier of this RexxEngine. The RexxEngine ID is a positive long number generated when this RexxEngine was created. The RexxEngine ID is unique and remains unchanged during its lifetime.
      Returns:
      this RexxEngine's ID.
    • setId

      protected void setId(long newValue)
      Allows to set the id value which will be used starting with BSF4ooReex850 as it became possible to get the ooRexx Rexx interpreter identifier using .context~interpreter. This is meant to be used by RexxAndJava.createRexxInterpreterInstance(...) such that for debugging both, ooRexx and Java use the same id value.
      Since:
      20250827
    • getRexxInterface

      public org.rexxla.bsf.engines.rexx.RexxAndJava getRexxInterface()
      Returns the RexxAndJava instance that is used for interfacing with Rexx.
    • initialize

      public void initialize(org.apache.bsf.BSFManager mgr, String lang, Vector declaredBeans) throws org.apache.bsf.BSFException
      Initializes the Rexx engine and causes the external functions 'BSF' and 'BSFPollEvents' to be registered with the Rexx interpreter. Therefore Rexx programs invoked from Java have these two functions available to them and are therefore able to communicate with Java.

      Note: at this point in time the Rexx interpreter instance has not been created yet. If using apply(), eval() and the like an instance with the default configuration gets created such that no instance creation options that a Java client may be defining can get honored. Therefore never use apply(), eval() in here.

      Specified by:
      initialize in interface org.apache.bsf.BSFEngine
      Overrides:
      initialize in class org.apache.bsf.util.BSFEngineImpl
      Parameters:
      mgr - The BSFManager that's hosting this engine.
      lang - Language string which this engine is handling.
      declaredBeans - Vector of BSFDeclaredObject containing beans that should be declared into the language runtime at init time as best as possible.
      Throws:
      org.apache.bsf.BSFException - if anything goes wrong while init'ing a BSFException is thrown. The reason indicates the problem.
    • getLocalEnvironment

      public Object getLocalEnvironment()
      Get the ooRexx .local directory.
      Returns:
      a RexxProxy allowing access to the ooRexx .local directory
      Since:
      2015-05-09
    • getGlobalEnvironment

      public Object getGlobalEnvironment()
      Get the ooRexx .environment directory.
      Returns:
      a RexxProxy allowing access to the ooRexx .environment directory
      Since:
      2015-05-09
    • getNil

      public Object getNil()
      Get the ooRexx .nil object.
      Returns:
      a RexxProxy representing the ooRexx .nil sentinel object
      Since:
      2015-05-09
    • getInterpreterVersion

      public long getInterpreterVersion()
      (Copied from the ooRexx rexxpg.pdf documentation) "Returns the version of the interpreter. The returned version is encoded in the 3 least significant bytes of the returned value, using 1 byte each for the interpreter version, release, and revision values. For example, on a 32-bit platform, this value would be 0x00040000 for version 4.0.0."
      Returns:
      the ooRexx interpreter version
      Since:
      2015-05-09
    • getLanguageLevel

      public long getLanguageLevel()
      (Copied from the ooRexx rexxpg.pdf documentation) "Returns the language level of the interpreter. The returned language level is encoded in the 2 least significant bytes of the returned value, using 1 byte each for the interpreter version, release, and revision values. For example, on a 32-bit platform, this value would be 0x00000603 for language level 6.03."
      Returns:
      the ooRexx language level
      Since:
      2015-05-09
    • eval

      public Object eval(String source, int lineNo, int columnNo, Object oscript) throws org.apache.bsf.BSFException
      Evaluates (executes) a piece of Rexx code (can be a whole program as well) without any Java-supplied arguments and returns the result.
      Parameters:
      source - if set to RexxAndJava.EVENT_TEXT, then oscript is put into the event queue to be polled by Rexx. If this text starts with the string "/*2*/" it is put into the alarm (highest dispatch) level vector, if it starts with the string "/*0*/" it is put into the batch (lowest dispatch) level vector, else it is put into the normal level vector.
      lineNo - not used.
      columnNo - not used.
      oscript - the String version of this object [using toString()] represents the Rexx code to be executed. Its statements are delimited with a ';' or a CR (carriage-return) and/or LF (line-feed).
      Returns:
      a String object with the result from Rexx or null.
      Throws:
      org.apache.bsf.BSFException - if anything goes wrong while eval'ing a BSFException is thrown. The reason indicates the problem.
    • call

      public Object call(Object object, String name, Object[] args) throws org.apache.bsf.BSFException
      Calls (executes) a Rexx program which code has been supplied before via an invocation of "apply()", "exec()" or "eval()" with the Java-supplied arguments and returns the result.

      [Hint: This follows after learning how Xalan is employing BSF: it first calls "exec()" and then "call()", hence "call()" does not receive the source to be executed.]

      As of 2009-05-17 using the new ooRexx 4.0 APIs the following fundamental change has been implemented: if the argument object is an instance of RexxProxy, then a callback on the RexxProxy object is carried out, using method as the ooRexx message name, supplying arguments, if any. Otherwise, the original behaviour takes place.

      Note: if the RexxProxy's userDataID field is not set (i.e. null), then no slot argument will be supplied as the last argument to the Rexx method.

      Parameters:
      object - if an instance of RexxProxy, then a callback is carried out
      name - if given, name of the message to send to the ooRexx object
      args - arguments to be passed to Rexx, if any
      Returns:
      an object with the result from Rexx or null.
      Throws:
      org.apache.bsf.BSFException - if anything goes wrong while eval'ing a BSFException is thrown. The reason indicates the problem.
    • call

      public Object call(Object object, String name, Object[] args, Object scope) throws org.apache.bsf.BSFException
      Call version that allows for supplying a Rexx class serving as the scope for the method invocation (new in ooRexx 5.0, cf. rexxapi.pdf, SendMessageScoped()).
      Parameters:
      object - if an instance of RexxProxy, then a callback is carried out
      name - if given, name of the message to send to the ooRexx object
      args - arguments to be passed to Rexx, if any
      scope - a string or RexxProxy representing an ooRexx class object, message resolution will start at the supplied scope (must be a superclass of the Rexx object resolving the message)
      Returns:
      an object with the result from Rexx or null.
      Throws:
      org.apache.bsf.BSFException
      Since:
      850 (2022-08-11)
    • call

      public Object call(RexxProxy proxy, Method methodObject, Object[] args) throws org.apache.bsf.BSFException
      Allows forwarding a messages to a RexxProxy using the method name of the supplied methodObject object with the supplied arguments, if any. This method will be mostlikely invoked employing a Proxy object.

      As of 2009-05-17 using the new ooRexx 4.0 APIs the following fundamental change has been implemented: if the argument object is an instance of RexxProxy, then a callback on the RexxProxy object is carried out, using method as the ooRexx message name, supplying arguments, if any. Otherwise, the original behaviour takes place.

      Parameters:
      proxy - a RexxProxy to which the callback is to be carried out
      methodObject - the java.lang.reflect.Method object that is supposed to be invoked originally
      args - arguments to be passed to Rexx, if any
      Returns:
      a String object with the result from Rexx or null.
      Throws:
      org.apache.bsf.BSFException
    • call

      public Object call(RexxProxy proxy, Object javaObject, String methodName, String methodDescriptor, Object[] args) throws org.apache.bsf.BSFException
      Allows forwarding a messages to a RexxProxy using the supplied methodName the supplied arguments, if any. This method will be mostlikely invoked employing a RexxProxy object in the context of a dynamically created (proxy) Java class (e.g. an abstract class, where the abstract methods will forward their invocation to the RexxProxy object).
      Parameters:
      proxy - a RexxProxy to which the callback is to be carried out
      javaObject - object that invoked this callback
      methodName - this name is used as the message to be sent to the Rexx object
      methodDescriptor - the Java internal representation of the method's arguments and return type, if any
      args - arguments to be passed to Rexx, if any
      Returns:
      a String object with the result from Rexx or null.
      Throws:
      org.apache.bsf.BSFException
    • apply

      public Object apply(String source, int lineNo, int columnNo, Object oscript, Vector vArgNames, Vector vArgs) throws org.apache.bsf.BSFException
      Applies (evaluates) a piece of Rexx code (can be a whole program as well) with Java-supplied arguments and returns the result.
      Specified by:
      apply in interface org.apache.bsf.BSFEngine
      Overrides:
      apply in class org.apache.bsf.util.BSFEngineImpl
      Parameters:
      source - name of source containing the script (e.g. fully qualified file name) or null
      lineNo - not used.
      columnNo - not used.
      oscript - the String version of this object [using toString()] represents the Rexx code to be executed. Its statements are delimited with a ';' or a an LF (line-feed, "0x0a"), preceeded by an optional CR (carriage-return, "0x0d").
      vArgNames - not used.
      vArgs - arguments to be passed to Rexx.
      Returns:
      a String object with the result from Rexx or null.
      Throws:
      org.apache.bsf.BSFException - if anything goes wrong while doin' it.
    • declareBean

      public void declareBean(org.apache.bsf.BSFDeclaredBean bean) throws org.apache.bsf.BSFException
      Saves the supplied bean in engineDeclaredBeans which will be looked up by RexxAndJava.lookupBean() if a bean with the supplied name is not present in RexxAndJava's registry.
      Specified by:
      declareBean in interface org.apache.bsf.BSFEngine
      Overrides:
      declareBean in class org.apache.bsf.util.BSFEngineImpl
      Parameters:
      bean - the bean to be declared
      Throws:
      org.apache.bsf.BSFException - if the engine cannot do this operation
    • undeclareBean

      public void undeclareBean(org.apache.bsf.BSFDeclaredBean bean) throws org.apache.bsf.BSFException
      Removes the supplied bean from engineDeclaredBeans.
      Specified by:
      undeclareBean in interface org.apache.bsf.BSFEngine
      Overrides:
      undeclareBean in class org.apache.bsf.util.BSFEngineImpl
      Parameters:
      bean - the bean to be declared for the already started language.
      Throws:
      org.apache.bsf.BSFException - if the engine cannot do this operation
    • terminate

      public void terminate()
      Waits until all Rexx threads of this engine's Rexx interpreter instance peer have terminated (using the new ooRExx 4.0 APIs); this method must be called from the same thread that created the Rexx interpreter instance (i.e. the thread that created this instance of the RexxEngine). Terminating the primodal Rexx interpreter instance makes it unavailable for use by the Java side, but remains running for the native code. All other Rexx interpreter instances will be terminated for good. Use isTerminated() to test whether the Rexx interpreter instance of this RexxEngine got terminated.

      Note: native termination of the RII (Rexx interpreter instance) MUST be solely done from here! To halt all Rexx threads of this engine's Rexx interpreter instance peer use halt().

      Specified by:
      terminate in interface org.apache.bsf.BSFEngine
      Overrides:
      terminate in class org.apache.bsf.util.BSFEngineImpl
    • halt

      public void halt() throws RexxException
      Halt (raise the HALT condition) all Rexx threads of this engine's peer Rexx interperter instance (using the new ooRExx 4.0 APIs).
      Throws:
      RexxException
    • halt

      public int halt(String tid)
      Allow halting an individual Rexx thread (raising the HALT condition) having the given thread ID.
      Parameters:
      tid - a string with the target thread ID, or the string "0" (raises the HALT condition in all ooRexx threads)
      Returns:
      return code from RexxSetHalt(...): 0 (o.k.), 1 (tid not found), or 2 (failure), or 3 (Rexx interpreter instance was not yet created)
    • registerBean

      public String registerBean(Object object) throws RexxException
      This method registers an object with the given beanName that gets created automatically in the BSF registry, if not registered yet. In addition a reference counting is carried out.
      Parameters:
      object - to be registered
      Returns:
      returns the beanName
      Throws:
      RexxException
      Since:
      2012-02-19
    • registerBean

      public String registerBean(String beanName, Object object) throws RexxException
      This method registers an object with the given beanName with the BSF registry, if not registered yet. In addition a reference counting is carried out.
      Parameters:
      beanName - name of the object to be registered
      object - to be registered
      Returns:
      returns the beanName
      Throws:
      RexxException
      Since:
      2012-02-19
    • unregisterBean

      public boolean unregisterBean(String beanName) throws RexxException
      This method allows for unregistering Beans, taking into account reference counters. Only if the reference counter drops to 0, will the given Bean be unregistered.
      Parameters:
      beanName - name of the Bean to be unregistered
      Returns:
      returns true, if the Bean exists, false else.
      Throws:
      RexxException
      Since:
      2012-02-19
    • lookupBean

      public Object lookupBean(String beanName) throws RexxException
      Allow lookup of BSFRegistry entries.
      Parameters:
      beanName - string denoting the index into the BSFRegistry
      Returns:
      the Java object matching beanName, if not found in BSF registry returns null
      Throws:
      RexxException
      Since:
      2012-02-19
    • procEnvironment

      public String procEnvironment(int t, String n, String v) throws RexxException
      Throws:
      RexxException