1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.monitoring.jmx;
24  
25  import com.liferay.portal.kernel.util.ArrayUtil;
26  import com.liferay.portal.monitoring.MonitoringException;
27  import com.liferay.portal.monitoring.statistics.SummaryStatistics;
28  import com.liferay.portal.monitoring.statistics.portal.ServerStatistics;
29  
30  import java.util.Set;
31  
32  /**
33   * <a href="PortalManager.java.html"><b><i>View Source</i></b></a>
34   *
35   * @author Michael C. Han
36   * @author Brian Wing Shun Chan
37   */
38  public class PortalManager implements PortalManagerMBean {
39  
40      public PortalManager(
41          ServerStatistics serverStatistics,
42          SummaryStatistics summaryStatistics) {
43  
44          _serverStatistics = serverStatistics;
45          _summaryStatistics = summaryStatistics;
46      }
47  
48      public long getAverageTime() throws MonitoringException {
49          return _summaryStatistics.getAverageTime();
50      }
51  
52      public long getAverageTimeByCompany(long companyId)
53          throws MonitoringException {
54  
55          return _summaryStatistics.getAverageTimeByCompany(companyId);
56      }
57  
58      public long getAverageTimeByCompany(String webId)
59          throws MonitoringException {
60  
61          return _summaryStatistics.getAverageTimeByCompany(webId);
62      }
63  
64      public long[] getCompanyIds() {
65          Set<Long> companyIds = _serverStatistics.getCompanyIds();
66  
67          return ArrayUtil.toArray(
68              companyIds.toArray(new Long[companyIds.size()]));
69      }
70  
71      public long getErrorCount() throws MonitoringException {
72          return _summaryStatistics.getErrorCount();
73      }
74  
75      public long getErrorCountByCompany(long companyId)
76          throws MonitoringException {
77  
78          return _summaryStatistics.getErrorCountByCompany(companyId);
79      }
80  
81      public long getErrorCountByCompany(String webId)
82          throws MonitoringException {
83  
84          return _summaryStatistics.getErrorCountByCompany(webId);
85      }
86  
87      public long getMaxTime() throws MonitoringException {
88          return _summaryStatistics.getMaxTime();
89      }
90  
91      public long getMaxTimeByCompany(long companyId) throws MonitoringException {
92          return _summaryStatistics.getMaxTimeByCompany(companyId);
93      }
94  
95      public long getMaxTimeByCompany(String webId) throws MonitoringException {
96          return _summaryStatistics.getMaxTimeByCompany(webId);
97      }
98  
99      public long getMinTime() throws MonitoringException {
100         return _summaryStatistics.getMinTime();
101     }
102 
103     public long getMinTimeByCompany(long companyId) throws MonitoringException {
104         return _summaryStatistics.getMinTimeByCompany(companyId);
105     }
106 
107     public long getMinTimeByCompany(String webId) throws MonitoringException {
108         return _summaryStatistics.getMinTimeByCompany(webId);
109     }
110 
111     public long getRequestCount() throws MonitoringException {
112         return _summaryStatistics.getRequestCount();
113     }
114 
115     public long getRequestCountByCompany(long companyId)
116         throws MonitoringException {
117 
118         return _summaryStatistics.getRequestCountByCompany(companyId);
119     }
120 
121     public long getRequestCountByCompany(String webId)
122         throws MonitoringException {
123 
124         return _summaryStatistics.getRequestCountByCompany(webId);
125     }
126 
127     public long getStartTime(long companyId) throws MonitoringException {
128         return _serverStatistics.getCompanyStatistics(companyId).getStartTime();
129     }
130 
131     public long getStartTime(String webId) throws MonitoringException {
132         return _serverStatistics.getCompanyStatistics(webId).getStartTime();
133     }
134 
135     public long getSuccessCount() throws MonitoringException {
136         return _summaryStatistics.getSuccessCount();
137     }
138 
139     public long getSuccessCountByCompany(long companyId)
140         throws MonitoringException {
141 
142         return _summaryStatistics.getSuccessCountByCompany(companyId);
143     }
144 
145     public long getSuccessCountByCompany(String webId)
146         throws MonitoringException {
147 
148         return _summaryStatistics.getSuccessCountByCompany(webId);
149     }
150 
151     public long getTimeoutCount() throws MonitoringException {
152         return _summaryStatistics.getTimeoutCount();
153     }
154 
155     public long getTimeoutCountByCompany(long companyId)
156         throws MonitoringException {
157 
158         return _summaryStatistics.getTimeoutCountByCompany(companyId);
159     }
160 
161     public long getTimeoutCountByCompany(String webId)
162         throws MonitoringException {
163 
164         return _summaryStatistics.getTimeoutCountByCompany(webId);
165     }
166 
167     public long getUptime(long companyId) throws MonitoringException {
168         return _serverStatistics.getCompanyStatistics(companyId).getUptime();
169     }
170 
171     public long getUptime(String webId) throws MonitoringException {
172         return _serverStatistics.getCompanyStatistics(webId).getUptime();
173     }
174 
175     public String[] getWebIds() {
176         Set<String> webIds = _serverStatistics.getWebIds();
177 
178         return webIds.toArray(new String[webIds.size()]);
179     }
180 
181     public void reset() {
182         _serverStatistics.reset();
183     }
184 
185     public void reset(long companyId) {
186         _serverStatistics.reset(companyId);
187     }
188 
189     public void reset(String webId) {
190         _serverStatistics.reset(webId);
191     }
192 
193     private ServerStatistics _serverStatistics;
194     private SummaryStatistics _summaryStatistics;
195 
196 }