Skip to content

Commit

Permalink
Merge branch '2.1.x' into 2.2.x
Browse files Browse the repository at this point in the history
Closes gh-19903
  • Loading branch information
snicoll committed Jan 24, 2020
2 parents ddcc52a + 4bcd02a commit 9933032
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,7 @@
import org.apache.catalina.Context;
import org.apache.catalina.Manager;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.boot.web.context.WebServerApplicationContext;
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
Expand All @@ -38,12 +39,14 @@
* @author Andy Wilkinson
* @since 2.1.0
*/
public class TomcatMetricsBinder implements ApplicationListener<ApplicationStartedEvent> {
public class TomcatMetricsBinder implements ApplicationListener<ApplicationStartedEvent>, DisposableBean {

private final MeterRegistry meterRegistry;

private final Iterable<Tag> tags;

private volatile TomcatMetrics tomcatMetrics;

public TomcatMetricsBinder(MeterRegistry meterRegistry) {
this(meterRegistry, Collections.emptyList());
}
Expand All @@ -57,7 +60,8 @@ public TomcatMetricsBinder(MeterRegistry meterRegistry, Iterable<Tag> tags) {
public void onApplicationEvent(ApplicationStartedEvent event) {
ApplicationContext applicationContext = event.getApplicationContext();
Manager manager = findManager(applicationContext);
new TomcatMetrics(manager, this.tags).bindTo(this.meterRegistry);
this.tomcatMetrics = new TomcatMetrics(manager, this.tags);
this.tomcatMetrics.bindTo(this.meterRegistry);
}

private Manager findManager(ApplicationContext applicationContext) {
Expand All @@ -80,4 +84,9 @@ private Context findContext(TomcatWebServer tomcatWebServer) {
return null;
}

@Override
public void destroy() {
this.tomcatMetrics.close();
}

}

0 comments on commit 9933032

Please sign in to comment.