View Javadoc

1   package org.apache.helix.monitoring.mbeans;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  
23  import java.util.Date;
24  
25  import org.apache.helix.alerts.AlertValueAndStatus;
26  
27  
28  public class ClusterAlertItem implements ClusterAlertItemMBean
29  {
30    String _alertItemName;
31    double  _alertValue;
32    int _alertFired;
33    String _additionalInfo = "";
34    AlertValueAndStatus _valueAndStatus;
35    long _lastUpdateTime = 0;
36    
37    public ClusterAlertItem(String name, AlertValueAndStatus valueAndStatus)
38    {
39      _valueAndStatus = valueAndStatus;
40      _alertItemName = name;
41      refreshValues();
42    }
43    @Override
44    public String getSensorName()
45    {
46      return _alertItemName;
47    }
48  
49    @Override
50    public double getAlertValue()
51    {
52      return _alertValue;
53    }
54    
55    public void setValueMap(AlertValueAndStatus valueAndStatus)
56    {
57      _valueAndStatus = valueAndStatus;
58      refreshValues();
59    }
60    
61    void refreshValues()
62    {
63      _lastUpdateTime = new Date().getTime();
64      if(_valueAndStatus.getValue().getElements().size() > 0)
65      {
66        _alertValue = Double.parseDouble(_valueAndStatus.getValue().getElements().get(0));
67      }
68      else
69      {
70        _alertValue = 0;
71      }
72      _alertFired = _valueAndStatus.isFired() ?  1 : 0;
73    }
74    @Override
75    public int getAlertFired()
76    {
77      return _alertFired;
78    }
79    
80    public void setAdditionalInfo(String additionalInfo)
81    {
82      _additionalInfo = additionalInfo;
83    }
84    
85    @Override
86    public String getAdditionalInfo()
87    {
88      return _additionalInfo;
89    }
90    
91    public void reset()
92    {
93      _alertFired = 0;
94      _additionalInfo = "";
95      _alertValue = 0;
96    }
97    
98    public long getLastUpdateTime()
99    {
100     return _lastUpdateTime;
101   }
102 }