How to keep access to java objects outside of the scope of a single Java Action

1
I'm looking to integrate a external java library which needs multiple related Java Actions to be executed in a microflow. (think of Start, Continue, Stop Actions) However, when a single Java Action is executed from the microflow, by default all java objects used within the Action are no longer available to the microflow. What I need is that for example the 'Stop' Action has access to the java object that was instantiated earlier by the external java library during the "Start' action.   Note that these java objects are created from an external library, so they can contain complex states, behavior, hold other objects, lists, et cetera. Therefore remodeling these to non-persistent Mendix entities to keep only some if its data available within the scope of the microflow is not feasible.   Is there a way to keep the java objects created by the library stored within the scope/session of a microflow,  so that any related Java Actions that are called later on in this microflow can pick them up again? Thanks!
asked
3 answers
3

You can use IContext:getData to get a map of objects bound to the current context. You can also use that to place data.

regards Fabian

answered
1

Make the variables static. This way they will stay in memory until you delete them manually or the program shuts down.

In the generated java action code there are two places where you can add code, one is within a function, and the other one is at the end of the file. In the latter you can add static variables.

-Andrej

answered
1

You can look at the rest service module (https://github.com/mendix/RestServices) for an example how to achive this:

* Http headers are store as java string in ThreadLocal: https://github.com/mendix/RestServices/blob/4c960ef54f720ce42699ce0f86e80fa40f1097b7/javasource/restservices/consume/RestConsumer.java#L173

 

answered