use of com.sun.messaging.bridge.service.jms.tx.TransactionManagerAdapter in project openmq by eclipse-ee4j.
the class JMSBridge method init.
public void init(BridgeContext bc, String name, boolean reset) throws Exception {
_bc = bc;
_name = name;
_reset = reset;
Properties props = bc.getConfig();
String domain = props.getProperty(BridgeContext.BRIDGE_PROP_PREFIX);
_xmlurl = props.getProperty(domain + PROP_XMLURL_SUFFIX);
if (_xmlurl == null) {
throw new IllegalArgumentException(_jbr.getKString(_jbr.X_NOT_SPECIFIED, _name, domain + PROP_XMLURL_SUFFIX));
}
_logger = Logger.getLogger(domain);
if (bc.isSilentMode()) {
_logger.setUseParentHandlers(false);
}
String var = bc.getRootDir();
File dir = new File(var);
if (!dir.exists()) {
dir.mkdirs();
}
String logfile = var + File.separator + "jms%g.log";
int limit = 0, count = 1;
String limits = props.getProperty(domain + PROP_LOGFILE_LIMIT_SUFFIX);
if (limits != null) {
limit = Integer.parseInt(limits);
}
String counts = props.getProperty(domain + PROP_LOGFILE_COUNT_SUFFIX);
if (counts != null) {
count = Integer.parseInt(counts);
}
FileHandler h = new FileHandler(logfile, limit, count, true);
h.setFormatter(new LogSimpleFormatter(_logger));
_logger.addHandler(h);
_logger.log(Level.INFO, _jbr.getString(_jbr.I_LOG_DOMAIN, _name, domain));
_logger.log(Level.INFO, _jbr.getString(_jbr.I_LOG_FILE, _name, logfile) + "[" + limit + "," + count + "]");
String lib = bc.getLibDir();
if (lib == null) {
throw new IllegalArgumentException("JMS bridge " + _name + " lib dir not specified");
}
String dtdd = lib + File.separator + "dtd" + File.separator;
File dtddir = new File(dtdd);
if (!dtddir.exists()) {
throw new IllegalArgumentException(_jbr.getKString(_jbr.X_NOT_EXIST, _name, dtdd));
}
String sysid = dtddir.toURI().toURL().toString();
String[] param = { _name, _xmlurl, sysid };
_logger.log(Level.INFO, _jbr.getString(_jbr.I_INIT_JMSBRIDGE_WITH, param));
JMSBridgeReader reader = new JMSBridgeReader(_xmlurl, sysid, _logger);
_jmsbridge = reader.getJMSBridgeElement();
if (!_name.equals(_jmsbridge.getName())) {
String[] eparam = { _name, _jmsbridge.getName(), _xmlurl };
throw new IllegalArgumentException(_jbr.getKString(_jbr.X_JMSBRIDGE_NAME_MISMATCH, eparam));
}
createBuiltInDMQ(_jmsbridge);
Map<String, DMQElement> edmqs = _jmsbridge.getDMQs();
for (Map.Entry<String, DMQElement> pair : edmqs.entrySet()) {
if (pair.getKey().equals(DMQElement.BUILTIN_DMQ_NAME)) {
continue;
}
createDMQ(pair.getValue(), _jmsbridge);
}
boolean xa = false;
Map<String, LinkElement> elinks = _jmsbridge.getLinks();
for (Map.Entry<String, LinkElement> pair : elinks.entrySet()) {
xa |= createLink(pair.getValue(), _jmsbridge);
}
if (xa) {
TransactionManagerAdapter tma = getTransactionManagerAdapter();
if (tma.registerRM()) {
Map<String, Refable> xacfs = new LinkedHashMap<>(_localXACFs);
for (Map.Entry<String, Refable> pair : _allCF.entrySet()) {
if (xacfs.get(pair.getKey()) != null) {
continue;
}
if (pair.getValue() instanceof XAConnectionFactory) {
xacfs.put(pair.getKey(), pair.getValue());
}
}
String cfref = null;
Refable cf = null;
Map<String, ConnectionFactoryElement> cfs = _jmsbridge.getAllCF();
for (Map.Entry<String, ConnectionFactoryElement> pair : cfs.entrySet()) {
cfref = pair.getKey();
if (xacfs.get(cfref) != null) {
continue;
}
try {
cf = createConnectionFactory(pair.getValue(), true);
} catch (NotXAConnectionFactoryException e) {
_logger.log(Level.INFO, _jbr.getString(_jbr.I_CF_NOT_XA_NO_REGISTER, pair.getKey(), "XAConnectionFactory"));
continue;
}
if (cf == null) {
cf = new XAConnectionFactoryImpl(_bc, _jmsbridge.getCF(cfref).getProperties(), _bc.isEmbeded(), cfref, pair.getValue().isMultiRM());
}
xacfs.put(cfref, cf);
}
registerXAResources(xacfs);
} else {
Link link = null;
for (Map.Entry<String, Link> pair : _links.entrySet()) {
link = pair.getValue();
if (link.isTransacted()) {
link.registerXAResources();
}
}
}
}
_asyncStartExecutor = Executors.newSingleThreadExecutor();
}
use of com.sun.messaging.bridge.service.jms.tx.TransactionManagerAdapter in project openmq by eclipse-ee4j.
the class JMSBridge method registerXAResources.
private void registerXAResources(Map<String, Refable> cfs) throws Exception {
TransactionManagerAdapter tma = getTransactionManagerAdapter();
if (!tma.registerRM()) {
return;
}
String cfref = null;
Refable cf = null;
XAConnection conn = null;
for (Map.Entry<String, Refable> pair : cfs.entrySet()) {
cfref = pair.getKey();
cf = pair.getValue();
if (!(cf instanceof XAConnectionFactory)) {
continue;
}
if (cf.isMultiRM()) {
_logger.log(Level.INFO, _jbr.getString(_jbr.I_SKIP_REGISTER_MULTIRM_CF, JMSBridgeXMLConstant.CF.MULTIRM, cfref));
continue;
}
XAResource xar = null;
EventListener l = new EventListener(this);
try {
String username = _jmsbridge.getCF(cf.getRef()).getUsername();
String password = _jmsbridge.getCF(cf.getRef()).getPassword();
_notifier.addEventListener(EventListener.EventType.BRIDGE_STOP, l);
conn = (XAConnection) openConnection(cf, 1, 0, username, password, "", this, l, _logger);
XASession ss = conn.createXASession();
xar = ss.getXAResource();
_logger.log(Level.INFO, _jbr.getString(_jbr.I_REGISTER_RM, cfref, xar.toString()));
tma.registerRM(cfref, xar);
} catch (Throwable t) {
_logger.log(Level.WARNING, _jbr.getKString(_jbr.W_REGISTER_RM_ATTEMPT_FAILED, cfref, (xar == null ? "" : xar.toString())), t);
} finally {
_notifier.removeEventListener(l);
try {
conn.close();
} catch (Exception e) {
}
}
}
}
Aggregations