Source Code Cross Referenced for JMSServicesClient.java in  » Workflow-Engines » bonita-v3.1 » hero » client » events » 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 » Workflow Engines » bonita v3.1 » hero.client.events 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         * JMSServicesClient.java - 
004:         * Copyright (C) 2004 Ecoo Team
005:         * valdes@loria.fr
006:         * 
007:         *
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU Lesser General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or (at your option) any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU Lesser General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU Lesser General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021:         */
022:
023:        package hero.client.events;
024:
025:        import javax.jms.TopicConnectionFactory;
026:        import javax.jms.Topic;
027:        import javax.jms.TopicConnection;
028:        import javax.jms.TopicSession;
029:        import javax.jms.TopicSubscriber;
030:        import javax.jms.TopicPublisher;
031:        import javax.jms.TextMessage;
032:        import javax.jms.ObjectMessage;
033:        import javax.jms.JMSException;
034:        import javax.jms.Session;
035:        import javax.jms.MessageListener;
036:        import javax.jms.Message;
037:        import javax.naming.NamingException;
038:        import javax.naming.Context;
039:        import javax.naming.InitialContext;
040:        import java.io.InputStreamReader;
041:        import java.util.Hashtable;
042:        import java.util.Enumeration;
043:
044:        public class JMSServicesClient {
045:
046:            private static JMSServicesClient jms = null; // Singleton pattern
047:
048:            private static String topicName = "testTopic";
049:            private static Context jndiContext = null;
050:            private static TopicConnectionFactory topicConnectionFactory = null;
051:            private static TopicSession topicSession = null;
052:            private static Topic topic = null;
053:            private static TopicConnection topicConnection = null;
054:            private static TopicSubscriber topicSubscriber = null;
055:            private static TopicPublisher topicPublisher = null;
056:            private static TextMessage message = null;
057:            private static ObjectMessage omessage = null;
058:            private static InputStreamReader inputStreamReader = null;
059:
060:            public JMSServicesClient() throws Exception {
061:
062:                /* 
063:                 * Create a JNDI InitialContext object if none exists yet.
064:                 */
065:
066:                try {
067:
068:                    jndiContext = new InitialContext();
069:                } catch (NamingException e) {
070:                    throw new Exception(e.getMessage(), e);
071:                }
072:
073:                /*
074:                 * Look up connection factory and topic.  If either does
075:                 * not exist, exit.
076:                 */
077:
078:                try {
079:                    topicConnectionFactory = (TopicConnectionFactory) jndiContext
080:                            .lookup("JTCF");
081:                    topic = (Topic) jndiContext.lookup(topicName);
082:                } catch (NamingException e) {
083:                    System.out.println("JNDI lookup failed: " + e.toString());
084:                    throw new Exception(e.getMessage(), e);
085:                    //            System.exit(1);
086:                }
087:
088:                /*
089:                 * Create connection.
090:                 * Create session from connection; false means session is
091:                 * not transacted.
092:                 */
093:
094:                try {
095:                    topicConnection = topicConnectionFactory
096:                            .createTopicConnection();
097:                    topicSession = topicConnection.createTopicSession(false,
098:                            Session.AUTO_ACKNOWLEDGE);
099:                } catch (JMSException e) {
100:                    System.out.println("Exception occurred: " + e.toString());
101:                }
102:
103:            }
104:
105:            /**
106:             * Returns the instance of the JMSServices
107:             * Implementation of the Singleton pattern.
108:             */
109:
110:            public static JMSServicesClient getInstance() throws Exception {
111:                if (jms == null) {
112:                    jms = new JMSServicesClient();
113:                }
114:                return jms;
115:
116:            }
117:
118:            /**
119:             * Create subscriber.
120:             * Register message listener (TextListener).
121:             * Receive text messages from topic.
122:             */
123:
124:            public void createSubscription(MessageListener listener, String evt)
125:                    throws Exception {
126:
127:                try {
128:                    topicSubscriber = topicSession.createSubscriber(topic, evt,
129:                            false);
130:                    topicSubscriber.setMessageListener(listener);
131:                    topicConnection.start();
132:                } catch (JMSException e) {
133:                    e.printStackTrace();
134:                    System.out.println("Exception occurred: " + e.toString());
135:                }
136:            }
137:
138:            public static Hashtable getEvt(Message message) throws JMSException {
139:                Enumeration keys = message.getPropertyNames();
140:                Hashtable evt = new Hashtable();
141:
142:                while (keys.hasMoreElements()) {
143:                    String key = (String) keys.nextElement();
144:                    evt.put(key, message.getObjectProperty(key));
145:                }
146:                return evt;
147:            }
148:
149:            public static java.io.Serializable getEvtObject(Message message)
150:                    throws JMSException {
151:                return (((ObjectMessage) message).getObject());
152:            }
153:
154:            public void closeConnection() {
155:
156:                if (topicConnection != null) {
157:                    try {
158:                        topicConnection.close();
159:                    } catch (JMSException e) {
160:                    }
161:                }
162:            }
163:
164:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.