001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: PresentQueueAction.java 9680 2006-10-06 12:08:33Z danesa $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.webapp.jonasadmin.service.jms;
027:
028: import java.io.IOException;
029: import java.util.ArrayList;
030: import java.util.Collections;
031:
032: import javax.management.ObjectName;
033: import javax.servlet.ServletException;
034: import javax.servlet.http.HttpServletRequest;
035: import javax.servlet.http.HttpServletResponse;
036:
037: import org.apache.struts.action.ActionForm;
038: import org.apache.struts.action.ActionForward;
039: import org.apache.struts.action.ActionMapping;
040: import org.objectweb.jonas.jmx.JonasManagementRepr;
041: import org.objectweb.jonas.jmx.JonasObjectName;
042: import org.objectweb.jonas.webapp.jonasadmin.JonasBaseAction;
043: import org.objectweb.jonas.webapp.jonasadmin.WhereAreYou;
044: import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItem;
045: import org.objectweb.jonas.webapp.jonasadmin.service.ejb.EjbItemByNameComparator;
046:
047: /**
048: * Action presenting a given JMS Queue destination's attributes.
049: * @author Adriana Danes
050: */
051: public class PresentQueueAction extends JonasBaseAction {
052: /**
053: */
054: public ActionForward executeAction(ActionMapping p_Mapping,
055: ActionForm p_Form, HttpServletRequest p_Request,
056: HttpServletResponse p_Response) throws IOException,
057: ServletException {
058:
059: // Selected queue
060: String queueName = p_Request.getParameter("name");
061:
062: // Form used
063: QueueForm oForm = null;
064: if (queueName != null) {
065: // Build a new form
066: oForm = new QueueForm();
067: oForm.reset(p_Mapping, p_Request);
068: m_Session.setAttribute("queueForm", oForm);
069: oForm.setName(queueName);
070: } else {
071: // Used last form in session
072: oForm = (QueueForm) m_Session.getAttribute("queueForm");
073: }
074:
075: // Force the node selected in tree
076: m_WhereAreYou.selectNameNode(getTreeBranchName(DEPTH_SERVER)
077: + WhereAreYou.NODE_SEPARATOR + "services"
078: + WhereAreYou.NODE_SEPARATOR + "jms"
079: + WhereAreYou.NODE_SEPARATOR + "queue"
080: + WhereAreYou.NODE_SEPARATOR + oForm.getName(), true);
081:
082: // Current server
083: WhereAreYou oWhere = (WhereAreYou) p_Request.getSession()
084: .getAttribute(WhereAreYou.SESSION_NAME);
085: String jonasServerName = oWhere.getCurrentJonasServerName();
086:
087: // Populuate
088: try {
089: if (queueName != null) {
090: // set UsedBy
091: ArrayList al = new ArrayList();
092: String[] asParam = new String[1];
093: String[] asSignature = new String[1];
094: asSignature[0] = "java.lang.String";
095: asParam[0] = queueName;
096: ObjectName ejbServiceMB = JonasObjectName.ejbService();
097: if (JonasManagementRepr.isRegistered(ejbServiceMB,
098: jonasServerName)) {
099: java.util.Iterator it = ((java.util.Set) JonasManagementRepr
100: .invoke(ejbServiceMB,
101: "getJmsDestinationDependence",
102: asParam, asSignature,
103: jonasServerName)).iterator();
104: while (it.hasNext()) {
105: al.add(new EjbItem((ObjectName) it.next(),
106: jonasServerName));
107: }
108: // Sort by name
109: Collections.sort(al, new EjbItemByNameComparator());
110: }
111: // Set list in form
112: oForm.setListUsedByEjb(al);
113:
114: // Set monitoting info
115: ObjectName jmsServiceMB = JonasObjectName.jmsService();
116: int pendigMessages = ((Integer) JonasManagementRepr
117: .invoke(jmsServiceMB, "getPendingMessages",
118: asParam, asSignature, jonasServerName))
119: .intValue();
120: oForm.setPendingMessages(pendigMessages);
121: int pendingRequests = ((Integer) JonasManagementRepr
122: .invoke(jmsServiceMB, "getPendingRequests",
123: asParam, asSignature, jonasServerName))
124: .intValue();
125: oForm.setPendingRequests(pendingRequests);
126: }
127: } catch (Throwable t) {
128: addGlobalError(t);
129: saveErrors(p_Request, m_Errors);
130: return (p_Mapping.findForward("Global Error"));
131: }
132:
133: // Forward to the jsp.
134: return (p_Mapping.findForward("Queue"));
135: }
136: }
|