docs: private void registerMetricsEventually(String key, String value, BiConsumer<ObjectName, Iterable<Tag>> perObject) {
          if (getJmxDomain() != null) {
              try {
                  Set<ObjectName> objectNames = this.mBeanServer.queryNames(new ObjectName(getJmxDomain() + ":" + key + "=" + value + ",name=*"), null);
                  if (!objectNames.isEmpty()) {
                      // MBean is present, so we can register metrics now.
                      objectNames.forEach(objectName -> perObject.accept(objectName, Tags.concat(tags, nameTag(objectName))));
                      return;
                  }
              } catch (MalformedObjectNameException e) {
                  // should never happen
                  throw new RuntimeException("Error registering Tomcat JMX based metrics", e);
              }
          }
  
          // MBean isn't yet registered, so we'll set up a notification to wait for them to be present and register
          // metrics later.
          NotificationListener notificationListener = new NotificationListener() {
              @Override
              public void handleNotification(Notification notification, Object handback) {
                  MBeanServerNotification mBeanServerNotification = (MBeanServerNotification) notification;
                  ObjectName objectName = mBeanServerNotification.getMBeanName();
                  perObject.accept(objectName, Tags.concat(tags, nameTag(objectName)));
                  try {
                      mBeanServer.removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME, this);
                  } catch (InstanceNotFoundException | ListenerNotFoundException ex) {
                      throw new RuntimeException(ex);
                  }
              }
          };
  
          NotificationFilter notificationFilter = (NotificationFilter) notification -> {
              if (!MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(notification.getType())) {
                  return false;
              }
  
              // we can safely downcast now
              ObjectName objectName = ((MBeanServerNotification) notification).getMBeanName();
              return objectName.getDomain().equals(getJmxDomain()) && objectName.getKeyProperty(key).equals(value);
          };
  
          try {
              mBeanServer.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, notificationListener, notificationFilter, null);
          } catch (InstanceNotFoundException e) {
              // should never happen
              throw new RuntimeException("Error registering MBean listener", e);
          }
      }