class MessageDispatchSender implements Sender, MessageDispatchRegistry {

  public void send(final Message message) throws CommunicationException {

    if (message instanceof MessageRequiringResponse) {
      final MessageRequiringResponse messageRequringResponse =
        (MessageRequiringResponse)message;

      final Message requestMessage = messageRequringResponse.getMessage();

      final BlockingHandler<Message> responder =
        m_responders.get(requestMessage.getClass());

      if (responder != null) {
        messageRequringResponse.sendResponse(
          responder.blockingSend(requestMessage));
        return;
      }
    }
    else {
      final Handler<Message> handler = m_handlers.get(message.getClass());

      if (handler != null) {
        handler.handle(message);
        return;
      }
    }

    final CommunicationException[] exception = new CommunicationException[1];

    m_fallbackHandlers.apply(new ListenerSupport.Informer<Handler<Message>>() {
        public void inform(Handler<Message> handler) {
          try {
            handler.handle(message);
          }
          catch (CommunicationException e) {
            exception[0] = e;
          }
        }
      });

    if (message instanceof MessageRequiringResponse) {
      final MessageRequiringResponse messageRequringResponse =
        (MessageRequiringResponse)message;

      if (!messageRequringResponse.isResponseSent()) {
        // No one responded.
        messageRequringResponse.sendResponse(new NoResponseMessage());
      }
    }

    if (exception[0] != null) {
      throw exception[0];
    }
  }

}