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