Source Code Cross Referenced for JMSConnectionFactory.java in  » J2EE » jfox » org » jfox » jms » 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 » J2EE » jfox » org.jfox.jms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JFox - The most lightweight Java EE Application Server!
003:         * more details please visit http://www.huihoo.org/jfox or http://www.jfox.org.cn.
004:         *
005:         * JFox is licenced and re-distributable under GNU LGPL.
006:         */
007:
008:        /* JFox, the OpenSource J2EE Application Server
009:         *
010:         * Distributable under GNU LGPL license by gun.org
011:         * more details please visit http://www.huihoo.org/jfox
012:         */
013:
014:        package org.jfox.jms;
015:
016:        import java.util.HashMap;
017:        import java.util.Map;
018:        import java.util.UUID;
019:        import javax.jms.Connection;
020:        import javax.jms.JMSException;
021:        import javax.jms.Message;
022:        import javax.jms.MessageListener;
023:        import javax.jms.Queue;
024:        import javax.jms.QueueConnection;
025:        import javax.jms.QueueReceiver;
026:        import javax.jms.QueueSender;
027:        import javax.jms.QueueSession;
028:        import javax.jms.Session;
029:        import javax.jms.TopicConnection;
030:        import javax.jms.XAConnection;
031:        import javax.jms.XAQueueConnection;
032:        import javax.jms.XATopicConnection;
033:
034:        import org.jfox.jms.destination.JMSDestination;
035:        import org.jfox.jms.destination.JMSQueue;
036:        import org.jfox.jms.destination.JMSTopic;
037:        import org.jfox.jms.message.JMSMessage;
038:
039:        /**
040:         * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
041:         */
042:
043:        public class JMSConnectionFactory implements  MessageService {
044:
045:            private Map<String, JMSDestination> destinationMap = new HashMap<String, JMSDestination>();
046:
047:            public Connection createConnection() throws JMSException {
048:                return createConnection(null, null);
049:            }
050:
051:            public Connection createConnection(String userName, String password)
052:                    throws JMSException {
053:                return createConnection(userName, password, false);
054:            }
055:
056:            public QueueConnection createQueueConnection() throws JMSException {
057:                return (QueueConnection) createConnection();
058:            }
059:
060:            public QueueConnection createQueueConnection(String userName,
061:                    String password) throws JMSException {
062:                return (QueueConnection) createConnection(userName, password);
063:            }
064:
065:            public TopicConnection createTopicConnection() throws JMSException {
066:                return (TopicConnection) createConnection();
067:            }
068:
069:            public TopicConnection createTopicConnection(String userName,
070:                    String password) throws JMSException {
071:                return (TopicConnection) createConnection(userName, password);
072:            }
073:
074:            public XAConnection createXAConnection() throws JMSException {
075:                return createXAConnection(null, null);
076:            }
077:
078:            public XAConnection createXAConnection(String userName,
079:                    String password) throws JMSException {
080:                return createConnection(userName, password, true);
081:            }
082:
083:            public XAQueueConnection createXAQueueConnection()
084:                    throws JMSException {
085:                return (XAQueueConnection) createXAConnection();
086:            }
087:
088:            public XAQueueConnection createXAQueueConnection(String userName,
089:                    String password) throws JMSException {
090:                return (XAQueueConnection) createXAConnection(userName,
091:                        password);
092:            }
093:
094:            public XATopicConnection createXATopicConnection()
095:                    throws JMSException {
096:                return (XATopicConnection) createXAConnection();
097:            }
098:
099:            public XATopicConnection createXATopicConnection(String userName,
100:                    String password) throws JMSException {
101:                return (XATopicConnection) createXAConnection(userName,
102:                        password);
103:            }
104:
105:            public void close() {
106:                for (JMSDestination destination : destinationMap.values()) {
107:                    destination.stop();
108:                }
109:            }
110:
111:            /**
112:             * create queue with given name
113:             *
114:             * MDBBucket 通过该方法创建Queue
115:             *
116:             * @param name queue name
117:             */
118:            public JMSQueue createQueue(String name) throws JMSException {
119:                if (!destinationMap.containsKey(name)) {
120:                    JMSQueue queue = new JMSQueue(name);
121:                    destinationMap.put(name, queue);
122:                    return queue;
123:                } else {
124:                    JMSDestination destination = destinationMap.get(name);
125:                    if (destination.isTopic()) {
126:                        throw new JMSException("Destination " + name
127:                                + " exists, but its type is Topic.");
128:                    }
129:                    return (JMSQueue) destination;
130:                }
131:            }
132:
133:            public JMSTopic createTopic(String name) throws JMSException {
134:                if (!destinationMap.containsKey(name)) {
135:                    JMSTopic queue = new JMSTopic(name);
136:                    destinationMap.put(name, queue);
137:                    return queue;
138:                } else {
139:                    JMSDestination destination = destinationMap.get(name);
140:                    if (!destination.isTopic()) {
141:                        throw new JMSException("Destination " + name
142:                                + " exists, but its type is Queue.");
143:                    }
144:                    return (JMSTopic) destination;
145:                }
146:            }
147:
148:            protected synchronized JMSConnection createConnection(
149:                    String userName, String password, boolean isXA) {
150:                //TODO: support username & password
151:                return new JMSConnection(UUID.randomUUID().toString(), this ,
152:                        true);
153:            }
154:
155:            public void sendMessage(JMSDestination destination,
156:                    JMSMessage message) {
157:
158:            }
159:
160:            public static void main(String[] args) throws Exception {
161:                JMSConnectionFactory connectionFactory = new JMSConnectionFactory();
162:                QueueConnection connection = connectionFactory
163:                        .createQueueConnection();
164:                QueueSession session = connection.createQueueSession(false,
165:                        Session.AUTO_ACKNOWLEDGE);
166:                Queue queue = session.createQueue("defaultQ");
167:                QueueSender sender = session.createSender(queue);
168:                sender.send(session.createTextMessage("Hello, JMS!"));
169:
170:                connection.start();
171:                QueueReceiver receiver = session.createReceiver(queue);
172:                Message message = receiver.receive();
173:                System.out.println("Received Message: " + message);
174:
175:                Thread.sleep(1000);
176:                receiver.setMessageListener(new MessageListener() {
177:                    public void onMessage(Message message) {
178:                        System.out.println("onMessage: " + message);
179:                    }
180:                });
181:                sender.send(session.createTextMessage("Hello, JMS2!"));
182:
183:                Thread.sleep(1000);
184:                connectionFactory.close();
185:            }
186:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.