View Javadoc

1   /*
2    *  Copyright 2010 Felix Roethenbacher
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package ch.syabru.nagios.broker.jmx;
17  
18  import javax.management.Notification;
19  
20  import org.apache.commons.lang.builder.ToStringBuilder;
21  
22  import ch.syabru.nagios.broker.Message;
23  
24  /**
25   * JMX message implementation.
26   *
27   * @author Felix Roethenbacher
28   *
29   */
30  public class JmxMessage implements Message {
31  
32      private String className;
33      private String message;
34      private String type;
35      private String source;
36  
37      /**
38       * Create a message from a JMX notification.
39       * @param notification JMX notification.
40       */
41      public JmxMessage(Notification notification) {
42          this.className = notification.getClass().getName();
43          this.message = notification.getMessage();
44          this.type = notification.getType();
45          this.source = notification.getSource().toString();
46      }
47  
48      @Override
49      public String getClassName() {
50          return className;
51      }
52  
53      @Override
54      public String getMessage() {
55          return message;
56      }
57  
58      @Override
59      public String getType() {
60          return type;
61      }
62  
63      @Override
64      public String getSource() {
65          return source;
66      }
67  
68      @Override
69      public String toString() {
70          return new ToStringBuilder(this)
71                  .append("className", className)
72                  .append("message", message)
73                  .append("type", type)
74                  .append("source", source).toString();
75      }
76  }