Source Code Cross Referenced for ViewMessagesRenderer.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » console » jmsmanager » renderers » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server geronimo » plugins » org.apache.geronimo.console.jmsmanager.renderers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */package org.apache.geronimo.console.jmsmanager.renderers;
017:
018:        import java.io.IOException;
019:        import java.util.ArrayList;
020:        import java.util.Collections;
021:        import java.util.Enumeration;
022:        import java.util.Hashtable;
023:        import java.util.List;
024:        import java.util.Map;
025:
026:        import javax.jms.Destination;
027:        import javax.jms.JMSException;
028:        import javax.jms.Message;
029:        import javax.jms.MessageListener;
030:        import javax.jms.Queue;
031:        import javax.jms.QueueBrowser;
032:        import javax.jms.QueueConnection;
033:        import javax.jms.QueueConnectionFactory;
034:        import javax.jms.QueueSession;
035:        import javax.jms.Topic;
036:        import javax.management.ObjectName;
037:        import javax.portlet.PortletException;
038:        import javax.portlet.RenderRequest;
039:        import javax.portlet.RenderResponse;
040:
041:        import org.apache.geronimo.console.jmsmanager.AbstractJMSManager;
042:        import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
043:        import org.apache.geronimo.gbean.AbstractName;
044:        import org.apache.commons.logging.Log;
045:        import org.apache.commons.logging.LogFactory;
046:
047:        public class ViewMessagesRenderer extends AbstractJMSManager implements 
048:                PortletRenderer {
049:
050:            private static final Log log = LogFactory
051:                    .getLog(ViewMessagesRenderer.class);
052:
053:            private static final TopicListener topicListener = new TopicListener();
054:
055:            public String render(RenderRequest request, RenderResponse response)
056:                    throws PortletException, IOException {
057:                List messageList = getMessageList(request, response);
058:                request.setAttribute("messages", messageList);
059:                return "/WEB-INF/view/jmsmanager/viewmessages.jsp";
060:            }
061:
062:            public List getMessageList(RenderRequest request,
063:                    RenderResponse response) throws PortletException {
064:                String destinationApplicationName = request
065:                        .getParameter("destinationApplicationName");
066:                String destinationModuleName = request
067:                        .getParameter("destinationModuleName");
068:                String destinationName = request
069:                        .getParameter("destinationName");
070:
071:                List ret = new ArrayList();
072:                try {
073:                    //TODO configid disabled
074:                    AbstractName adminObjectName = null;//NameFactory.getComponentName(null,
075:                    //                    null, destinationApplicationName, NameFactory.JCA_RESOURCE,
076:                    //                    destinationModuleName, destinationName, null, baseContext);
077:                    Destination dest = (Destination) kernel.invoke(
078:                            adminObjectName, "$getResource");
079:                    if (dest instanceof  Queue) {
080:                        Queue queue = (Queue) dest;
081:                        QueueConnectionFactory qConFactory = null;
082:                        QueueConnection qConnection = null;
083:                        QueueSession qSession = null;
084:                        QueueBrowser qBrowser = null;
085:                        try {
086:                            qConFactory = (QueueConnectionFactory) kernel
087:                                    .invoke(
088:                                            JCA_MANAGED_CONNECTION_FACTORY_NAME,
089:                                            "$getResource");
090:                            qConnection = qConFactory.createQueueConnection();
091:                            qSession = qConnection.createQueueSession(false,
092:                                    QueueSession.AUTO_ACKNOWLEDGE);
093:                            qBrowser = qSession.createBrowser(queue);
094:                            qConnection.start();
095:                            for (Enumeration e = qBrowser.getEnumeration(); e
096:                                    .hasMoreElements();) {
097:                                Object o = e.nextElement();
098:                                ret.add(o);
099:                            }
100:                            qConnection.stop();
101:                        } catch (Exception e) {
102:                            log.error(e.getMessage(), e);
103:                        } finally {
104:                            try {
105:                                if (qBrowser != null) {
106:                                    qBrowser.close();
107:                                }
108:                            } catch (JMSException ignore) {
109:                            }
110:                            try {
111:                                if (qSession != null) {
112:                                    qSession.close();
113:                                }
114:                            } catch (JMSException ignore) {
115:                            }
116:                            try {
117:                                if (qConnection != null) {
118:                                    qConnection.close();
119:                                }
120:                            } catch (JMSException ignore) {
121:                            }
122:                        }
123:                    } else if (dest instanceof  Topic) {
124:                        //TODO configid disabled
125:                        AbstractName tBrowserObjName = null;//NameFactory.getComponentName(null,
126:                        //                        null, destinationApplicationName,
127:                        //                        NameFactory.JCA_RESOURCE, destinationModuleName,
128:                        //                        destinationName, "TopicBrowser", baseContext);
129:                        ret = (List) kernel.invoke(tBrowserObjName,
130:                                "getMessages");
131:                    }
132:                } catch (Exception e) {
133:                    log.error(e.getMessage(), e);
134:                }
135:                return ret;
136:            }
137:
138:            static class TopicListener implements  MessageListener {
139:                /**
140:                 * Hashtable to hold the messages for each topic. Messages are stored as
141:                 * Message/Topic key/value pairs.
142:                 */
143:                private Map messagesMap = new Hashtable();
144:
145:                public final String name = this .toString();
146:
147:                public synchronized void onMessage(Message message) {
148:                    try {
149:                        Destination dest = message.getJMSDestination();
150:                        List messages = null;
151:                        if (!messagesMap.containsKey(dest)) {
152:                            register((Topic) dest);
153:                        }
154:                        messages = (List) messagesMap.get(dest);
155:
156:                        if (!messages.contains(message)) {
157:                            messages.add(message);
158:                        }
159:                        messagesMap.put(dest, messages);
160:                    } catch (JMSException e) {
161:                        log.error(e.getMessage(), e);
162:                    }
163:                }
164:
165:                public void register(Topic topic) {
166:                    if (!messagesMap.containsKey(topic)) {
167:                        List messages = new ArrayList();
168:                        messagesMap.put(topic, messages);
169:                    }
170:                }
171:
172:                public List getMessages(Topic topic) {
173:                    List ret;
174:                    if (messagesMap.containsKey(topic)) {
175:                        ret = (List) messagesMap.get(topic);
176:                    } else {
177:                        ret = Collections.EMPTY_LIST;
178:                    }
179:                    return Collections.unmodifiableList(ret);
180:                }
181:
182:                public boolean isListeningTo(Topic topic) {
183:                    return messagesMap.containsKey(topic);
184:                }
185:            }
186:
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.