Source Code Cross Referenced for NamedQueueManagerImpl.java in  » Net » Coadunation_1.0.1 » com » rift » coad » daemon » messageservice » named » 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 » Net » Coadunation_1.0.1 » com.rift.coad.daemon.messageservice.named 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * MessageService: The message service daemon
003:         * Copyright (C) 2006  Rift IT Contracting
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
018:         *
019:         * QueueManagerImpl.java
020:         */
021:
022:        // package path
023:        package com.rift.coad.daemon.messageservice.named;
024:
025:        // java imports
026:        import java.rmi.Remote;
027:        import java.rmi.RemoteException;
028:        import java.util.ArrayList;
029:        import java.util.List;
030:        import java.util.HashMap;
031:        import java.util.Map;
032:        import java.util.Date;
033:        import java.util.Set;
034:        import java.util.HashSet;
035:        import java.util.Vector;
036:        import java.util.concurrent.ConcurrentHashMap;
037:        import javax.naming.Context;
038:        import javax.naming.InitialContext;
039:        import javax.transaction.SystemException;
040:        import javax.transaction.UserTransaction;
041:        import javax.transaction.Status;
042:        import javax.transaction.xa.XAException;
043:        import javax.transaction.xa.XAResource;
044:        import javax.transaction.xa.Xid;
045:
046:        // logging import
047:        import org.apache.log4j.Logger;
048:
049:        // hibernate imports
050:        import org.hibernate.*;
051:        import org.hibernate.cfg.*;
052:
053:        // coadunation imports
054:        import com.rift.coad.daemon.messageservice.*;
055:        import com.rift.coad.util.transaction.TransactionManager;
056:        import com.rift.coad.util.lock.LockRef;
057:        import com.rift.coad.util.lock.ObjectLockFactory;
058:        import com.rift.coad.daemon.messageservice.db.*;
059:        import com.rift.coad.hibernate.util.HibernateUtil;
060:        import com.rift.coad.lib.ResourceIndex;
061:        import com.rift.coad.lib.Resource;
062:        import com.rift.coad.lib.bean.TransactionBeanCache;
063:        import com.rift.coad.lib.cache.CacheRegistry;
064:
065:        /**
066:         * The implementation of the queue manager object.
067:         *
068:         * @author Brett Chaldecott
069:         */
070:        public class NamedQueueManagerImpl implements  QueueManager {
071:
072:            // the queue manager singleton method
073:            private static NamedQueueManagerImpl singleton = null;
074:
075:            // the logger reference
076:            protected Logger log = Logger.getLogger(NamedQueueManagerImpl.class
077:                    .getName());
078:
079:            // private member variables
080:            private Map queues = new HashMap();
081:
082:            /**
083:             * Creates a new instance of QueueManagerImpl
084:             */
085:            public NamedQueueManagerImpl() throws MessageServiceException {
086:                singleton = this ;
087:            }
088:
089:            /**
090:             * This method returns the queue specified by the name. If the queue does
091:             * not exist it gets created.
092:             *
093:             * @return The queue identified by the name.
094:             * @param name The name of the queue to retrieve.
095:             * @exception RemoteException
096:             * @exception MessageServiceException
097:             */
098:            public synchronized NamedQueue getNamedQueue(String name)
099:                    throws RemoteException, MessageServiceException {
100:                try {
101:                    Boolean value = (Boolean) queues.get(name);
102:                    if (value != null) {
103:                        if (value.booleanValue()) {
104:                            return new NamedQueueImpl(name);
105:                        } else {
106:                            log.error("This is not a named queue [" + name
107:                                    + "].");
108:                            throw new MessageServiceException(
109:                                    "This is not a named queue [" + name + "].");
110:                        }
111:                    }
112:                    Session session = HibernateUtil.getInstance(
113:                            MessageServiceManager.class).getSession();
114:                    List list = session.createQuery(
115:                            "FROM MessageQueue AS queue "
116:                                    + "WHERE queue.messageQueueName = ?")
117:                            .setString(0, name).list();
118:                    NamedQueueImpl queue = new NamedQueueImpl(name);
119:                    if (list.size() == 1) {
120:                        com.rift.coad.daemon.messageservice.db.MessageQueue dbQueue = (com.rift.coad.daemon.messageservice.db.MessageQueue) list
121:                                .get(0);
122:                        if ((dbQueue.getNamed() == null)
123:                                || (dbQueue.getNamed() == 0)) {
124:                            addCheckEntry(name, false);
125:                            log.error("This is not a named queue [" + name
126:                                    + "].");
127:                            throw new MessageServiceException(
128:                                    "This is not a named queue [" + name + "].");
129:                        }
130:                        addCheckEntry(name, true);
131:                        return queue;
132:                    }
133:                    com.rift.coad.daemon.messageservice.db.MessageQueue dbQueue = new com.rift.coad.daemon.messageservice.db.MessageQueue(
134:                            name);
135:                    dbQueue.setNamed(1);
136:                    session.persist(dbQueue);
137:                    addCheckEntry(name, true);
138:                    return queue;
139:                } catch (MessageServiceException ex) {
140:                    throw ex;
141:                } catch (Exception ex) {
142:                    log.error("Failed to retrieve the named message queue ["
143:                            + name + "] : " + ex.getMessage(), ex);
144:                    throw new MessageServiceException(
145:                            "Failed to retrieve the named message queue ["
146:                                    + name + "] : " + ex.getMessage(), ex);
147:                }
148:            }
149:
150:            /**
151:             * This method returns true if the queue with the specified name exists.
152:             *
153:             * @return TRUE if found, FALSE if not.
154:             * @param name The name of the queue to check for.
155:             * @exception MessageServiceException
156:             */
157:            public synchronized boolean checkForNamedQueue(String name,
158:                    boolean create) throws MessageServiceException {
159:                try {
160:                    Boolean value = (Boolean) queues.get(name);
161:                    if (value != null) {
162:                        return value.booleanValue();
163:                    }
164:                    Session session = HibernateUtil.getInstance(
165:                            MessageServiceManager.class).getSession();
166:                    List list = session.createQuery(
167:                            "FROM MessageQueue AS queue "
168:                                    + "WHERE queue.messageQueueName = ?")
169:                            .setString(0, name).list();
170:                    if (list.size() == 1) {
171:                        com.rift.coad.daemon.messageservice.db.MessageQueue queue = (com.rift.coad.daemon.messageservice.db.MessageQueue) list
172:                                .get(0);
173:                        if ((queue.getNamed() != null)
174:                                && (queue.getNamed() == 1)) {
175:                            addCheckEntry(name, true);
176:                            return true;
177:                        } else {
178:                            addCheckEntry(name, false);
179:                            return false;
180:                        }
181:                    } else if (create) {
182:                        com.rift.coad.daemon.messageservice.db.MessageQueue dbQueue = new com.rift.coad.daemon.messageservice.db.MessageQueue(
183:                                name);
184:                        dbQueue.setNamed(1);
185:                        session.persist(dbQueue);
186:                        addCheckEntry(name, true);
187:                        return true;
188:                    }
189:                    return false;
190:                } catch (Exception ex) {
191:                    log.error("Failed to check for the named queue [" + name
192:                            + "] : " + ex.getMessage(), ex);
193:                    throw new MessageServiceException(
194:                            "Failed to check for the named queue [" + name
195:                                    + "] : " + ex.getMessage(), ex);
196:                }
197:            }
198:
199:            /**
200:             * This method returns a reference to the singleton instance.
201:             *
202:             * @return A reference to the singleton instance.
203:             * @exception MessageServiceException
204:             */
205:            public static synchronized NamedQueueManagerImpl getInstance()
206:                    throws MessageServiceException {
207:                if (singleton == null) {
208:                    throw new MessageServiceException(
209:                            "Message service singleton not initialized");
210:                }
211:                return singleton;
212:            }
213:
214:            /**
215:             * This method addes a check flag value to the memory queues list
216:             *
217:             * @param name The name to add.
218:             * @praam the type of queue. TRUE if named
219:             */
220:            private void addCheckEntry(String name, boolean queueType) {
221:                queues.put(name, new Boolean(queueType));
222:            }
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.