I have a sequence of events that I didn't expect. It may be normal, but I wanted to checked.

My client subscribes to a feed, and when the onSubscription() event fires on my client, I am doing a sendMessage().
The method that deals with the incoming message in my data adapter is also called "sendMessage".

On the server side, I am finding that the message is arriving in my data adapter BEFORE the "subscribe" method has completed. This causes some issues because the processing on the "sendMessage" method in my data adapter relies on an object that gets created in the "subscribe" method - but I am finding that it is often not created at that time. I have included a sequence of debug messages and it confirms the sequence of events. At the moment I have worked around it by including a very short sleep() loop in my "sendMessage" that waits until the "subscribe" method has done its thing.

In case it is relevant, the subscribe method is creating a thread and starting it(a bit like the hello world example), and the sendMessage is relying on that thread having been started. But in my sendMessage method the thread object is often still null - hence the little wait.

So it works, but I don't like it.

Am I wrong in my assumption that the client is safe to sendMessage() once the onSubscription has fired? It seems not. So when is it safe? I basically do not want my client to be able to sendMessage until the subscribe method in my data adapter has finished.