Source Code Cross Referenced for JMSTrigger.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » samples » 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 » Content Management System » apache lenya 2.0 » org.apache.cocoon.samples.jms 
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:         */
017:        package org.apache.cocoon.samples.jms;
018:
019:        import java.util.Hashtable;
020:
021:        import javax.jms.DeliveryMode;
022:        import javax.jms.JMSException;
023:        import javax.jms.Session;
024:        import javax.jms.TextMessage;
025:        import javax.jms.Topic;
026:        import javax.jms.TopicConnection;
027:        import javax.jms.TopicConnectionFactory;
028:        import javax.jms.TopicPublisher;
029:        import javax.jms.TopicSession;
030:        import javax.naming.Context;
031:        import javax.naming.InitialContext;
032:        import javax.naming.NamingException;
033:
034:        import org.hsqldb.Trigger;
035:
036:        /**
037:         * Example Trigger for HSQLDB doing cache invalidation through the eventcache
038:         * block and JMS messages. 
039:         * 
040:         * @version CVS $Id: JMSTrigger.java 433543 2006-08-22 06:22:54Z crossley $
041:         * @author <a href="mailto:haul@apache.org">haul</a>
042:         */
043:        public class JMSTrigger implements  Trigger {
044:
045:            // this exmaple class uses defaults to run with OpenJMS
046:            // TODO make this somehow configurable...
047:            protected String contextFactoryName = "org.exolab.jms.jndi.InitialContextFactory";
048:            protected String scheme = "rmi";
049:            protected String host = "localhost";
050:            protected String port = "";
051:            protected String jndiname = "";
052:            protected String topicFactoryName = "JmsTopicConnectionFactory";
053:            protected String topicName = "topic1";
054:            protected int deliveryMode = DeliveryMode.NON_PERSISTENT;
055:            protected int priority = 4;
056:            protected long timeToLive = 10000;
057:
058:            protected Topic topic = null;
059:            protected TopicPublisher publisher = null;
060:            protected TopicSession session = null;
061:            protected TopicConnection connection = null;
062:            protected Context context = null;
063:            protected TopicConnectionFactory topicConnectionFactory = null;
064:
065:            /**
066:             * 
067:             */
068:            public JMSTrigger() {
069:                super ();
070:            }
071:
072:            /**
073:             * Get initial context.
074:             * 
075:             * @return initial context
076:             * @throws NamingException
077:             */
078:            public Context getContext() throws NamingException {
079:
080:                Hashtable properties = new Hashtable();
081:
082:                properties.put(Context.INITIAL_CONTEXT_FACTORY,
083:                        this .contextFactoryName);
084:
085:                if (this .port.length() == 0) {
086:                    if (scheme.equals("tcp") || scheme.equals("tcps")) {
087:                        port = "3035";
088:                    } else if (scheme.equals("http")) {
089:                        port = "8080";
090:                    } else if (scheme.equals("https")) {
091:                        port = "8443";
092:                    } else if (scheme.equals("rmi")) {
093:                        port = "1099";
094:                    }
095:                }
096:
097:                String name = "";
098:                if (scheme.equals("rmi")) {
099:                    name = this .jndiname;
100:                }
101:
102:                String url = scheme + "://" + host + ":" + port + "/" + name;
103:
104:                properties.put(Context.PROVIDER_URL, url);
105:                return new InitialContext(properties);
106:            }
107:
108:            private void setupConnection() throws NamingException, JMSException {
109:                // setup JMS connection
110:                this .context = this .getContext();
111:                this .topicConnectionFactory = (TopicConnectionFactory) this .context
112:                        .lookup(this .topicFactoryName);
113:                this .connection = this .topicConnectionFactory
114:                        .createTopicConnection();
115:                this .connection.start();
116:            }
117:
118:            private void setupSession() throws JMSException {
119:                this .session = connection.createTopicSession(false,
120:                        Session.CLIENT_ACKNOWLEDGE);
121:                this .topic = session.createTopic(this .topicName);
122:                this .publisher = session.createPublisher(topic);
123:            }
124:
125:            private void connect() throws NamingException, JMSException {
126:                if (this .connection == null)
127:                    this .setupConnection();
128:                if (this .session == null)
129:                    this .setupSession();
130:            }
131:
132:            private void disconnect() throws JMSException, NamingException {
133:                // do we really need to do this every time??
134:                // OTOH we should expect to run this trigger rather infrequently.
135:                this .session.close();
136:                this .session = null;
137:                this .connection.close();
138:                this .connection = null;
139:                this .topicConnectionFactory = null;
140:                this .context.close();
141:                this .context = null;
142:            }
143:
144:            /* 
145:             * @see org.hsqldb.Trigger#fire(java.lang.String, java.lang.String, java.lang.Object[])
146:             */
147:            public void fire(String trigName, String tabName, Object[] row) {
148:                try {
149:                    connect();
150:                    TextMessage message = this .session
151:                            .createTextMessage(trigName.toLowerCase() + "|"
152:                                    + tabName.toLowerCase());
153:                    this .publisher.publish(this .topic, message,
154:                            this .deliveryMode, this .priority, this .timeToLive);
155:                    disconnect();
156:
157:                } catch (Exception e) {
158:                    e.printStackTrace();
159:                }
160:            }
161:
162:            /* (non-Javadoc)
163:             * @see org.hsqldb.Trigger#fire(int, java.lang.String, java.lang.String, java.lang.Object[], java.lang.Object[])
164:             */
165:            public void fire(int arg0, String arg1, String arg2, Object[] arg3,
166:                    Object[] arg4) {
167:                // TODO Auto-generated method stub
168:
169:            }
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.