public void prepare() throws Exception { storageManager.readLock(); try { synchronized (timeoutLock) { if (state == State.ROLLBACK_ONLY) { if (exception != null) { // this TX will never be rolled back, // so we reset it now beforeRollback(); afterRollback(); operations.clear(); throw exception; } else { // Do nothing return; } } else if (state != State.ACTIVE) { throw new IllegalStateException("Transaction is in invalid state " + state); } if (xid == null) { throw new IllegalStateException("Cannot prepare non XA transaction"); } beforePrepare(); storageManager.prepare(id, xid); state = State.PREPARED; // We use the Callback even for non persistence // If we are using non-persistence with replication, the replication manager will have // to execute this runnable in the correct order storageManager.afterCompleteOperations( new IOAsyncTask() { public void onError(final int errorCode, final String errorMessage) { HornetQServerLogger.LOGGER.ioErrorOnTX(errorCode, errorMessage); } public void done() { afterPrepare(); } }); } } finally { storageManager.readUnLock(); } }