1 // ========================================================================
2 // Copyright (c) Webtide LLC
3 // ------------------------------------------------------------------------
4 // All rights reserved. This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v1.0
6 // and Apache License v2.0 which accompanies this distribution.
7 // The Eclipse Public License is available at
8 // http://www.eclipse.org/legal/epl-v10.html
9 // The Apache License v2.0 is available at
10 // http://www.opensource.org/licenses/apache2.0.php
11 // You may elect to redistribute this code under either of these licenses.
12 // ========================================================================
13
14
15 package org.eclipse.jetty.monitor.triggers;
16
17 import javax.management.MalformedObjectNameException;
18
19
20 /* ------------------------------------------------------------ */
21 /**
22 * EqualToAttrEventTrigger
23 *
24 * Event trigger that polls a value of an MXBean attribute and
25 * checks if it is equal to specified value.
26 */
27 public class EqualToAttrEventTrigger<TYPE extends Comparable<TYPE>> extends AttrEventTrigger<TYPE>
28 {
29 protected final TYPE _value;
30
31 /* ------------------------------------------------------------ */
32 /**
33 * Construct event trigger and specify the MXBean attribute
34 * that will be polled by this event trigger as well as the
35 * target value of the attribute.
36 *
37 * @param objectName object name of an MBean to be polled
38 * @param attributeName name of an MBean attribute to be polled
39 * @param value target value of the attribute
40 *
41 * @throws MalformedObjectNameException
42 * @throws IllegalArgumentException
43 */
44 public EqualToAttrEventTrigger(String objectName, String attributeName, TYPE value)
45 throws MalformedObjectNameException, IllegalArgumentException
46 {
47 super(objectName,attributeName);
48
49 if (value == null)
50 throw new IllegalArgumentException("Value cannot be null");
51
52 _value = value;
53 }
54
55 /* ------------------------------------------------------------ */
56 /**
57 * Compare the value of the MXBean attribute being polling
58 * to check if it is equal to the specified value.
59 */
60 @Override
61 public boolean match(Comparable<TYPE> value)
62 {
63 return (value.compareTo(_value) == 0);
64 }
65
66 /* ------------------------------------------------------------ */
67 /**
68 * Returns the string representation of this event trigger
69 * in the format "name=value".
70 *
71 * @return string representation of the event trigger
72 *
73 * @see java.lang.Object#toString()
74 */
75 public String toString()
76 {
77 StringBuilder result = new StringBuilder();
78
79 result.append(getNameString());
80 result.append("==");
81 result.append(_value);
82
83 return result.toString();
84 }
85 }