use of com.sun.enterprise.config.serverbeans.Application in project Payara by payara.
the class InboundRecoveryHandler method recoverInboundTransactions.
private void recoverInboundTransactions(List<XAResource> xaresList) {
List<Application> applications = deployedApplications.getApplications();
try {
_logger.log(Level.INFO, "Recovery of Inbound Transactions started.");
if (applications.size() == 0) {
_logger.log(Level.FINE, "No applications deployed.");
return;
}
// List of CMT enabled MDB descriptors on the application server instance.
List<EjbDescriptor> xaEnabledMDBList = new ArrayList<EjbDescriptor>();
// Done so as to initialize connectors-runtime before loading inbound active RA. need a better way ?
ConnectorRuntime cr = connectorRuntimeProvider.get();
for (Application application : applications) {
Vector ejbDescVec = getEjbDescriptors(application, appsRegistry);
for (int j = 0; j < ejbDescVec.size(); j++) {
EjbDescriptor desc = (EjbDescriptor) ejbDescVec.elementAt(j);
// add it to the list of xaEnabledMDBList.
if (desc instanceof EjbMessageBeanDescriptor && desc.getTransactionType().equals(EjbDescriptor.CONTAINER_TRANSACTION_TYPE)) {
xaEnabledMDBList.add(desc);
_logger.log(Level.FINE, "Found a CMT MDB: " + desc.getEjbClassName());
}
}
}
if (xaEnabledMDBList.size() == 0) {
_logger.log(Level.FINE, "Found no CMT MDBs in all applications");
return;
}
ConnectorRegistry creg = ConnectorRegistry.getInstance();
// for each RA (key in the map) get the list (value) of MDB Descriptors
Map<String, List<EjbDescriptor>> mappings = createRAEjbMapping(xaEnabledMDBList);
// For each RA
for (Map.Entry entry : mappings.entrySet()) {
String raMid = (String) entry.getKey();
List<EjbDescriptor> respectiveDesc = mappings.get(raMid);
try {
createActiveResourceAdapter(raMid);
} catch (Exception ex) {
_logger.log(Level.SEVERE, "error.loading.connector.resources.during.recovery", raMid);
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, ex.toString(), ex);
}
}
ActiveInboundResourceAdapter activeInboundRA = (ActiveInboundResourceAdapter) creg.getActiveResourceAdapter(raMid);
// assert activeInboundRA instanceof ActiveInboundResourceAdapter;
boolean isSystemJmsRA = false;
if (ConnectorsUtil.isJMSRA(activeInboundRA.getModuleName())) {
isSystemJmsRA = true;
}
javax.resource.spi.ResourceAdapter resourceAdapter = activeInboundRA.getResourceAdapter();
// activationSpecList represents the ActivationSpec[] that would be
// sent to the getXAResources() method.
ArrayList<ActivationSpec> activationSpecList = new ArrayList<ActivationSpec>();
try {
for (int i = 0; i < respectiveDesc.size(); i++) {
try {
// Get a MessageBeanDescriptor from respectiveDesc ArrayList
EjbMessageBeanDescriptor descriptor = (EjbMessageBeanDescriptor) respectiveDesc.get(i);
// to be updated J2EE 1.4 style props.
if (isSystemJmsRA) {
// XXX: Find out the pool descriptor corres to MDB and update
// MDBRuntimeInfo with that.
activeInboundRA.updateMDBRuntimeInfo(descriptor, null);
}
// Get the ActivationConfig Properties from the MDB Descriptor
Set activationConfigProps = RARUtils.getMergedActivationConfigProperties(descriptor);
// get message listener type
String msgListenerType = descriptor.getMessageListenerType();
// start resource adapter and get ActivationSpec class for
// the given message listener type from the ConnectorRuntime
ActivationSpec aspec = (ActivationSpec) (Class.forName(cr.getActivationSpecClass(raMid, msgListenerType), false, resourceAdapter.getClass().getClassLoader()).newInstance());
aspec.setResourceAdapter(resourceAdapter);
// Populate ActivationSpec class with ActivationConfig properties
SetMethodAction sma = new SetMethodAction(aspec, activationConfigProps);
sma.run();
activationSpecList.add(aspec);
} catch (Exception e) {
_logger.log(Level.WARNING, "error.creating.activationspec", e.getMessage());
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, e.toString(), e);
}
}
}
// Get XA resources from RA.
ActivationSpec[] activationSpecArray = activationSpecList.toArray(new ActivationSpec[activationSpecList.size()]);
XAResource[] xar = resourceAdapter.getXAResources(activationSpecArray);
// Add the resources to the xaresList which is used by the RecoveryManager
if (xar != null) {
for (int p = 0; p < xar.length; p++) {
xaresList.add(xar[p]);
}
}
// Catch UnsupportedOperationException if a RA does not support XA
// which is fine.
} catch (UnsupportedOperationException uoex) {
_logger.log(Level.FINE, uoex.getMessage());
// otherwise catch the unexpected exception
} catch (Exception e) {
_logger.log(Level.SEVERE, "exception.during.inbound.resource.acqusition", e);
}
}
} catch (Exception e) {
_logger.log(Level.SEVERE, "exception.during.inbound.recovery", e);
}
}
Aggregations