code: protected Realm matchRealm(IMessage message, String realm) {
      if (realmExists(realm)) {
        ApplicationId singleId = message.getSingleApplicationId();
        // check on single app id, than we iterate.
        Realm r = getRealm(realm, singleId);
        if (r == null) {
          List<ApplicationId> appIds = message.getApplicationIdAvps();
          for (int index = 0; index < appIds.size(); index++) {
            r = getRealm(realm, appIds.get(index));
            if (r != null) {
              break;
            }
          }
        }
  
        return r;
      }
      return null;
    }
docs: -------------------- helper methods --------------------