Filter out events using AMI

Hi,

I am trying to create a java application using asterisk-java. The application asks Asterisk to make concurrent, outbound calls using AMI. Given that Asterisk sends each event to everyone connected to it, I need a way to filter out unwanted events for each thread. I find that filtering events using unique ids is not very reliable when dealing with multiple threads. Setting a unique id of a custom variable and adding it to an action seem like a good option, but not every event allows us to get that variable back. What is the best way to do it? Thanks.