View Javadoc

1   /*
2    ~ Copyright 2006-2007 Nicolas De Loof.
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 org.jmonit.monitors;
17  
18  import java.util.Collections;
19  import java.util.Set;
20  
21  import org.jmonit.Monitor;
22  import org.jmonit.events.MonitoringEvent;
23  
24  /**
25   * A convenience stub for testing purpose or to disable monitoring without
26   * breaking the application.
27   * 
28   * @author <a href="mailto:nicolas.deloof@gmail.com">Nicolas De Loof</a>
29   */
30  public class NullMonitor
31      implements Monitor
32  {
33  
34      private String name;
35  
36      public NullMonitor( String name )
37      {
38          super();
39          this.name = name;
40      }
41  
42      /**
43       * {@inheritDoc}
44       * 
45       * @see org.jmonit.Monitor#add(long)
46       */
47      public void add( long value )
48      {
49          // ignored
50      }
51  
52      /**
53       * {@inheritDoc}
54       * 
55       * @see org.jmonit.Monitor#clear()
56       */
57      public void clear()
58      {
59          // ignored
60      }
61  
62      /**
63       * {@inheritDoc}
64       * 
65       * @see org.jmonit.Monitor#fireEvent(org.jmonit.events.MonitoringEvent)
66       */
67      public void fireMonitoringEvent( MonitoringEvent event )
68      {
69          // ignored
70      }
71  
72      /**
73       * {@inheritDoc}
74       * 
75       * @see org.jmonit.Monitor#getFeature(java.lang.Class)
76       */
77      public <T> T getFeature( Class<T> feature )
78      {
79          try
80          {
81              return feature.newInstance();
82          }
83          catch ( Exception e )
84          {
85              return null;
86          }
87      }
88  
89      /**
90       * {@inheritDoc}
91       * 
92       * @see org.jmonit.Monitor#getFeatures()
93       */
94      public Set<Class> getFeatures()
95      {
96          return Collections.EMPTY_SET;
97      }
98  
99      /**
100      * {@inheritDoc}
101      * 
102      * @see org.jmonit.Monitor#getName()
103      */
104     public String getName()
105     {
106         return name;
107     }
108 
109     /**
110      * {@inheritDoc}
111      * 
112      * @see org.jmonit.Monitor#getTags()
113      */
114     public Set<String> getTags()
115     {
116         return Collections.EMPTY_SET;
117     }
118 
119     /**
120      * {@inheritDoc}
121      * 
122      * @see org.jmonit.Monitor#hasFeatures(java.lang.Class[])
123      */
124     public boolean hasFeatures( Class[] features )
125     {
126         return false;
127     }
128 
129     /**
130      * {@inheritDoc}
131      * 
132      * @see org.jmonit.Monitor#isFeatureSupported(java.lang.Class)
133      */
134     public boolean isFeatureSupported( Class clazz )
135     {
136         return false;
137     }
138 
139     /**
140      * {@inheritDoc}
141      * 
142      * @see org.jmonit.Monitor#isTagged(java.lang.String)
143      */
144     public boolean isTagged( String tag )
145     {
146         return false;
147     }
148 
149     /**
150      * {@inheritDoc}
151      * 
152      * @see org.jmonit.Monitor#monitor(long, java.lang.Object)
153      */
154     public void monitor( long value, Object context )
155     {
156         // ignored
157     }
158 
159     /**
160      * {@inheritDoc}
161      * 
162      * @see org.jmonit.Monitor#tag(java.lang.String)
163      */
164     public Monitor tag( String tag )
165     {
166         return this;
167     }
168 
169 }