KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > console > plugins > MonitorLister


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.console.plugins;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Set JavaDoc;
27
28 import javax.management.MBeanServer JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30
31 import org.jboss.console.manager.interfaces.ManageableResource;
32 import org.jboss.console.manager.interfaces.TreeNode;
33 import org.jboss.console.plugins.helpers.AbstractPluginWrapper;
34 import org.jboss.monitor.services.ActiveAlarmTableMBean;
35 import org.jboss.mx.util.InstanceOfQueryExp;
36 /**
37  * As the number of MBeans is very big, we use a real Java class which is far
38  * faster than beanshell
39  *
40  * @author <a HREF="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>.
41  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>.
42  * @version $Revision: 37459 $
43  */

44 public class MonitorLister
45    extends AbstractPluginWrapper
46 {
47    public MonitorLister () { super(); }
48
49    private TreeNode[] createMonitorSubNodes () throws Exception JavaDoc
50    {
51       MBeanServer JavaDoc mbeanServer = getMBeanServer();
52       InstanceOfQueryExp queryExp = null;
53       queryExp = new InstanceOfQueryExp("org.jboss.monitor.JBossMonitorMBean");
54       Set JavaDoc monitors = mbeanServer.queryNames(null, queryExp);
55       Iterator JavaDoc mbeans = monitors.iterator();;
56       
57       TreeNode[] result = null;
58       
59       ArrayList JavaDoc monitorNodes = new ArrayList JavaDoc ();
60
61       String JavaDoc emptySig[] = {};
62       Object JavaDoc emptyArgs[] = {};
63       while( mbeans.hasNext() )
64       {
65          ObjectName JavaDoc mbean = (ObjectName JavaDoc)mbeans.next();
66          String JavaDoc monitorName = (String JavaDoc)mbeanServer.getAttribute(mbean, "MonitorName");
67          boolean alerted = ((Boolean JavaDoc)mbeanServer.invoke(mbean, "alerted", emptyArgs, emptySig)).booleanValue();
68          //String image = alerted ? "images/red_bullet.gif" : "images/green_bullet.gif";
69
String JavaDoc image = "images/service.gif";
70          Object JavaDoc[] args = {"monitors", monitorName, "-service.xml"};
71          String JavaDoc[] signature = {"java.lang.String", "java.lang.String", "java.lang.String"};
72          Object JavaDoc rtn = mbeanServer.invoke(new ObjectName JavaDoc("jboss.admin:service=DeploymentFileRepository"), "isStored", args, signature);
73          boolean persisted = ((Boolean JavaDoc)rtn).booleanValue();
74          String JavaDoc url = "";
75          if (persisted)
76          {
77             url = "manageThresholdMonitor.jsp?monitorObjectName=" + encode(mbean.toString());
78          }
79          else
80          {
81             url = "/jmx-console/HtmlAdaptor?action=inspectMBean&name=" +encode(mbean.toString());
82          }
83          monitorNodes.add(createTreeNode (
84                monitorName, // name
85
"Alert Monitor " + monitorName, // description
86
image, // Icon URL
87
url, // Default URL
88
null, // menu
89
null, // sub nodes
90
null // Sub-Resources
91
)
92          );
93          
94       }
95       
96       if (monitorNodes.size() == 0)
97       {
98          result = null;
99       }
100       else
101       {
102          result = (TreeNode[]) monitorNodes.toArray(new TreeNode[monitorNodes.size()]);
103       }
104       
105       return result;
106    }
107    
108    private TreeNode[] createSnapshotSubNodes() throws Exception JavaDoc
109    {
110       MBeanServer JavaDoc mbeanServer = getMBeanServer();
111       InstanceOfQueryExp queryExp = null;
112       queryExp = new InstanceOfQueryExp("org.jboss.monitor.SnapshotRecordingMonitorMBean");
113       Set JavaDoc monitors = mbeanServer.queryNames(null, queryExp);
114       Iterator JavaDoc mbeans = monitors.iterator();;
115
116       TreeNode[] result = null;
117
118       ArrayList JavaDoc monitorNodes = new ArrayList JavaDoc ();
119
120       while( mbeans.hasNext() )
121       {
122          ObjectName JavaDoc mbean = (ObjectName JavaDoc)mbeans.next();
123          String JavaDoc monitorName = (String JavaDoc)mbeanServer.getAttribute(mbean, "MonitorName");
124          String JavaDoc url = "manageSnapshot.jsp?monitorObjectName=" + encode(mbean.toString());
125          String JavaDoc image = "images/service.gif";
126          monitorNodes.add(createTreeNode (
127                monitorName, // name
128
"Snapshot " + monitorName, // description
129
image, // Icon URL
130
url, // Default URL
131
null, // menu
132
null, // sub nodes
133
null // Sub-Resources
134
)
135          );
136
137       }
138
139       if (monitorNodes.size() == 0)
140       {
141          result = null;
142       }
143       else
144       {
145          result = (TreeNode[]) monitorNodes.toArray(new TreeNode[monitorNodes.size()]);
146       }
147
148       return result;
149    }
150
151    private TreeNode[] createWebSubNodes() throws Exception JavaDoc
152    {
153       TreeNode[] webSubNodes = new TreeNode[2];
154       
155       webSubNodes[0] = createTreeNode(
156             "Connector scoreboard", // name
157
"JBossWeb Connectors status scoreboard", // description
158
"images/smallnet.gif", // Icon URL
159
"status", // Default URL
160
null,
161             null, // sub nodes
162
null // Sub-Resources
163
);
164       webSubNodes[1] = createTreeNode(
165             "Full status", // name
166
"JBossWeb complete status", // description
167
"images/smallnet.gif", // Icon URL
168
"status?full=true", // Default URL
169
null,
170             null, // sub nodes
171
null // Sub-Resources
172
);
173      
174       return webSubNodes;
175    }
176    
177    protected TreeNode getTreeForResource(String JavaDoc profile, ManageableResource resource)
178    {
179       try
180       {
181          ArrayList JavaDoc subNodeList = new ArrayList JavaDoc();
182          
183          if (isActiveAlarmTablePresent())
184          {
185             subNodeList.add(createTreeNode(
186                   "Alarm Table", // name
187
"Alarm Table", // description
188
"images/smallnet.gif", // icon URL
189
"listActiveAlarmTable.jsp", // default URL
190
null,
191                   null, // sub-nodes
192
null // sub-resources
193
));
194          }
195          
196          subNodeList.add(createTreeNode(
197                "Monitor Alerts", // name
198
"Monitor Alerts", // description
199
"images/smallnet.gif", // Icon URL
200
"listMonitors.jsp", // Default URL
201
null,
202                createMonitorSubNodes(), // sub nodes
203
null // Sub-Resources
204
));
205          
206          subNodeList.add(createTreeNode(
207                "Snapshots", // name
208
"Snapshot Monitors", // description
209
"images/smallnet.gif", // Icon URL
210
null, // Default URL
211
null,
212                createSnapshotSubNodes(), // sub nodes
213
null // Sub-Resources
214
));
215          
216          subNodeList.add(createTreeNode(
217                "Web Status", // name
218
"JBossWeb Connectors status", // description
219
"images/smallnet.gif", // Icon URL
220
null, // Default URL
221
null,
222                createWebSubNodes(), // sub nodes
223
null // Sub-Resources
224
));
225          
226          // convert ArrayList to TreeNode[]
227
TreeNode[] subnodes = (TreeNode[]) subNodeList.toArray(new TreeNode[subNodeList.size()]);
228          
229          return createTreeNode (
230                "Monitoring", // name
231
"Monitoring", // description
232
"images/smallnet.gif", // Icon URL
233
null, // Default URL
234
null,
235                subnodes, // sub nodes
236
null // Sub-Resources
237
);
238       }
239       catch (Exception JavaDoc e)
240       {
241          e.printStackTrace ();
242          return null;
243       }
244    }
245    
246    private boolean isActiveAlarmTablePresent()
247    {
248       MBeanServer JavaDoc server = getMBeanServer();
249       return server.isRegistered(ActiveAlarmTableMBean.OBJECT_NAME);
250    }
251 }
252
Popular Tags