1 // 2 // ======================================================================== 3 // Copyright (c) 1995-2013 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 20 package org.eclipse.jetty.monitor.triggers; 21 22 import javax.management.MalformedObjectNameException; 23 24 25 /* ------------------------------------------------------------ */ 26 /** 27 * RangeInclAttrEventTrigger 28 * 29 * Event trigger that polls a value of an MXBean attribute and 30 * checks if it is in a range from specified min value to 31 * specified max value including the range bounds. 32 */ 33 public class RangeInclAttrEventTrigger<TYPE extends Comparable<TYPE>> extends AttrEventTrigger<TYPE> 34 { 35 protected final TYPE _min; 36 protected final TYPE _max; 37 38 /* ------------------------------------------------------------ */ 39 /** 40 * Construct event trigger and specify the MXBean attribute 41 * that will be polled by this event trigger as well as min 42 * and max value of the attribute. 43 * 44 * @param objectName object name of an MBean to be polled 45 * @param attributeName name of an MBean attribute to be polled 46 * @param min minimum value of the attribute 47 * @param max maximum value of the attribute 48 * 49 * @throws MalformedObjectNameException 50 * @throws IllegalArgumentException 51 */ 52 public RangeInclAttrEventTrigger(String objectName, String attributeName,TYPE min, TYPE max) 53 throws MalformedObjectNameException, IllegalArgumentException 54 { 55 super(objectName,attributeName); 56 57 if (min == null) 58 throw new IllegalArgumentException("Value cannot be null"); 59 if (max == null) 60 throw new IllegalArgumentException("Value cannot be null"); 61 62 _min = min; 63 _max = max; 64 } 65 66 /* ------------------------------------------------------------ */ 67 /** 68 * Compare the value of the MXBean attribute being polling 69 * to check if it is in a range from specified min value to 70 * specified max value including the range bounds. 71 * 72 * @see org.eclipse.jetty.monitor.triggers.AttrEventTrigger#match(java.lang.Comparable) 73 */ 74 @Override 75 public boolean match(Comparable<TYPE> value) 76 { 77 return (value.compareTo(_min) >= 0) &&(value.compareTo(_max) <= 0); 78 } 79 80 /* ------------------------------------------------------------ */ 81 /** 82 * Returns the string representation of this event trigger 83 * in the format "min<=name<=max". 84 * 85 * @return string representation of the event trigger 86 * 87 * @see java.lang.Object#toString() 88 */ 89 public String toString() 90 { 91 StringBuilder result = new StringBuilder(); 92 93 result.append(_min); 94 result.append("<="); 95 result.append(getNameString()); 96 result.append("<="); 97 result.append(_max); 98 99 return result.toString(); 100 } 101 }