📄 jmsintegrationservicefactory.java
字号:
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the JBPM BPEL PUBLIC LICENSE AGREEMENT as
* published by JBoss Inc.; either version 1.0 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
package org.jbpm.bpel.integration.jms;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jbpm.JbpmConfiguration;
import org.jbpm.bpel.graph.def.BpelDefinition;
import org.jbpm.bpel.integration.IntegrationService;
import org.jbpm.svc.Service;
import org.jbpm.svc.ServiceFactory;
/**
* @author Alejandro Gu韟ar
* @version $Revision: 1.5 $ $Date: 2007/01/18 13:49:50 $
*/
public class JmsIntegrationServiceFactory implements ServiceFactory {
// injected fields, see jbpm.cfg.xml
protected String defaultDestinationName;
protected String defaultConnectionFactoryName;
private Destination defaultDestination;
private ConnectionFactory defaultConnectionFactory;
private Map integrationControls = new HashMap();
private static final Log log = LogFactory.getLog(JmsIntegrationServiceFactory.class);
private static final long serialVersionUID = 1L;
public Service openService() {
return new JmsIntegrationService(this);
}
public void close() {
Iterator integrationControlIt = integrationControls.values().iterator();
while (integrationControlIt.hasNext()) {
IntegrationControl integrationControl = (IntegrationControl) integrationControlIt.next();
try {
integrationControl.disableInboundMessageActivities();
}
catch (JMSException e) {
log.debug("could not close integration control", e);
}
}
}
public IntegrationControl getIntegrationControl(
BpelDefinition processDefinition) {
Long processId = new Long(processDefinition.getId());
IntegrationControl integrationControl = (IntegrationControl) integrationControls.get(processId);
if (integrationControl == null) {
log.debug("creating integration control: processDefinition="
+ processDefinition);
integrationControl = new IntegrationControl(this);
integrationControls.put(processId, integrationControl);
}
return integrationControl;
}
public ConnectionFactory getDefaultConnectionFactory() {
if (defaultConnectionFactory == null
&& defaultConnectionFactoryName != null) {
try {
defaultConnectionFactory = createDefaultConnectionFactory();
}
catch (Exception e) {
log.debug("could not create default connection", e);
}
}
return defaultConnectionFactory;
}
private ConnectionFactory createDefaultConnectionFactory()
throws NamingException {
InitialContext initialContext = new InitialContext();
try {
return (ConnectionFactory) initialContext.lookup(defaultConnectionFactoryName);
}
finally {
initialContext.close();
}
}
public Destination getDefaultDestination() {
if (defaultDestination == null && defaultDestinationName != null) {
try {
defaultDestination = createDefaultDestination();
}
catch (Exception e) {
log.debug("could not create default destination", e);
}
}
return defaultDestination;
}
private Destination createDefaultDestination() throws NamingException {
InitialContext initialContext = new InitialContext();
try {
return (Destination) initialContext.lookup(defaultDestinationName);
}
finally {
initialContext.close();
}
}
public static JmsIntegrationServiceFactory getInstance(
JbpmConfiguration jbpmConfiguration) {
return (JmsIntegrationServiceFactory) jbpmConfiguration.getServiceFactory(IntegrationService.SERVICE_NAME);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -