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