Source Code Cross Referenced for TopicRequestor.java in  » 6.0-JDK-Modules » JMS » javax » 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 » 6.0 JDK Modules » JMS » javax.jms 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)TopicRequestor.java	1.20 02/04/09
003:         *
004:         * Copyright 1997-2002 Sun Microsystems, Inc. All Rights Reserved.
005:         *
006:         *  SUN PROPRIETARY/CONFIDENTIAL.
007:         * This software is the proprietary information of Sun Microsystems, Inc.  
008:         * Use is subject to license terms.
009:         * 
010:         */
011:
012:        package javax.jms;
013:
014:        /** The <CODE>TopicRequestor</CODE> helper class simplifies
015:         * making service requests.
016:         *
017:         * <P>The <CODE>TopicRequestor</CODE> constructor is given a non-transacted 
018:         * <CODE>TopicSession</CODE> and a destination <CODE>Topic</CODE>. It creates a 
019:         * <CODE>TemporaryTopic</CODE> for the responses and provides a 
020:         * <CODE>request</CODE> method that sends the request message and waits 
021:         * for its reply.
022:         *
023:         * <P>This is a basic request/reply abstraction that should be sufficient 
024:         * for most uses. JMS providers and clients are free to create more 
025:         * sophisticated versions.
026:         *
027:         * @version     1.0 - 8 July 1998
028:         * @author      Mark Hapner
029:         * @author      Rich Burridge
030:         *
031:         * @see         javax.jms.QueueRequestor
032:         */
033:
034:        public class TopicRequestor {
035:
036:            TopicSession session; // The topic session the topic belongs to.
037:            Topic topic; // The topic to perform the request/reply on.  
038:            TemporaryTopic tempTopic;
039:            TopicPublisher publisher;
040:            TopicSubscriber subscriber;
041:
042:            /** Constructor for the <CODE>TopicRequestor</CODE> class.
043:             * 
044:             * <P>This implementation assumes the session parameter to be non-transacted,
045:             * with a delivery mode of either <CODE>AUTO_ACKNOWLEDGE</CODE> or 
046:             * <CODE>DUPS_OK_ACKNOWLEDGE</CODE>.
047:             *
048:             * @param session the <CODE>TopicSession</CODE> the topic belongs to
049:             * @param topic the topic to perform the request/reply call on
050:             *
051:             * @exception JMSException if the JMS provider fails to create the
052:             *                         <CODE>TopicRequestor</CODE> due to some internal
053:             *                         error.
054:             * @exception InvalidDestinationException if an invalid topic is specified.
055:             */
056:
057:            public TopicRequestor(TopicSession session, Topic topic)
058:                    throws JMSException {
059:                this .session = session;
060:                this .topic = topic;
061:                tempTopic = session.createTemporaryTopic();
062:                publisher = session.createPublisher(topic);
063:                subscriber = session.createSubscriber(tempTopic);
064:            }
065:
066:            /** Sends a request and waits for a reply. The temporary topic is used for
067:             * the <CODE>JMSReplyTo</CODE> destination; the first reply is returned, 
068:             * and any following replies are discarded.
069:             *
070:             * @param message the message to send
071:             *  
072:             * @return the reply message
073:             *  
074:             * @exception JMSException if the JMS provider fails to complete the
075:             *                         request due to some internal error.
076:             */
077:
078:            public Message request(Message message) throws JMSException {
079:                message.setJMSReplyTo(tempTopic);
080:                publisher.publish(message);
081:                return (subscriber.receive());
082:            }
083:
084:            /** Closes the <CODE>TopicRequestor</CODE> and its session.
085:             *
086:             * <P>Since a provider may allocate some resources on behalf of a 
087:             * <CODE>TopicRequestor</CODE> outside the Java virtual machine, clients 
088:             * should close them when they 
089:             * are not needed. Relying on garbage collection to eventually reclaim 
090:             * these resources may not be timely enough.
091:             *
092:             * <P>Note that this method closes the <CODE>TopicSession</CODE> object 
093:             * passed to the <CODE>TopicRequestor</CODE> constructor.
094:             *  
095:             * @exception JMSException if the JMS provider fails to close the
096:             *                         <CODE>TopicRequestor</CODE> due to some internal
097:             *                         error.
098:             */
099:
100:            public void close() throws JMSException {
101:
102:                // publisher and consumer created by constructor are implicitly closed.
103:                session.close();
104:                tempTopic.delete();
105:            }
106:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.