Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] DSF - use of asynchronous method to retrieve informations in DataRequestMonitor issue

There is also the CountingRequestMonitor that allows you to perform multiple aysynchronous calls
at the same time, and trigger some code once all calls are done.


From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Jason Litton
Sent: Monday, February 04, 2013 9:53 AM
To: CDT General developers list.
Subject: Re: [cdt-dev] DSF - use of asynchronous method to retrieve informations in DataRequestMonitor issue

A CountDownLatch is only good if you know how many operations you're going to have. I always do the calculation before I get into the queueCommand() call. If you can't know how many operations you have, you might be better off calling the Query class. However, I assume multiple commands would be in a for loop. If so, just set the latch to (i -1). If you're in something like a do...while, you may want to make each call blocking (with a latch value of 1). You'll lose speed by not being able to queue your operations all together, but you'll get guaranteed data back as long as you handle warnings and errors correctly.
Jason


From: "Maherzia BELAAZI" <maherzia.belaazi@xxxxxx>
To: "CDT General developers list." <cdt-dev@xxxxxxxxxxx>
Sent: Monday, February 4, 2013 1:11:56 AM
Subject: Re: [cdt-dev] DSF - use of asynchronous method to retrieve informations in DataRequestMonitor issue

Thanks a lot of these helpful indications and suggestions.

Jason,

Please, What is the most adequate numOperations  to set in CountDownLatch ?  (I’m dealing with different types of variables and I can’t predict the number of  call/operations to do ?

Thanks in advance,

Maherzia

 

From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of Marc Khouzam
Sent: vendredi 1 février 2013 16:45
To: CDT General developers list.
Subject: Re: [cdt-dev] DSF - use of asynchronous method to retrieve informations in DataRequestMonitor issue

 

Jason's suggestion seems good.
 
DSF also provides the Query class for this.  There are many examples of how to use it in the code.
 
Remember that an asynchronous call completes "later", so it makes sense that the result is not there on the line that follows the async call.  That is why you need some kind of blocking call that will wait for the result to become available
 
Best regards,
 
Marc
 
 
----- Original Message -----
From: Jason Litton <jason@xxxxxxxxxxxxxxx>
To: "CDT General developers list." <cdt-dev@xxxxxxxxxxx>
Sent: 01-02-2013 9:41
Subject: Re: [cdt-dev] DSF - use of asynchronous method to retrieve informations in DataRequestMonitor issue
 
 

Maherzia,
I don't know if this is the accepted way, but when I need to have the info from my request monitors to do further processing, I use a CountDownLatch:

CountDownLatch latch = new CountDownLatch(numOperations);

DataRequestMonitor<IExpressionDMContext[]> drm =  // the used DataRequestMonitor

                           new DataRequestMonitor<IExpressionDMContext[]>(fSession.getExecutor(), rm) {

 

@Override

protected

void handleCompleted() {

super.handleCompleted();

latch.countdown();

}

 

 

                                  protected void handleSuccess() {

                                        children.addAll(Arrays.asList(getData())); (1)

                                        //children here are not empty

                                  }

 

                           };

expressionService.getSubExpressions(miDMCExp, drm);     // call of the asynchronous method

try {
latch.await(x, TimeUnit.{something});
} catch (InterruptedException e) {
//whatever you do to handle
}


//children will be populated here.


From: "Maherzia BELAAZI" <maherzia.belaazi@xxxxxx>
To:
cdt-dev@xxxxxxxxxxx
Sent: Friday, February 1, 2013 12:52:12 AM
Subject: [cdt-dev] DSF - use of asynchronous method to retrieve informations in DataRequestMonitor issue

Hello,

 

I’m calling an asynchronous method that uses a DataRequestMonitor. This method returns a set of variables

Calling this method in Run mode : I get empty set

Calling this method in debug mode and stepping in : I get a set with correct values

So in Run mode i used “Thread.sleep” to solve a problem of conflict between threads (a simple reflection)

But it is not a good solution

My question is

how could I complete an asynchronous method call and get returned values without setting a Thread.sleep ?                                                                                         

 

                                                                                                                                                             

 

My piece of code :

final ArrayList<IExpressionDMContext> children = new ArrayList<IExpressionDMContext>();

IExpressions expressionService = fServicesTracker.getService(IExpressions.class, null);

DataRequestMonitor<IExpressionDMContext[]> drm =  // the used DataRequestMonitor

                           new DataRequestMonitor<IExpressionDMContext[]>(fSession.getExecutor(), rm) {

                                  protected void handleSuccess() {

                                        children.addAll(Arrays.asList(getData())); (1)

                                        //children here are not empty

                                  }

 

                           };

expressionService.getSubExpressions(miDMCExp, drm);     // call of the asynchronous method

//children here are empty

 

In handleSuccess() method normally (as I understood) the calling of the asynchronous  method is completed.

And so in (1) I get all searched data.

But in (2) the filled “children” is empty.

 

Is there any wrong use the asynchronous  method ? is something missing ?

 

Thanks for any help

 

                                      


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev

Back to the top