Concurrent methods question

Excuse me for showing some ignorance here (but I feel it’s a frienldy audience ;-) )

I have a button/script that validates some local form data via a call to a remote site (not a Servoy server) and waits for a response, which can take 10 to 60 seconds. The response is used to set a ‘validated’ flag, ie a field in the record indicating that it’s passed or failed validation. This part works fine. Most of the time is spent waiting for the response, the method itself is only a few lines of code, a call to a custom plugin, the wait for the response, then a couple of lines of code handling the result.

I’d like to hide the process, by triggering it from the OnDataChange method rather than a button, running it as a seperate thread, and allowing the data entry to continue, some of which triggers other local methods. Once the validation method returns a response, the ‘validated’ field is set appropriately.

Ideally I’d like this to happen without any noticable delay in data entry nor interference with the execution of methods associated with other fields.

My trials so far seem to degrade performance. I thought about using the scheduler plugin to add the validation as a job. Would this achieve the effect I’m after?

Any words from the wise would be appreciated, before I go too far down this path.

(There’s also the issue that the user could move to another record or form, but I can handle that.)

No, the scheduler plugin will not help you in that case.

I think there is no real solution other than sticking it in a seperate thread.

I think I could add a method to the progress plugin simply offering you a thread to work with, without a progress bar.

The issue would be that your client will not have any feedback so when you do something that should be waited for the progress plugin with feedback is a better alternative.

Thanks Marcel, as seperate thread is what I need. I will check out the Progress plugin. A progress bar would be OK if it wasn’t modal, ie allowed the user to continue working.

If you call a custom plugin that does a job that takes up to a minute, why don’t you simply do this in a thread in your custom plugin? You simply have to do the work in a thread and call a Servoy method when done. I don’t really see how a standard plugin can do this kind of thing for you…

Hi Patrick, thanks for your thoughts. Actually, it’s not a plugin, just a JAR I’ve dropped into the lib folder.

I currently have something like

// ID is the field containing the data to be verified
// the call to the external JAR returns the result in a vector object
// vResponse is true if the call has completed without error.

var result = new java.util.Vector()

var vResponse = Packages.au.gov.hic.hiconline.client.api.EclaimAPI.getInstance().verify(ID, result);

if (vResponse)
{
// read the contents of the result vector
...
}
else
{
...
}

The method waits for a response from the EclaimAPI (which does the call to the remote server.)

If I dropped the "var vResponse = " part, and add it as an element of the result vector, I could make the call and move on, but I’m not clear how I’d get a result back into Servoy. From what you’re saying that instead of the JAR, I’ll have to create a plugin that can call a Servoy method when the thread. I’ve made a simple plugin before (with Marcel’s assistance) but not one that calls Servoy methods.

Well, I guess we could help you with that… Have a look at the scheduler plugin, it has the source files included and it does call methods.

Oh, thanks for the tip Patrick, that’ll be enough to get me going.