Best way to synchronize asynchronous task

Viewed 13945

My Problem: I've got 802.15.4 Wireless network connected to a serial port (using a wrapper). I can send packages into the network and listen for incoming packages. As you can imagine this is highly asynchronous.

Here comes the task: I want to send commands to the network and wait for the response in one function call. For Example: I want to get the temperature from the Node with the network ID 1338.

double getTemperature(int id) throws Exception { .... }

Is there a better way of waiting for a response message other than doing all this "synchonized(object) wait(..) notify(..)" stuff?

Best regards, bigbohne

Maybe to add some spice:

This should all end in a webinterface where user can request these commands (either through ajax or directly). I've also thought of caching responce values in a database. But for some commands you MUSS have a direct answer of success/failure

3 Answers
Related