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