1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jmonit.monitors;
17
18 import java.util.Collection;
19
20 import org.jmonit.Repository;
21 import org.jmonit.log.Log;
22 import org.jmonit.spi.Plugin;
23 import org.jmonit.spi.PluginManager;
24 import org.jmonit.spi.PluginManagerAware;
25 import org.jmonit.spi.RepositoryAware;
26
27
28
29
30
31
32
33 public class DefaultMonitor
34 extends AbstractMonitor
35 implements PluginManagerAware
36 {
37
38 private static Log log = Log.getLog( DefaultMonitor.class );
39
40 private PluginManager pluginManager;
41
42 private Repository repository;
43
44 public DefaultMonitor( String name, Repository repository )
45 {
46 super( name );
47 this.repository = repository;
48 }
49
50
51
52
53
54
55 public void setPluginManager( PluginManager manager )
56 {
57 this.pluginManager = manager;
58 }
59
60
61
62
63
64
65
66
67
68 @Override
69 public <T> T getFeature( Class<T> role )
70 {
71 T feature = super.getFeature( role );
72 if ( feature != null )
73 {
74 return feature;
75 }
76
77 if ( pluginManager != null )
78 {
79 if ( log.isDebugEnabled() )
80 {
81 log.debug( "enhance monitor " + getName() + " with feature " + role.getName() );
82 }
83 Plugin<T> plugin = pluginManager.getFactory( role ).newPluginInstance();
84 if ( plugin instanceof RepositoryAware )
85 {
86 ( (RepositoryAware) plugin ).setRepository( repository );
87 }
88 register( plugin, role );
89 return plugin.getFeature();
90 }
91 return null;
92 }
93
94
95
96
97
98
99 protected void onMonitorTaggedEvent( String tag )
100 {
101 if ( pluginManager != null )
102 {
103 Collection<Class> plugins = pluginManager.getFeatures( tag );
104 for ( Class feature : plugins )
105 {
106 getFeature( feature );
107 }
108 }
109 }
110 }