I want to know if exists a framework (or any way) to wait for a message inside a java code on asynchronous way. I repeat "asynchronous way".
For example:
int a=5;
MyObject mio= new MyObject();
mio.setx(6);
String message='x|1|5ABC';
MOM.enqueue(message,'myResponseQueue'); // <-- Shoot and forget!!
String res=MOM.dequeue('myResponseQueue'); // instance of class sleep (not in memory) waiting for message.
if (a=mio.getx()){int b=6; } // code awake and continue
a=7;
message='x|2|6ABC';
MOM.enqueue(message,'myResponseQueue'); // <-- Shoot and forget again!!
String res=MOM.dequeue('myResponseQueue'); // instance of class sleep (not in memory) again waiting for message.
if (res!=null){ // <-- code awake again
if (a==5){int b=7;}
}
I know with a Message-Drive Bean i can create a method to wait for the message, but if I have many messages I will break the code in many methods and I will lost the values of the local variables, this makes a very ugly code.