KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > webapp > jonasadmin > service > jms > PresentQueueAction


1 /*
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: PresentQueueAction.java,v 1.4 2004/03/19 14:31:48 sauthieg Exp $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.jonas.webapp.jonasadmin.service.jms;
27
28 import java.io.IOException JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Collections JavaDoc;
31
32 import javax.management.ObjectName JavaDoc;
33 import javax.servlet.ServletException JavaDoc;
34 import javax.servlet.http.HttpServletRequest JavaDoc;
35 import javax.servlet.http.HttpServletResponse JavaDoc;
36
37 import org.apache.struts.action.ActionForm;
38 import org.apache.struts.action.ActionForward;
39 import org.apache.struts.action.ActionMapping;
40 import org.objectweb.jonas.jmx.JonasManagementRepr;
41 import org.objectweb.jonas.jmx.JonasObjectName;
42 import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
43 import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
44 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
45 import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
46
47 /**
48  * Action presenting a given JMS Queue destination's attributes.
49  * @author Adriana Danes
50  */

51 public class PresentQueueAction extends JonasBaseAction {
52     /**
53      */

54     public ActionForward executeAction(ActionMapping p_Mapping, ActionForm p_Form
55         , HttpServletRequest JavaDoc p_Request, HttpServletResponse JavaDoc p_Response)
56         throws IOException JavaDoc, ServletException JavaDoc {
57
58         // Selected queue
59
String JavaDoc queueName = p_Request.getParameter("name");
60
61         // Form used
62
QueueForm oForm = null;
63         if (queueName != null) {
64             // Build a new form
65
oForm = new QueueForm();
66             oForm.reset(p_Mapping, p_Request);
67             m_Session.setAttribute("queueForm", oForm);
68             oForm.setName(queueName);
69         }
70         else {
71             // Used last form in session
72
oForm = (QueueForm) m_Session.getAttribute("queueForm");
73         }
74
75         // Force the node selected in tree
76
m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER) + WhereAreYou.NODE_SEPARATOR
77             + "services" + WhereAreYou.NODE_SEPARATOR + "jms" + WhereAreYou.NODE_SEPARATOR
78             + "queue" + WhereAreYou.NODE_SEPARATOR + oForm.getName(), true);
79
80         // Populuate
81
try {
82             if (queueName != null) {
83                 // set UsedBy
84
ArrayList JavaDoc al = new ArrayList JavaDoc();
85                 String JavaDoc[] asParam = new String JavaDoc[1];
86                 String JavaDoc[] asSignature = new String JavaDoc[1];
87                 asSignature[0] = "java.lang.String";
88                 asParam[0] = queueName;
89                 ObjectName JavaDoc ejbServiceMB = JonasObjectName.ejbService();
90                 if (JonasManagementRepr.isRegistered(ejbServiceMB)) {
91                     java.util.Iterator JavaDoc it = ((java.util.Set JavaDoc) JonasManagementRepr.invoke(
92                         ejbServiceMB, "getJmsDestinationDependence", asParam
93                         , asSignature)).iterator();
94                     while (it.hasNext()) {
95                         al.add(new EjbItem((ObjectName JavaDoc) it.next()));
96                     }
97                     // Sort by name
98
Collections.sort(al, new EjbItemByNameComparator());
99                 }
100                 // Set list in form
101
oForm.setListUsedByEjb(al);
102
103                 // Set monitoting info
104
ObjectName JavaDoc jmsServiceMB = JonasObjectName.jmsService();
105                 int pendigMessages = ((Integer JavaDoc) JonasManagementRepr.invoke(jmsServiceMB
106                     , "getPendingMessages", asParam, asSignature)).intValue();
107                 oForm.setPendingMessages(pendigMessages);
108                 int pendingRequests = ((Integer JavaDoc) JonasManagementRepr.invoke(jmsServiceMB
109                     , "getPendingRequests", asParam, asSignature)).intValue();
110                 oForm.setPendingRequests(pendingRequests);
111             }
112         }
113         catch (Throwable JavaDoc t) {
114             addGlobalError(t);
115             saveErrors(p_Request, m_Errors);
116             return (p_Mapping.findForward("Global Error"));
117         }
118
119         // Forward to the jsp.
120
return (p_Mapping.findForward("Queue"));
121     }
122 }
123
Popular Tags