private void cleanupUserTransaction() { if (ut != null) { UserTransactionHelper.returnUserTransaction(ut); ut = null; } } }
/** * Return a UserTransaction that was retrieved via getUserTransaction(). * This will make sure that the InitalContext used to lookup/create the * UserTransaction is properly cleaned up. */ public static void returnUserTransaction(UserTransaction userTransaction) { if ((userTransaction != null) && (userTransaction instanceof UserTransactionWithContext)) { UserTransactionWithContext userTransactionWithContext = (UserTransactionWithContext)userTransaction; userTransactionWithContext.closeContext(); } }
/** * Create/Lookup a UserTransaction in the InitialContext via the * name set in setUserTxLocation(). */ public static UserTransaction lookupUserTransaction() throws SchedulerException { return new UserTransactionWithContext(); }
@Override protected void begin() throws SchedulerException { // Don't get a new UserTransaction w/o making sure we cleaned up the old // one. This is necessary because there are paths through JobRunShell.run() // where begin() can be called multiple times w/o complete being called in // between. cleanupUserTransaction(); boolean beganSuccessfully = false; try { getLog().debug("Looking up UserTransaction."); ut = UserTransactionHelper.lookupUserTransaction(); if (transactionTimeout != null) { ut.setTransactionTimeout(transactionTimeout); } getLog().debug("Beginning UserTransaction."); ut.begin(); beganSuccessfully = true; } catch (SchedulerException se) { throw se; } catch (Exception nse) { throw new SchedulerException( "JTAJobRunShell could not start UserTransaction.", nse); } finally { if (beganSuccessfully == false) { cleanupUserTransaction(); } } }
/** * When we are being garbage collected, make sure we were properly * returned to the UserTransactionHelper. */ @Override protected void finalize() throws Throwable { try { if (context != null) { getLog().warn("UserTransaction was never returned to the UserTransactionHelper."); closeContext(); } } finally { super.finalize(); } }
/** * <p> * Called by the <class>{@link org.quartz.core.QuartzSchedulerThread} * </code> to obtain instances of <code> * {@link org.quartz.core.JobRunShell}</code>. * </p> */ public JobRunShell createJobRunShell(TriggerFiredBundle bundle) throws SchedulerException { return new JTAJobRunShell(scheduler, bundle); }
/** * Override passivate() to ensure we always cleanup the UserTransaction. */ @Override public void passivate() { cleanupUserTransaction(); super.passivate(); }
/** * Close the InitialContext that was used to lookup/create the * underlying UserTransaction. */ public void closeContext() { try { if (context != null) { context.close(); } } catch (Throwable t) { getLog().warn("Failed to close InitialContext used to get a UserTransaction.", t); } context = null; }
@Override protected void begin() throws SchedulerException { // Don't get a new UserTransaction w/o making sure we cleaned up the old // one. This is necessary because there are paths through JobRunShell.run() // where begin() can be called multiple times w/o complete being called in // between. cleanupUserTransaction(); boolean beganSuccessfully = false; try { getLog().debug("Looking up UserTransaction."); ut = UserTransactionHelper.lookupUserTransaction(); if (transactionTimeout != null) { ut.setTransactionTimeout(transactionTimeout); } getLog().debug("Beginning UserTransaction."); ut.begin(); beganSuccessfully = true; } catch (SchedulerException se) { throw se; } catch (Exception nse) { throw new SchedulerException( "JTAJobRunShell could not start UserTransaction.", nse); } finally { if (beganSuccessfully == false) { cleanupUserTransaction(); } } }
/** * When we are being garbage collected, make sure we were properly * returned to the UserTransactionHelper. */ @Override protected void finalize() throws Throwable { try { if (context != null) { getLog().warn("UserTransaction was never returned to the UserTransactionHelper."); closeContext(); } } finally { super.finalize(); } }
private void cleanupUserTransaction() { if (ut != null) { UserTransactionHelper.returnUserTransaction(ut); ut = null; } } }
/** * Return a UserTransaction that was retrieved via getUserTransaction(). * This will make sure that the InitalContext used to lookup/create the * UserTransaction is properly cleaned up. */ public static void returnUserTransaction(UserTransaction userTransaction) { if ((userTransaction != null) && (userTransaction instanceof UserTransactionWithContext)) { UserTransactionWithContext userTransactionWithContext = (UserTransactionWithContext)userTransaction; userTransactionWithContext.closeContext(); } }
/** * Create/Lookup a UserTransaction in the InitialContext via the * name set in setUserTxLocation(). */ public static UserTransaction lookupUserTransaction() throws SchedulerException { return new UserTransactionWithContext(); }
/** * <p> * Called by the <class>{@link org.quartz.core.QuartzSchedulerThread} * </code> to obtain instances of <code> * {@link org.quartz.core.JobRunShell}</code>. * </p> */ public JobRunShell createJobRunShell(TriggerFiredBundle bundle) throws SchedulerException { return new JTAJobRunShell(scheduler, bundle); }
/** * Override passivate() to ensure we always cleanup the UserTransaction. */ @Override public void passivate() { cleanupUserTransaction(); super.passivate(); }
/** * Close the InitialContext that was used to lookup/create the * underlying UserTransaction. */ public void closeContext() { try { if (context != null) { context.close(); } } catch (Throwable t) { getLog().warn("Failed to close InitialContext used to get a UserTransaction.", t); } context = null; }
/** * If the given UserTransaction is not null, it is committed/rolledback, * and then returned to the UserTransactionHelper. */ private void resolveUserTransaction(UserTransaction userTransaction) { if (userTransaction != null) { try { if (userTransaction.getStatus() == Status.STATUS_MARKED_ROLLBACK) { userTransaction.rollback(); } else { userTransaction.commit(); } } catch (Throwable t) { getLog().error("Failed to resolve UserTransaction for plugin: " + getName(), t); } finally { UserTransactionHelper.returnUserTransaction(userTransaction); } } } }
public UserTransactionWithContext() throws SchedulerException { try { context = new InitialContext(); } catch (Throwable t) { throw new SchedulerException( "UserTransactionHelper failed to create InitialContext to lookup/create UserTransaction.", t); } try { userTransaction = (UserTransaction)context.lookup(userTxURL); } catch (Throwable t) { closeContext(); throw new SchedulerException( "UserTransactionHelper could not lookup/create UserTransaction.", t); } if (userTransaction == null) { closeContext(); throw new SchedulerException( "UserTransactionHelper could not lookup/create UserTransaction from the InitialContext."); } }
/** * If the given UserTransaction is not null, it is committed/rolledback, * and then returned to the UserTransactionHelper. */ private void resolveUserTransaction(UserTransaction userTransaction) { if (userTransaction != null) { try { if (userTransaction.getStatus() == Status.STATUS_MARKED_ROLLBACK) { userTransaction.rollback(); } else { userTransaction.commit(); } } catch (Throwable t) { getLog().error("Failed to resolve UserTransaction for plugin: " + getName(), t); } finally { UserTransactionHelper.returnUserTransaction(userTransaction); } } } }
public UserTransactionWithContext() throws SchedulerException { try { context = new InitialContext(); } catch (Throwable t) { throw new SchedulerException( "UserTransactionHelper failed to create InitialContext to lookup/create UserTransaction.", t); } try { userTransaction = (UserTransaction)context.lookup(userTxURL); } catch (Throwable t) { closeContext(); throw new SchedulerException( "UserTransactionHelper could not lookup/create UserTransaction.", t); } if (userTransaction == null) { closeContext(); throw new SchedulerException( "UserTransactionHelper could not lookup/create UserTransaction from the InitialContext."); } }