Skip to content

Commit b897c94

Browse files
authored
Merge pull request #4963 from evolvedbinary/hotfix/jmx-tabular-data
Improve JMX output
2 parents eb14531 + 47157a2 commit b897c94

File tree

9 files changed

+145
-43
lines changed

9 files changed

+145
-43
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* eXist-db Open Source Native XML Database
3+
* Copyright (C) 2001 The eXist-db Authors
4+
*
5+
6+
* http://www.exist-db.org
7+
*
8+
* This library is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU Lesser General Public
10+
* License as published by the Free Software Foundation; either
11+
* version 2.1 of the License, or (at your option) any later version.
12+
*
13+
* This library is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
* Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public
19+
* License along with this library; if not, write to the Free Software
20+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21+
*/
22+
package org.exist.management.impl;
23+
24+
import javax.management.MalformedObjectNameException;
25+
import javax.management.ObjectName;
26+
27+
/**
28+
* Interface for all eXist-db provided MBeans.
29+
*/
30+
public interface ExistMBean {
31+
32+
/**
33+
* Get the name of the MBean.
34+
*
35+
* @return the name of the mbean.
36+
*
37+
* @throws MalformedObjectNameException if the name cannot be constructed.
38+
*/
39+
ObjectName getName() throws MalformedObjectNameException;
40+
}

exist-core/src/main/java/org/exist/management/impl/JMXAgent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public JMXAgent() {
7070

7171
private void registerSystemMBeans() {
7272
try {
73-
addMBean(new ObjectName(SystemInfo.OBJECT_NAME), new org.exist.management.impl.SystemInfo());
73+
final SystemInfoMXBean systemInfoMXBean = new org.exist.management.impl.SystemInfo();
74+
addMBean(systemInfoMXBean.getName(), systemInfoMXBean);
7475
} catch (final MalformedObjectNameException | DatabaseConfigurationException e) {
7576
LOG.warn("Exception while registering cache mbean.", e);
7677
}

exist-core/src/main/java/org/exist/management/impl/PerInstanceMBean.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222

2323
package org.exist.management.impl;
2424

25-
import javax.management.MalformedObjectNameException;
26-
import javax.management.ObjectName;
27-
28-
public interface PerInstanceMBean {
25+
public interface PerInstanceMBean extends ExistMBean {
2926
String getInstanceId();
30-
ObjectName getName() throws MalformedObjectNameException;
3127
}

exist-core/src/main/java/org/exist/management/impl/ProcessReport.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
*/
2222
package org.exist.management.impl;
2323

24-
import java.util.ArrayList;
2524
import java.util.List;
25+
import java.util.Map;
26+
import java.util.HashMap;
27+
import java.util.TreeMap;
2628

2729
import org.exist.scheduler.ScheduledJobInfo;
2830
import org.exist.scheduler.Scheduler;
@@ -66,30 +68,30 @@ public String getInstanceId() {
6668
}
6769

6870
@Override
69-
public List<Job> getScheduledJobs() {
70-
final List<Job> jobList = new ArrayList<>();
71+
public Map<String, Job> getScheduledJobs() {
72+
final Map<String, Job> jobList = new HashMap<>();
7173

7274
final List<ScheduledJobInfo> jobs = scheduler.getScheduledJobs();
7375
for (final ScheduledJobInfo job : jobs) {
74-
jobList.add(new Job(job.getName(), job.getGroup(), job.getTriggerExpression()));
76+
jobList.put(job.getName(), new Job(job.getName(), job.getGroup(), job.getTriggerExpression()));
7577
}
7678
return jobList;
7779
}
7880

7981
@Override
80-
public List<Job> getRunningJobs() {
81-
final List<Job> jobList = new ArrayList<>();
82+
public Map<String, Job> getRunningJobs() {
83+
final Map<String, Job> jobList = new HashMap<>();
8284

8385
final ProcessMonitor.JobInfo[] jobs = processMonitor.runningJobs();
8486
for (final ProcessMonitor.JobInfo job : jobs) {
85-
jobList.add(new Job(job.getThread().getName(), job.getAction(), job.getAddInfo().toString()));
87+
jobList.put(job.getThread().getName(), new Job(job.getThread().getName(), job.getAction(), job.getAddInfo().toString()));
8688
}
8789
return jobList;
8890
}
8991

9092
@Override
91-
public List<RunningQuery> getRunningQueries() {
92-
final List<RunningQuery> queries = new ArrayList<>();
93+
public Map<QueryKey, RunningQuery> getRunningQueries() {
94+
final Map<QueryKey, RunningQuery> queries = new TreeMap<>();
9395

9496
final XQueryWatchDog[] watchdogs = processMonitor.getRunningXQueries();
9597
for (final XQueryWatchDog watchdog : watchdogs) {
@@ -98,7 +100,8 @@ public List<RunningQuery> getRunningQueries() {
98100
requestURI = ProcessMonitor.getRequestURI(watchdog);
99101
}
100102

101-
queries.add(new RunningQuery(watchdog, requestURI));
103+
final RunningQuery runningQuery = new RunningQuery(watchdog, requestURI);
104+
queries.put(new QueryKey(runningQuery.getId(), runningQuery.getSourceKey()), runningQuery);
102105
}
103106
return queries;
104107
}
@@ -119,12 +122,12 @@ public void killQuery(final int id) {
119122
}
120123

121124
@Override
122-
public List<RecentQueryHistory> getRecentQueryHistory() {
123-
final List<RecentQueryHistory> history = new ArrayList<>();
125+
public Map<QueryKey, RecentQueryHistory> getRecentQueryHistory() {
126+
final Map<QueryKey, RecentQueryHistory> history = new TreeMap<>();
124127
final QueryHistory[] queryHistories = processMonitor.getRecentQueryHistory();
125-
int i = 0;
126-
for (final QueryHistory queryHistory : queryHistories) {
127-
history.add(new RecentQueryHistory(i++, queryHistory));
128+
for (int i = 0; i < queryHistories.length; i++) {
129+
final QueryHistory queryHistory = queryHistories[i];
130+
history.put(new QueryKey(i, queryHistory.getSource()), new RecentQueryHistory(i, queryHistory));
128131
}
129132
return history;
130133
}

exist-core/src/main/java/org/exist/management/impl/ProcessReportMXBean.java

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@
2121
*/
2222
package org.exist.management.impl;
2323

24-
import java.util.List;
24+
import java.util.Map;
2525

2626
public interface
2727
ProcessReportMXBean extends PerInstanceMBean {
2828

29-
List<Job> getScheduledJobs();
29+
Map<String, Job> getScheduledJobs();
3030

31-
List<Job> getRunningJobs();
31+
Map<String, Job> getRunningJobs();
3232

33-
List<RunningQuery> getRunningQueries();
33+
Map<QueryKey, RunningQuery> getRunningQueries();
3434

35-
List<RecentQueryHistory> getRecentQueryHistory();
35+
Map<QueryKey, RecentQueryHistory> getRecentQueryHistory();
3636

3737
void killQuery(int id);
3838

@@ -77,4 +77,54 @@
7777
void setTrackRequestURI(boolean track);
7878

7979
boolean getTrackRequestURI();
80+
81+
class QueryKey implements Comparable<QueryKey> {
82+
private final int id;
83+
private final String key;
84+
85+
public QueryKey(final int id, final String key) {
86+
this.id = id;
87+
this.key = key;
88+
}
89+
90+
public int getId() {
91+
return id;
92+
}
93+
94+
public String getKey() {
95+
return key;
96+
}
97+
98+
@Override
99+
public boolean equals(final Object other) {
100+
if (this == other) {
101+
return true;
102+
}
103+
if (other == null || getClass() != other.getClass()) {
104+
return false;
105+
}
106+
107+
QueryKey queryKey = (QueryKey) other;
108+
if (id != queryKey.id) {
109+
return false;
110+
}
111+
return key.equals(queryKey.key);
112+
}
113+
114+
@Override
115+
public int hashCode() {
116+
int result = id;
117+
result = 31 * result + key.hashCode();
118+
return result;
119+
}
120+
121+
@Override
122+
public int compareTo(final QueryKey other) {
123+
if (other == null) {
124+
return 1;
125+
}
126+
127+
return key.compareTo(other.key);
128+
}
129+
}
80130
}

exist-core/src/main/java/org/exist/management/impl/RecentQueryHistory.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
*/
3030
public class RecentQueryHistory {
3131

32-
private int idx;
33-
private String sourceKey;
34-
private int recentInvocationCount;
35-
private long mostRecentExecutionTime;
36-
private long mostRecentExecutionDuration;
37-
private String requestURI;
32+
private final int idx;
33+
private final String sourceKey;
34+
private final int recentInvocationCount;
35+
private final long mostRecentExecutionTime;
36+
private final long mostRecentExecutionDuration;
37+
private final String requestURI;
3838

39-
public RecentQueryHistory(int idx, ProcessMonitor.QueryHistory queryHistory) {
39+
public RecentQueryHistory(final int idx, final ProcessMonitor.QueryHistory queryHistory) {
4040
this.idx = idx;
4141
this.sourceKey = queryHistory.getSource();
4242
this.recentInvocationCount = queryHistory.getInvocationCount();

exist-core/src/main/java/org/exist/management/impl/RunningQuery.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
*/
3030
public class RunningQuery {
3131

32-
int id;
33-
String sourceType;
34-
String sourceKey;
35-
boolean terminating;
36-
String requestURI;
37-
String thread;
38-
long elapsed;
32+
private final int id;
33+
private final String sourceType;
34+
private final String sourceKey;
35+
private final boolean terminating;
36+
private final String requestURI;
37+
private final String thread;
38+
private final long startTime;
3939

4040
public RunningQuery(final XQueryWatchDog watchdog, final String requestURI) {
4141
this.id = watchdog.getContext().hashCode();
@@ -44,7 +44,7 @@ public RunningQuery(final XQueryWatchDog watchdog, final String requestURI) {
4444
this.terminating = watchdog.isTerminating();
4545
this.requestURI = requestURI;
4646
this.thread = watchdog.getRunningThread();
47-
this.elapsed = System.currentTimeMillis() - watchdog.getStartTime();
47+
this.startTime = watchdog.getStartTime();
4848
}
4949

5050
public int getId() {
@@ -71,7 +71,11 @@ public String getThread() {
7171
return thread;
7272
}
7373

74+
public long getStartTime() {
75+
return startTime;
76+
}
77+
7478
public long getElapsed() {
75-
return elapsed;
79+
return System.currentTimeMillis() - startTime;
7680
}
7781
}

exist-core/src/main/java/org/exist/management/impl/SystemInfo.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626

2727
import org.exist.SystemProperties;
2828

29+
import javax.management.MalformedObjectNameException;
30+
import javax.management.ObjectName;
31+
2932
/**
3033
* Class SystemInfo
3134
*
@@ -36,6 +39,11 @@ public class SystemInfo implements SystemInfoMXBean {
3639

3740
public static final String OBJECT_NAME = "org.exist.management:type=SystemInfo";
3841

42+
@Override
43+
public ObjectName getName() throws MalformedObjectNameException {
44+
return new ObjectName(OBJECT_NAME);
45+
}
46+
3947
@Override
4048
public String getProductName() {
4149
return SystemProperties.getInstance().getSystemProperty("product-name","eXist");

exist-core/src/main/java/org/exist/management/impl/SystemInfoMXBean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* @author wessels
2828
* @author ljo
2929
*/
30-
public interface SystemInfoMXBean {
30+
public interface SystemInfoMXBean extends ExistMBean {
3131
String getProductName();
3232

3333
String getProductVersion();

0 commit comments

Comments
 (0)