use of javax.resource.ResourceException in project jaybird by FirebirdSQL.
the class FBDriver method connect.
public FirebirdConnection connect(FirebirdConnectionProperties properties) throws SQLException {
GDSType type = GDSType.getType(properties.getType());
if (type == null)
type = GDSFactory.getDefaultGDSType();
try {
FBManagedConnectionFactory mcf = new FBManagedConnectionFactory(type);
mcf = mcf.canonicalize();
FBDataSource dataSource = createDataSource(mcf);
return (FirebirdConnection) dataSource.getConnection(mcf.getUserName(), mcf.getPassword());
} catch (ResourceException ex) {
throw new FBSQLException(ex);
}
}
use of javax.resource.ResourceException in project jaybird by FirebirdSQL.
the class FBDataSource method getConnection.
/**
* <p>Attempt to establish a database connection.
*
* @param username
* the database user on whose behalf the Connection is
* being made
* @param password
* the user's password
* @return a Connection to the database
* @throws SQLException
* if a database-access error occurs.
*/
@SuppressWarnings("deprecation")
public Connection getConnection(String username, String password) throws SQLException {
try {
// mcf makes a copy for us.
FBConnectionRequestInfo subjectCri = mcf.getDefaultConnectionRequestInfo();
subjectCri.setUserName(username);
subjectCri.setPassword(password);
return (Connection) cm.allocateConnection(mcf, subjectCri);
} catch (ResourceException re) {
if (re.getCause() instanceof SQLException) {
throw (SQLException) re.getCause();
}
if (re.getLinkedException() instanceof SQLException) {
throw (SQLException) re.getLinkedException();
}
throw new FBSQLException(re);
}
}
use of javax.resource.ResourceException in project activemq-artemis by apache.
the class ActiveMQMessageHandler method onMessage.
@Override
public void onMessage(final ClientMessage message) {
if (logger.isTraceEnabled()) {
logger.trace("onMessage(" + message + ")");
}
ActiveMQMessage msg = ActiveMQMessage.createMessage(message, session, options);
boolean beforeDelivery = false;
try {
if (activation.getActivationSpec().getTransactionTimeout() > 0 && tm != null) {
tm.setTransactionTimeout(activation.getActivationSpec().getTransactionTimeout());
}
if (logger.isTraceEnabled()) {
logger.trace("HornetQMessageHandler::calling beforeDelivery on message " + message);
}
endpoint.beforeDelivery(ActiveMQActivation.ONMESSAGE);
beforeDelivery = true;
msg.doBeforeReceive();
if (transacted) {
message.individualAcknowledge();
}
((MessageListener) endpoint).onMessage(msg);
if (!transacted) {
message.individualAcknowledge();
}
if (logger.isTraceEnabled()) {
logger.trace("HornetQMessageHandler::calling afterDelivery on message " + message);
}
try {
endpoint.afterDelivery();
} catch (ResourceException e) {
ActiveMQRALogger.LOGGER.unableToCallAfterDelivery(e);
// If we get here, The TX was already rolled back
// However we must do some stuff now to make sure the client message buffer is cleared
// so we mark this as rollbackonly
session.markRollbackOnly();
return;
}
if (useLocalTx) {
session.commit();
}
if (logger.isTraceEnabled()) {
logger.trace("finished onMessage on " + message);
}
} catch (Throwable e) {
ActiveMQRALogger.LOGGER.errorDeliveringMessage(e);
// we need to call before/afterDelivery as a pair
if (beforeDelivery) {
if (useXA && tm != null) {
// this is to avoid a scenario where afterDelivery would kick in
try {
Transaction tx = tm.getTransaction();
if (tx != null) {
tx.setRollbackOnly();
}
} catch (Exception e1) {
ActiveMQRALogger.LOGGER.unableToClearTheTransaction(e1);
}
}
MessageEndpoint endToUse = endpoint;
try {
// to avoid a NPE that would happen while the RA is in tearDown
if (endToUse != null) {
endToUse.afterDelivery();
}
} catch (ResourceException e1) {
ActiveMQRALogger.LOGGER.unableToCallAfterDelivery(e1);
}
}
if (useLocalTx || !activation.isDeliveryTransacted()) {
try {
session.rollback(true);
} catch (ActiveMQException e1) {
ActiveMQRALogger.LOGGER.unableToRollbackTX();
}
}
// This is to make sure we will issue a rollback after failures
// so that would cleanup consumer buffers among other things
session.markRollbackOnly();
} finally {
try {
session.resetIfNeeded();
} catch (ActiveMQException e) {
ActiveMQRALogger.LOGGER.unableToResetSession(activation.toString(), e);
activation.startReconnectThread("Reset MessageHandler after Failure Thread");
}
}
}
use of javax.resource.ResourceException in project camunda-bpm-platform by camunda.
the class JcaExecutorServiceConnector method endpointActivation.
// JobHandler activation / deactivation ///////////////////////////
public void endpointActivation(MessageEndpointFactory endpointFactory, ActivationSpec spec) throws ResourceException {
if (jobHandlerActivation != null) {
throw new ResourceException("The camunda BPM job executor can only service a single MessageEndpoint for job execution. " + "Make sure not to deploy more than one MDB implementing the '" + JobExecutionHandler.class.getName() + "' interface.");
}
JobExecutionHandlerActivation activation = new JobExecutionHandlerActivation(this, endpointFactory, (JobExecutionHandlerActivationSpec) spec);
activation.start();
jobHandlerActivation = activation;
}
use of javax.resource.ResourceException in project camunda-bpm-platform by camunda.
the class JcaInflowExecuteJobsRunnable method executeJob.
@Override
protected void executeJob(String nextJobId, CommandExecutor commandExecutor) {
JobExecutionHandlerActivation jobHandlerActivation = ra.getJobHandlerActivation();
if (jobHandlerActivation == null) {
// TODO: stop acquisition / only activate acquisition if MDB active?
log.warning("Cannot execute acquired job, no JobExecutionHandler MDB deployed.");
return;
}
MessageEndpoint endpoint = null;
try {
endpoint = jobHandlerActivation.getMessageEndpointFactory().createEndpoint(null);
try {
endpoint.beforeDelivery(method);
} catch (NoSuchMethodException e) {
log.log(Level.WARNING, "NoSuchMethodException while invoking beforeDelivery() on MessageEndpoint '" + endpoint + "'", e);
} catch (ResourceException e) {
log.log(Level.WARNING, "ResourceException while invoking beforeDelivery() on MessageEndpoint '" + endpoint + "'", e);
}
try {
((JobExecutionHandler) endpoint).executeJob(nextJobId, commandExecutor);
} catch (Exception e) {
log.log(Level.WARNING, "Exception while executing job with id '" + nextJobId + "'.", e);
}
try {
endpoint.afterDelivery();
} catch (ResourceException e) {
log.log(Level.WARNING, "ResourceException while invoking afterDelivery() on MessageEndpoint '" + endpoint + "'", e);
}
} catch (UnavailableException e) {
log.log(Level.SEVERE, "UnavailableException while attempting to create messaging endpoint for executing job", e);
} finally {
if (endpoint != null) {
endpoint.release();
}
}
}
Aggregations