View Javadoc

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