View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe.beans.stats.collectors;
12  
13  import javax.inject.Inject;
14  
15  import org.springframework.beans.factory.annotation.Value;
16  
17  import psiprobe.beans.ContainerListenerBean;
18  import psiprobe.model.Connector;
19  import psiprobe.tools.TimeExpression;
20  
21  /**
22   * The Class ConnectorStatsCollectorBean.
23   */
24  public class ConnectorStatsCollectorBean extends AbstractStatsCollectorBean {
25  
26    /** The listener bean. */
27    @Inject
28    private ContainerListenerBean listenerBean;
29  
30    /**
31     * Gets the listener bean.
32     *
33     * @return the listener bean
34     */
35    public ContainerListenerBean getListenerBean() {
36      return listenerBean;
37    }
38  
39    /**
40     * Sets the listener bean.
41     *
42     * @param listenerBean the new listener bean
43     */
44    public void setListenerBean(ContainerListenerBean listenerBean) {
45      this.listenerBean = listenerBean;
46    }
47  
48    @Override
49    public void collect() throws Exception {
50      for (Connector connector : listenerBean.getConnectors(false)) {
51        String statName = "stat.connector." + connector.getProtocolHandler();
52        buildDeltaStats(statName + ".requests", connector.getRequestCount());
53        buildDeltaStats(statName + ".errors", connector.getErrorCount());
54        buildDeltaStats(statName + ".sent", connector.getBytesSent());
55        buildDeltaStats(statName + ".received", connector.getBytesReceived());
56        buildDeltaStats(statName + ".proc_time", connector.getProcessingTime());
57      }
58    }
59  
60    /**
61     * Reset.
62     *
63     * @throws Exception the exception
64     */
65    public void reset() throws Exception {
66      for (Connector connector : listenerBean.getConnectors(false)) {
67        reset(connector.getProtocolHandler());
68      }
69    }
70  
71    /**
72     * Reset.
73     *
74     * @param connectorName the connector name
75     */
76    public void reset(String connectorName) {
77      String statName = "stat.connector." + connectorName;
78      resetStats(statName + ".requests");
79      resetStats(statName + ".errors");
80      resetStats(statName + ".sent");
81      resetStats(statName + ".received");
82      resetStats(statName + ".proc_time");
83    }
84  
85    /**
86     * Sets the max series expression.
87     *
88     * @param period the period
89     * @param span the span
90     */
91    public void setMaxSeries(
92        @Value("${psiprobe.beans.stats.collectors.connector.period}") long period,
93        @Value("${psiprobe.beans.stats.collectors.connector.span}") long span) {
94      super.setMaxSeries((int) TimeExpression.dataPoints(period, span));
95    }
96  
97  }