01: /*
02: * JBoss, Home of Professional Open Source
03: * Copyright 2005, JBoss Inc., and individual contributors as indicated
04: * by the @authors tag. See the copyright.txt in the distribution for a
05: * full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jbpm.msg.jms;
23:
24: import javax.jms.Connection;
25: import javax.jms.ConnectionFactory;
26: import javax.jms.Destination;
27: import javax.jms.Session;
28: import javax.naming.InitialContext;
29:
30: import org.jbpm.JbpmException;
31: import org.jbpm.svc.Service;
32: import org.jbpm.svc.ServiceFactory;
33:
34: public class JmsMessageServiceFactoryImpl implements ServiceFactory {
35:
36: private static final long serialVersionUID = 1L;
37:
38: String connectionFactoryJndiName = "java:/JmsXA";
39: String destinationJndiName = "queue/JbpmJobQueue";
40: boolean isCommitEnabled = false;
41:
42: public Service openService() {
43: Connection connection = null;
44: Session session = null;
45: Destination destination = null;
46:
47: try {
48: InitialContext initialContext = new InitialContext();
49: ConnectionFactory connectionFactory = (ConnectionFactory) initialContext
50: .lookup(connectionFactoryJndiName);
51: destination = (Destination) initialContext
52: .lookup(destinationJndiName);
53: connection = connectionFactory.createConnection();
54:
55: // If you use an XA connection factory in JBoss, the parameters will be ignored. It will always take part in the global JTA transaction.
56: // If you use a non XQ connection factory, the first parameter specifies wether you want to have all message productions and
57: // consumptions as part of one transaction (TRUE) or wether you want all productions and consumptions to be instantanious (FALSE)
58: // Of course, we never want messages to be received before the current jbpm transaction commits so we just set it to true.
59: session = connection.createSession(true,
60: Session.AUTO_ACKNOWLEDGE);
61:
62: } catch (Exception e) {
63: throw new JbpmException(
64: "couldn't open jms message session", e);
65: }
66:
67: return new JmsMessageServiceImpl(connection, session,
68: destination, isCommitEnabled);
69: }
70:
71: public void close() {
72: }
73:
74: }
|