title: Best practice for async communication between services
body: <p>What's best/good service binding/communication practice in the following scenario (I hope the title is somewhat meaningful):</p>
  
  <p>A business layer (BL) comprising several service methods that share (as common communication endpoint) an asynchronous socket service (SS) which may be bound by those methods and used for socket IO.</p>
  
  <p>E.g. the BL grabs SL and invokes send(message) and then awaits a response.</p>
  
  <p>I used callbacks and the binder pattern at first. As I had some problems with a clear design using the binder pattern (lack of a message queue and everything done in the main thread), I am now trying the message pattern.</p>
  
  <p>So basically, BL services and the SL service now have a Messenger and a corresponding handler:</p>
  
  <pre><code>private final IncomingHandler incomingHandler = new IncomingHandler();
  private final Messenger messengerReceiver = new Messenger(incomingHandler);
  private class IncomingHandler extends Handler {
    @Override
    public void handleMessage(Message msg) {
    ...
    }
  }
  </code></pre>
  
  <p>One of the BLs is an AbstractAccountAuthenticator subclass implementing</p>
  
  <pre><code>addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options){
       ...
       if(socketConnectionState != null){
          Bundle authBundle = new Bundle();
          authBundle.putString("password", password);
          authBundle.putString("username", account.name);
          Message message = Message.obtain(null, SocketConnectionHandler.SEND_REQUEST, authBundle);
          message.replyTo = messengerReceiver;
          socketConnectionState.getMessenger().send(message);
  ...}
  </code></pre>
  
  <p>which also uses the SL to obtain the authToken.
  The addAccount() method either requires to return the result (the authToken) immediately in a Bundle or to call the response callback methods instead.
  Now if I request the auth token inside addAccount via SL, how would I handle to pass back the result?</p>
  
  <p>The main problem here is that the result is not returned to the calling method (addAccount()) but to the messengerReceiver handler.</p>
  
  <p>The only way I could think of is a BlockingQueue which is offered the response by the message handler and which is then taken inside the addAccount() method but this really feels uberugly.
  Other ideas? Right approach at all?</p>