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 package org.eclipse.jetty.monitor.triggers;
20
21 import javax.management.MalformedObjectNameException;
22
23
24 /* ------------------------------------------------------------ */
25 /**
26 * GreaterThanAttrEventTrigger
27 *
28 * Event trigger that polls a value of an MXBean attribute and
29 * checks if it is greater than specified min value.
30 */
31 public class GreaterThanAttrEventTrigger<TYPE extends Comparable<TYPE>> extends AttrEventTrigger<TYPE>
32 {
33 protected final TYPE _min;
34
35 /* ------------------------------------------------------------ */
36 /**
37 * Construct event trigger and specify the MXBean attribute
38 * that will be polled by this event trigger as well as min
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 min minimum value of the attribute
44 *
45 * @throws MalformedObjectNameException
46 * @throws IllegalArgumentException
47 */
48 public GreaterThanAttrEventTrigger(String objectName, String attributeName, TYPE min)
49 throws MalformedObjectNameException, IllegalArgumentException
50 {
51 super(objectName,attributeName);
52
53 if (min == null)
54 throw new IllegalArgumentException("Value cannot be null");
55
56 _min = min;
57 }
58
59 /* ------------------------------------------------------------ */
60 /**
61 * Compare the value of the MXBean attribute being polling
62 * to check if it is greater than the min 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(_min) > 0);
70 }
71
72 /* ------------------------------------------------------------ */
73 /**
74 * Returns the string representation of this event trigger
75 * in the format "min<name".
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(_min);
86 result.append("<");
87 result.append(getNameString());
88
89 return result.toString();
90 }
91 }