View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.monitor.triggers;
20  
21  import javax.management.MalformedObjectNameException;
22  
23  /**
24   * GreaterThanAttrEventTrigger
25   * <p> 
26   * Event trigger that polls a value of an MXBean attribute and
27   * checks if it is greater than specified min value. 
28   * @param <TYPE> event trigger type
29   */
30  public class GreaterThanAttrEventTrigger<TYPE extends Comparable<TYPE>> extends AttrEventTrigger<TYPE>
31  {
32      protected final TYPE _min;
33      
34      /* ------------------------------------------------------------ */
35      /**
36       * Construct event trigger and specify the MXBean attribute
37       * that will be polled by this event trigger as well as min
38       * value of the attribute.
39       * 
40       * @param objectName object name of an MBean to be polled
41       * @param attributeName name of an MBean attribute to be polled
42       * @param min minimum value of the attribute
43       * 
44       * @throws MalformedObjectNameException on bad object name
45       * @throws IllegalArgumentException on bad parameters
46       */
47      public GreaterThanAttrEventTrigger(String objectName, String attributeName, TYPE min)
48          throws MalformedObjectNameException, IllegalArgumentException
49      {
50          super(objectName,attributeName);
51          
52          if (min == null)
53              throw new IllegalArgumentException("Value cannot be null");
54  
55          _min = min;
56      }
57  
58      /* ------------------------------------------------------------ */
59      /**
60       * Compare the value of the MXBean attribute being polling
61       * to check if it is greater than the min value.
62       * 
63       * @see org.eclipse.jetty.monitor.triggers.AttrEventTrigger#match(java.lang.Comparable)
64       */
65      @Override
66      public boolean match(Comparable<TYPE> value)
67      {
68          return (value.compareTo(_min) > 0);
69      }
70  
71      /* ------------------------------------------------------------ */
72      /**
73       * Returns the string representation of this event trigger
74       * in the format "min&lt;name". 
75       * 
76       * @return string representation of the event trigger
77       * 
78       * @see java.lang.Object#toString()
79       */
80      public String toString()
81      {
82          StringBuilder result = new StringBuilder();
83          
84          result.append(_min);
85          result.append("<");
86          result.append(getNameString());
87         
88          return result.toString();
89      }
90  }