1
14
15 package com.liferay.portal.kernel.messaging.jmx;
16
17 import com.liferay.portal.kernel.messaging.Destination;
18 import com.liferay.portal.kernel.messaging.DestinationStatistics;
19
20 import javax.management.MalformedObjectNameException;
21 import javax.management.ObjectName;
22
23
30 public class DestinationStatisticsManager
31 implements DestinationStatisticsManagerMBean {
32
33 public static ObjectName createObjectName(String destinationName) {
34 try {
35 return new ObjectName(_OBJECT_NAME_PREFIX + destinationName);
36 }
37 catch (MalformedObjectNameException mone) {
38 throw new IllegalStateException(mone);
39 }
40 }
41
42 public DestinationStatisticsManager(Destination destination) {
43 _destination = destination;
44 }
45
46 public int getActiveThreadCount() {
47 if (_autoRefresh) {
48 refresh();
49 }
50
51 return _destinationStatistics.getActiveThreadCount();
52 }
53
54 public int getCurrentThreadCount() {
55 if (_autoRefresh || (_destinationStatistics == null)) {
56 refresh();
57 }
58
59 return _destinationStatistics.getCurrentThreadCount();
60 }
61
62 public int getLargestThreadCount() {
63 if (_autoRefresh || (_destinationStatistics == null)) {
64 refresh();
65 }
66
67 return _destinationStatistics.getLargestThreadCount();
68 }
69
70 public String getLastRefresh() {
71 return String.valueOf(_lastRefresh);
72 }
73
74 public int getMaxThreadPoolSize() {
75 if (_autoRefresh || (_destinationStatistics == null)) {
76 refresh();
77 }
78
79 return _destinationStatistics.getMaxThreadPoolSize();
80 }
81
82 public int getMinThreadPoolSize() {
83 if (_autoRefresh || (_destinationStatistics == null)) {
84 refresh();
85 }
86
87 return _destinationStatistics.getMinThreadPoolSize();
88 }
89
90 public long getPendingMessageCount() {
91 if (_autoRefresh || (_destinationStatistics == null)) {
92 refresh();
93 }
94
95 return _destinationStatistics.getPendingMessageCount();
96 }
97
98 public long getSentMessageCount() {
99 if (_autoRefresh || (_destinationStatistics == null)) {
100 refresh();
101 }
102
103 return _destinationStatistics.getSentMessageCount();
104 }
105
106 public boolean isAutoRefresh() {
107 return _autoRefresh;
108 }
109
110 public void refresh() {
111 if (System.currentTimeMillis() > _lastRefresh) {
112 _lastRefresh = System.currentTimeMillis();
113 _destinationStatistics = _destination.getDestinationStatistics();
114 }
115 }
116
117 public void setAutoRefresh(boolean autoRefresh) {
118 _autoRefresh = autoRefresh;
119 }
120
121 private static final String _OBJECT_NAME_PREFIX =
122 "Liferay:product=Portal,type=MessagingDestinationStatistics,name=";
123
124 private boolean _autoRefresh;
125 private Destination _destination;
126 private long _lastRefresh;
127 private DestinationStatistics _destinationStatistics;
128
129 }