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  /**
25   * LessThanOrEqualToAttrEventTrigger
26   * <p> 
27   * Event trigger that polls a value of an MXBean attribute and
28   * checks if it is less than or equal to specified max value. 
29   * @param <TYPE> event trigger type 
30   */
31  public class LessThanOrEqualToAttrEventTrigger<TYPE extends Comparable<TYPE>> extends AttrEventTrigger<TYPE>
32  {
33      protected final TYPE _max;
34      
35      /* ------------------------------------------------------------ */
36      /**
37       * Construct event trigger and specify the MXBean attribute
38       * that will be polled by this event trigger as well as max
39       * value of the attribute.
40       * 
41       * @param objectName object name of an MBean to be polled
42       * @param attributeName name of an MBean attribute to be polled
43       * @param max maximum value of the attribute
44       * 
45       * @throws MalformedObjectNameException on bad object name
46       * @throws IllegalArgumentException on bad parameters
47       */
48      public LessThanOrEqualToAttrEventTrigger(String objectName, String attributeName, TYPE max)
49          throws MalformedObjectNameException, IllegalArgumentException
50      {
51          super(objectName,attributeName);
52          
53          if (max == null)
54              throw new IllegalArgumentException("Value cannot be null");
55  
56          _max = max;
57      }
58  
59      /* ------------------------------------------------------------ */
60      /**
61       * Compare the value of the MXBean attribute being polling
62       * to check if it is less than or equal to the max value.
63       * 
64       * @see org.eclipse.jetty.monitor.triggers.AttrEventTrigger#match(java.lang.Comparable)
65       */
66      @Override
67      public boolean match(Comparable<TYPE> value)
68      {
69          return (value.compareTo(_max) <= 0);
70      }
71  
72      /* ------------------------------------------------------------ */
73      /**
74       * Returns the string representation of this event trigger
75       * in the format "name&lt;=max". 
76       * 
77       * @return string representation of the event trigger
78       * 
79       * @see java.lang.Object#toString()
80       */
81      public String toString()
82      {
83          StringBuilder result = new StringBuilder();
84          
85          result.append(getNameString());
86          result.append("<=");
87          result.append(_max);
88          
89          return result.toString();
90      }
91  }