View Javadoc

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