Non-Persistent Asynchronous calling with object passing

2
Hi, I am trying to execute a microflow asynchronous based on non-persistent entities. I am using the "RunMicroflowAsyncInQueue" java action in the Community commens. I understand that session.retain is deprecated after 5.21 (https://docs.mendix.com/refguide6/ISession+API+Usage), however the proposed solution (linking it to the $currentSession) does not seem to work. At first the  "RunMicroflowAsyncInQueue" did not pass on the "currentSession" object (per remarks of MWE "//MWE: somehow, it only works with system context... well thats OK for now." in Misc.java). It seems to work if i pass getContext(); instead of the createSystemContext(); however still no objects retrieved. Has somebody encountered and solved this issue before or perhaps know where to look ? Thanks in advance,
asked
4 answers
5

I got this working in a demo project, I'll invite you in a minute. The required Java code is:

 

	// BEGIN USER CODE
	HashMap<String, Object> parameters = new HashMap<String, Object>();
	parameters.put(inputName, inputObject);
	Future<Object> future = Core.executeAsync(this.getContext(), microflowName, false, parameters);
	future.get();
	return true;
	// END USER CODE

Note the false in the Core.executeAsync() method. Without this parameter, this fails.

answered
0

Ronald:

"Although you may be correct that this will never work (haven't tested yet, should work in my opinion), it is simply plain wrong that NP objects only exist client side: this might be true in Mendix 7, but isn't valid for Mendix 6.9.1.

Rom van Arendonk

8 minutes ago"

 

Think that Rom is correct in this case, even stonger yet it woks in older versions.... i even get the correct objectID in my debugflow... but even when the correct assiciation is present i can't seem to retrieve it.

answered
0

See used code below:

 

public static Boolean runMicroflowInBackground(final IContext context, final String microflowName,
			final IMendixObject paramObject)
	{
		final ISession session = context.getSession();
		
		if (paramObject != null)
			session.retain(paramObject); // shows as deprecated
		
			
		MFSerialExecutor.instance().execute(new Runnable() {

			@Override
			public void run()
			{
				try
				{
					IContext c = Core.createSystemContext();
					if (paramObject != null) {
							//Core.executeAsync(c, microflowName, true, paramObject).get(); //MWE: somehow, it only works with system context... well thats OK for now.						
						// use context instead of c otherwise there is no currentsession passed
						Core.executeAsync(context, microflowName, true, paramObject).get(); //MWE: somehow, it only works with system context... well thats OK for now.						
					}
					else
						Core.executeAsync(c, microflowName, true, new HashMap<String,Object>()).get(); //MWE: somehow, it only works with system context... well thats OK for now.
				}
				catch (Exception e)
				{
					throw new RuntimeException("Failed to run Async: "+ microflowName + ": " + e.getMessage(), e);
				}
				
				finally {
					if (paramObject != null)
						session.release(paramObject.getId()); // shows as deprecated
				}
			}
			
		});
		return true;
	}	

 

answered
-1

I think this will never work with non persistent objects. Non persistent objects only exist client side, so a Java action is never able to pick up these objects. My sollution would be to make them persistable and do a cleanup of these objects later.

Regards,

Ronald

 

answered