Class RexxEngine
- All Implemented Interfaces:
PropertyChangeListener,EventListener,org.apache.bsf.BSFEngine
------------------------ 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
FieldsModifier and TypeFieldDescriptionprotected booleanWill be set to true, if terminate() used JNI to successfully terminate the Rexx interpreter instance.protected booleanIf terminate() was invoked, then this instance must not be used anymore.protected longprotected static StringThePARSE VERSIONstring of the currently ooRexx interpreter in use.static final StringVersion 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 -
Method Summary
Modifier and TypeMethodDescriptionApplies (evaluates) a piece of Rexx code (can be a whole program as well) with Java-supplied arguments and returns the result.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 version that allows for supplying a Rexx class serving as the scope for the method invocation (new in ooRexx 5.0, cf.Allows forwarding a messages to a RexxProxy using the suppliedmethodNamethe suppliedarguments, if any.Allows forwarding a messages to a RexxProxy using the method name of the suppliedmethodObjectobject with the suppliedarguments, if any.voiddeclareBean(org.apache.bsf.BSFDeclaredBean bean) Saves the supplied bean inengineDeclaredBeanswhich will be looked up by RexxAndJava.lookupBean() if a bean with the supplied name is not present in RexxAndJava's registry.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.environmentdirectory.longgetId()Returns the identifier of this RexxEngine.long(Copied from the ooRexxrexxpg.pdfdocumentation) "Returns the version of the interpreter.long(Copied from the ooRexxrexxpg.pdfdocumentation) "Returns the language level of the interpreter.static StringGetter method.Get the ooRexx.localdirectory.getNil()Get the ooRexx.nilobject.booleanReturns the current value ofresetLocalBeforeTerminatestatic booleanReturns the current value ofresetLocalBeforeTerminateDefaultGetter method.org.rexxla.bsf.engines.rexx.RexxAndJavaReturns theRexxAndJavainstance that is used for interfacing with Rexx.static StringReturns the string indicating which major ooRexx version and compilation date fixed the Terminate() problem.booleanReturns the current value ofTerminateOnSeparateThreadstatic booleanReturns the current value ofTerminateOnSeparateThreadDefaultvoidhalt()Halt (raise theHALTcondition) all Rexx threads of this engine's peer Rexx interperter instance (using the new ooRExx 4.0 APIs).intAllow halting an individual Rexx thread (raising theHALTcondition) having the given thread ID.voidinitialize(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.booleanReturns the current value ofresetLocalBeforeTerminatestatic booleanReturns the current value ofresetLocalBeforeTerminateDefaultbooleanGetter method for fieldbTerminated.booleanReturns the current value ofTerminateOnSeparateThreadstatic booleanReturns the current value ofTerminateOnSeparateThreadDefaultprotected static booleanDetermines 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) registerBean(Object object) 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 voidset_rii_ID(String rii_ID) Setter method.protected voidsetId(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.voidsetResetLocalBeforeTerminate(boolean newValue) Determines whether RexxEngine.terminate() executes on the current thread or on a separate thread.static voidsetResetLocalBeforeTerminateDefault(boolean newValue) Determines whether RexxEngine.terminate() executes on the current thread (default) or on a separate thread.static voidsetTerminateFixed(String newValue) Allows to set the string indicating which major ooRexx version and compilation date fixed the Terminate() problem.voidsetTerminateOnSeparateThread(boolean newValue) Determines whether RexxEngine.terminate() executes on the current thread or on a separate thread.static voidsetTerminateOnSeparateThreadDefault(boolean newValue) Determines whether RexxEngine.terminate() executes on the current thread (default) or on a separate thread.voidWaits 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.voidundeclareBean(org.apache.bsf.BSFDeclaredBean bean) Removes the supplied bean fromengineDeclaredBeans.booleanunregisterBean(String beanName) 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
-
Field Details
-
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 bTerminatedIf terminate() was invoked, then this instance must not be used anymore. -
bJNITerminated
protected boolean bJNITerminatedWill be set to true, if terminate() used JNI to successfully terminate the Rexx interpreter instance.- Since:
- 2013-06-25
-
languageVersionString
ThePARSE VERSIONstring 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 fieldbTerminated.- Returns:
true, if Rexx engine got successfully terminated,false
-
getTerminateFixed
Returns the string indicating which major ooRexx version and compilation date fixed the Terminate() problem.- Returns:
- current string
-
setTerminateFixed
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 ofTerminateOnSeparateThreadDefault- Returns:
- current setting
-
getTerminateOnSeparateThreadDefault
public static boolean getTerminateOnSeparateThreadDefault()Returns the current value ofTerminateOnSeparateThreadDefault- 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 ofTerminateOnSeparateThread- Returns:
- current setting
-
getTerminateOnSeparateThread
public boolean getTerminateOnSeparateThread()Returns the current value ofTerminateOnSeparateThread- 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 ofresetLocalBeforeTerminateDefault- Returns:
- current setting
-
getResetLocalBeforeTerminateDefault
public static boolean getResetLocalBeforeTerminateDefault()Returns the current value ofresetLocalBeforeTerminateDefault- 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 ofresetLocalBeforeTerminate- Returns:
- current setting
-
getResetLocalBeforeTerminate
public boolean getResetLocalBeforeTerminate()Returns the current value ofresetLocalBeforeTerminate- Returns:
- current setting
-
getLanguageVersionString
Getter method.- Returns:
- returns the
PARSE VERSIONstring 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
Getter method.- Returns:
- the RexxInterpreter instance ID
-
set_rii_ID
Setter method. Only meant to be used by Java4Rexx.java. -
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 theRexxAndJavainstance 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:
initializein interfaceorg.apache.bsf.BSFEngine- Overrides:
initializein classorg.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
Get the ooRexx.localdirectory.- Returns:
- a
RexxProxyallowing access to the ooRexx.localdirectory - Since:
- 2015-05-09
-
getGlobalEnvironment
Get the ooRexx.environmentdirectory.- Returns:
- a
RexxProxyallowing access to the ooRexx.environmentdirectory - Since:
- 2015-05-09
-
getNil
Get the ooRexx.nilobject.- Returns:
- a
RexxProxyrepresenting the ooRexx.nilsentinel object - Since:
- 2015-05-09
-
getInterpreterVersion
public long getInterpreterVersion()(Copied from the ooRexxrexxpg.pdfdocumentation) "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 be0x00040000for version 4.0.0."- Returns:
- the ooRexx interpreter version
- Since:
- 2015-05-09
-
getLanguageLevel
public long getLanguageLevel()(Copied from the ooRexxrexxpg.pdfdocumentation) "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 be0x00000603for 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 toRexxAndJava.EVENT_TEXT, thenoscriptis 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
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
objectis an instance ofRexxProxy, then a callback on the RexxProxy object is carried out, usingmethod as the ooRexx message name, supplying arguments, if any. Otherwise, the original behaviour takes place.Note: if the RexxProxy's
userDataIDfield 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 outname- if given, name of the message to send to the ooRexx objectargs- 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 outname- if given, name of the message to send to the ooRexx objectargs- arguments to be passed to Rexx, if anyscope- 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 suppliedmethodObjectobject with the suppliedarguments, if any. This method will be mostlikely invoked employing aProxyobject.As of 2009-05-17 using the new ooRexx 4.0 APIs the following fundamental change has been implemented: if the argument
objectis an instance ofRexxProxy, then a callback on the RexxProxy object is carried out, usingmethod 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 outmethodObject- the java.lang.reflect.Method object that is supposed to be invoked originallyargs- 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 suppliedmethodNamethe suppliedarguments, 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 outjavaObject- object that invoked this callbackmethodName- this name is used as the message to be sent to the Rexx objectmethodDescriptor- the Java internal representation of the method's arguments and return type, if anyargs- 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:
applyin interfaceorg.apache.bsf.BSFEngine- Overrides:
applyin classorg.apache.bsf.util.BSFEngineImpl- Parameters:
source- name of source containing the script (e.g. fully qualified file name) or nulllineNo- 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 inengineDeclaredBeanswhich will be looked up by RexxAndJava.lookupBean() if a bean with the supplied name is not present in RexxAndJava's registry.- Specified by:
declareBeanin interfaceorg.apache.bsf.BSFEngine- Overrides:
declareBeanin classorg.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 fromengineDeclaredBeans.- Specified by:
undeclareBeanin interfaceorg.apache.bsf.BSFEngine- Overrides:
undeclareBeanin classorg.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. UseisTerminated()to test whether the Rexx interpreter instance of thisRexxEnginegot 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:
terminatein interfaceorg.apache.bsf.BSFEngine- Overrides:
terminatein classorg.apache.bsf.util.BSFEngineImpl
-
halt
Halt (raise theHALTcondition) all Rexx threads of this engine's peer Rexx interperter instance (using the new ooRExx 4.0 APIs).- Throws:
RexxException
-
halt
Allow halting an individual Rexx thread (raising theHALTcondition) having the given thread ID.- Parameters:
tid- a string with the target thread ID, or the string"0"(raises theHALTcondition in all ooRexx threads)- Returns:
- return code from
RexxSetHalt(...):0(o.k.),1(tid not found), or2(failure), or3(Rexx interpreter instance was not yet created)
-
registerBean
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
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 registeredobject- to be registered- Returns:
- returns the beanName
- Throws:
RexxException- Since:
- 2012-02-19
-
unregisterBean
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,falseelse. - Throws:
RexxException- Since:
- 2012-02-19
-
lookupBean
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 returnsnull - Throws:
RexxException- Since:
- 2012-02-19
-
procEnvironment
- Throws:
RexxException
-