Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix 2 Bugs in twitter4j mbean support.

1) Accumulate stats based on twitter method name, instead of full URL.
2) Give the mbean a reference to the same APIStatistics instance that
   is used by methodCalled() to calculate stats (instead of a local
   APIStatistics instance that nothing else has access to, which causes
   the mbean to report 0's for all stats).
  • Loading branch information...
commit 219c8b36fd5f1782808222d98db32e3bc947088d 1 parent e6aa1b2
@jkasnicki jkasnicki authored
Showing with 5 additions and 6 deletions.
  1. +5 −6 twitter4j-core/src/main/java/twitter4j/TwitterAPIMonitor.java
View
11 twitter4j-core/src/main/java/twitter4j/TwitterAPIMonitor.java
@@ -44,11 +44,11 @@
// https?:\/\/[^\/]+\/([a-zA-Z_\.]*).*
// finds the "method" part a Twitter REST API url, ignoring member-specific resource names
private static final Pattern pattern =
- Pattern.compile("https?:\\/\\/[^\\/]+\\/([a-zA-Z_\\.]*).*");
+ Pattern.compile("https?:\\/\\/[^\\/]+\\/\\d+\\/([a-zA-Z_\\.]*).*");
private static final TwitterAPIMonitor SINGLETON = new TwitterAPIMonitor();
- private final APIStatistics STATISTICS = new APIStatistics(100);
+ private static final APIStatistics STATISTICS = new APIStatistics(100);
static {
@@ -70,13 +70,12 @@
try {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
- APIStatistics statsMBean = new APIStatistics(100);
if (isJDK14orEarlier) {
ObjectName oName = new ObjectName("twitter4j.mbean:type=APIStatistics");
- mbs.registerMBean(statsMBean, oName);
+ mbs.registerMBean(STATISTICS, oName);
} else {
ObjectName oName = new ObjectName("twitter4j.mbean:type=APIStatisticsOpenMBean");
- APIStatisticsOpenMBean openMBean = new APIStatisticsOpenMBean(statsMBean);
+ APIStatisticsOpenMBean openMBean = new APIStatisticsOpenMBean(STATISTICS);
mbs.registerMBean(openMBean, oName);
}
} catch (InstanceAlreadyExistsException e) {
@@ -111,7 +110,7 @@ public APIStatisticsMBean getStatistics() {
void methodCalled(String twitterUrl, long elapsedTime, boolean success) {
Matcher matcher = pattern.matcher(twitterUrl);
if (matcher.matches() && matcher.groupCount() > 0) {
- String method = matcher.group();
+ String method = matcher.group(1);
STATISTICS.methodCalled(method, elapsedTime, success);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.