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   */
39  public class PortalManager implements PortalManagerMBean {
40  
41      public PortalManager(
42          ServerStatistics serverStatistics,
43          SummaryStatistics summaryStatistics) {
44  
45          _serverStatistics = serverStatistics;
46          _summaryStatistics = summaryStatistics;
47      }
48  
49      public long getAverageTime() throws MonitoringException {
50          return _summaryStatistics.getAverageTime();
51      }
52  
53      public long getAverageTimeByCompany(long companyId)
54          throws MonitoringException {
55  
56          return _summaryStatistics.getAverageTimeByCompany(companyId);
57      }
58  
59      public long getAverageTimeByCompany(String webId)
60          throws MonitoringException {
61  
62          return _summaryStatistics.getAverageTimeByCompany(webId);
63      }
64  
65      public long[] getCompanyIds() {
66          Set<Long> companyIds = _serverStatistics.getCompanyIds();
67  
68          return ArrayUtil.toArray(
69              companyIds.toArray(new Long[companyIds.size()]));
70      }
71  
72      public long getErrorCount() throws MonitoringException {
73          return _summaryStatistics.getErrorCount();
74      }
75  
76      public long getErrorCountByCompany(long companyId)
77          throws MonitoringException {
78  
79          return _summaryStatistics.getErrorCountByCompany(companyId);
80      }
81  
82      public long getErrorCountByCompany(String webId)
83          throws MonitoringException {
84  
85          return _summaryStatistics.getErrorCountByCompany(webId);
86      }
87  
88      public long getMaxTime() throws MonitoringException {
89          return _summaryStatistics.getMaxTime();
90      }
91  
92      public long getMaxTimeByCompany(long companyId) throws MonitoringException {
93          return _summaryStatistics.getMaxTimeByCompany(companyId);
94      }
95  
96      public long getMaxTimeByCompany(String webId) throws MonitoringException {
97          return _summaryStatistics.getMaxTimeByCompany(webId);
98      }
99  
100     public long getMinTime() throws MonitoringException {
101         return _summaryStatistics.getMinTime();
102     }
103 
104     public long getMinTimeByCompany(long companyId) throws MonitoringException {
105         return _summaryStatistics.getMinTimeByCompany(companyId);
106     }
107 
108     public long getMinTimeByCompany(String webId) throws MonitoringException {
109         return _summaryStatistics.getMinTimeByCompany(webId);
110     }
111 
112     public long getRequestCount() throws MonitoringException {
113         return _summaryStatistics.getRequestCount();
114     }
115 
116     public long getRequestCountByCompany(long companyId)
117         throws MonitoringException {
118 
119         return _summaryStatistics.getRequestCountByCompany(companyId);
120     }
121 
122     public long getRequestCountByCompany(String webId)
123         throws MonitoringException {
124 
125         return _summaryStatistics.getRequestCountByCompany(webId);
126     }
127 
128     public long getStartTime(long companyId) throws MonitoringException {
129         return _serverStatistics.getCompanyStatistics(companyId).getStartTime();
130     }
131 
132     public long getStartTime(String webId) throws MonitoringException {
133         return _serverStatistics.getCompanyStatistics(webId).getStartTime();
134     }
135 
136     public long getSuccessCount() throws MonitoringException {
137         return _summaryStatistics.getSuccessCount();
138     }
139 
140     public long getSuccessCountByCompany(long companyId)
141         throws MonitoringException {
142 
143         return _summaryStatistics.getSuccessCountByCompany(companyId);
144     }
145 
146     public long getSuccessCountByCompany(String webId)
147         throws MonitoringException {
148 
149         return _summaryStatistics.getSuccessCountByCompany(webId);
150     }
151 
152     public long getTimeoutCount() throws MonitoringException {
153         return _summaryStatistics.getTimeoutCount();
154     }
155 
156     public long getTimeoutCountByCompany(long companyId)
157         throws MonitoringException {
158 
159         return _summaryStatistics.getTimeoutCountByCompany(companyId);
160     }
161 
162     public long getTimeoutCountByCompany(String webId)
163         throws MonitoringException {
164 
165         return _summaryStatistics.getTimeoutCountByCompany(webId);
166     }
167 
168     public long getUptime(long companyId) throws MonitoringException {
169         return _serverStatistics.getCompanyStatistics(companyId).getUptime();
170     }
171 
172     public long getUptime(String webId) throws MonitoringException {
173         return _serverStatistics.getCompanyStatistics(webId).getUptime();
174     }
175 
176     public String[] getWebIds() {
177         Set<String> webIds = _serverStatistics.getWebIds();
178 
179         return webIds.toArray(new String[webIds.size()]);
180     }
181 
182     public void reset() {
183         _serverStatistics.reset();
184     }
185 
186     public void reset(long companyId) {
187         _serverStatistics.reset(companyId);
188     }
189 
190     public void reset(String webId) {
191         _serverStatistics.reset(webId);
192     }
193 
194     private ServerStatistics _serverStatistics;
195     private SummaryStatistics _summaryStatistics;
196 
197 }