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

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

Back to the top