Search in sources :

Example 31 with LogWriterI18n

use of org.apache.geode.i18n.LogWriterI18n in project geode by apache.

the class TransactionManagerImpl method suspend.

/**
   * @see javax.transaction.TransactionManager#suspend()
   */
public Transaction suspend() throws SystemException {
    if (!isActive) {
        throw new SystemException(LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGER_INVALID.toLocalizedString());
    }
    Transaction txn = getTransaction();
    if (null != txn) {
        GlobalTransaction gtx = getGlobalTransaction(txn);
        gtx.suspend();
        transactionMap.remove(Thread.currentThread());
        LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
        if (writer.infoEnabled())
            writer.info(LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPLSUSPENDTRANSACTION_SUSPENDED);
    }
    return txn;
}
Also used : SystemException(javax.transaction.SystemException) Transaction(javax.transaction.Transaction) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n)

Example 32 with LogWriterI18n

use of org.apache.geode.i18n.LogWriterI18n in project geode by apache.

the class TransactionManagerImpl method rollback.

/**
   * Rolls back the transaction associated with the current thread by calling the
   * GlobalTransaction.rollback(). When this method completes, the thread is no longer associated
   * with a transaction.
   * 
   * @throws java.lang.SecurityException - Thrown to indicate that the thread is not allowed to
   *         commit the transaction.
   * @throws java.lang.IllegalStateException - Thrown if the current thread is not associated with a
   *         transaction.
   * @throws SystemException - Thrown if the transaction manager encounters an unexpected error
   *         condition.
   * 
   * @see javax.transaction.TransactionManager#commit()
   */
public void rollback() throws IllegalStateException, SecurityException, SystemException {
    if (!isActive) {
        throw new SystemException(LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGER_INVALID.toLocalizedString());
    }
    // boolean isRollingBack = false;
    LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
    Transaction transactionImpl = getTransaction();
    if (transactionImpl == null) {
        String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_ROLLBACK_NO_TRANSACTION_EXISTS.toLocalizedString();
        if (VERBOSE)
            writer.fine(exception);
        throw new IllegalStateException(exception);
    }
    GlobalTransaction gtx = getGlobalTransaction(transactionImpl);
    if (gtx == null) {
        String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_ROLLBACK_NO_GLOBAL_TRANSACTION_EXISTS.toLocalizedString();
        if (VERBOSE)
            writer.fine(exception);
        throw new SystemException(exception);
    }
    int status = gtx.getStatus();
    if (!(status == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK)) {
        String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_ROLLBACK_TRANSACTION_STATUS_DOES_NOT_ALLOW_ROLLBACK_TRANSACTIONAL_STATUS_0.toLocalizedString(Integer.valueOf(status));
        if (VERBOSE)
            writer.fine(exception);
        throw new IllegalStateException(exception);
    }
    // ensure only one thread proceeds from here
    status = -1;
    synchronized (gtx) {
        if ((status = gtx.getStatus()) == Status.STATUS_ACTIVE || status == Status.STATUS_MARKED_ROLLBACK)
            gtx.setStatus(Status.STATUS_ROLLING_BACK);
        else if (gtx.getStatus() == Status.STATUS_ROLLING_BACK) {
            String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_ROLLBACK_TRANSACTION_ALREADY_IN_A_ROLLING_BACK_STATE_TRANSACTIONAL_STATUS_0.toLocalizedString(Integer.valueOf(status));
            if (VERBOSE)
                writer.fine(exception);
            throw new IllegalStateException(exception);
        } else {
            String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_ROLLBACK_TRANSACTION_STATUS_DOES_NOT_ALLOW_ROLLBACK.toLocalizedString();
            if (VERBOSE)
                writer.fine(exception);
            throw new IllegalStateException(exception);
        }
    }
    // Only one thread can call rollback (the first thread to do reach the
    // block above).
    // Before rollback the notifications to be done before the done are called
    // the global transaction is called and then the after completion
    // notifications
    // are taken care of. The transactions associated to the global
    // transactions are
    // removed from the map and also the tread to transaction.
    //
    // TODO remove all threads-transactions (from the map)
    // for transactions participating in the global transaction
    //
    SystemException se = null;
    try {
        gtx.rollback();
    } catch (SystemException se1) {
        se = se1;
    }
    try {
        ((TransactionImpl) transactionImpl).notifyAfterCompletion(gtx.getStatus());
    } catch (Exception e1) {
        if (writer.infoEnabled())
            writer.info(LocalizedStrings.TransactionManagerImpl_EXCEPTION_IN_NOTIFY_AFTER_COMPLETION_DUE_TO__0, e1.getMessage(), e1);
    }
    Thread thread = Thread.currentThread();
    transactionMap.remove(thread);
    this.gtxSet.remove(gtx);
    if (se != null) {
        if (VERBOSE)
            writer.fine(se);
        throw se;
    }
    gtx.setStatus(Status.STATUS_NO_TRANSACTION);
}
Also used : SystemException(javax.transaction.SystemException) Transaction(javax.transaction.Transaction) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) InvalidTransactionException(javax.transaction.InvalidTransactionException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException) HeuristicMixedException(javax.transaction.HeuristicMixedException) CancelException(org.apache.geode.CancelException)

Example 33 with LogWriterI18n

use of org.apache.geode.i18n.LogWriterI18n in project geode by apache.

the class TransactionManagerImpl method getGlobalTransaction.

/**
   * Get the Global Transaction associated with the calling thread
   */
GlobalTransaction getGlobalTransaction(Transaction txn) throws SystemException {
    if (txn == null) {
        String exception = LocalizedStrings.TransactionManagerImpl_TRANSACTIONMANAGERIMPL_GETGLOBALTRANSACTION_NO_TRANSACTION_EXISTS.toLocalizedString();
        LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
        if (VERBOSE)
            writer.fine(exception);
        throw new SystemException(exception);
    }
    GlobalTransaction gtx = (GlobalTransaction) globalTransactionMap.get(txn);
    return gtx;
}
Also used : SystemException(javax.transaction.SystemException) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n)

Example 34 with LogWriterI18n

use of org.apache.geode.i18n.LogWriterI18n in project geode by apache.

the class ContextImpl method lookup.

/**
   * Looks up object with binding name name in this context.
   * 
   * @param name name to look up
   * @return object reference bound to name name.
   * @throws NoPermissionException if this context has been destroyed.
   * @throws InvalidNameException if name is CompositeName that spans more than one naming system
   * @throws NameNotFoundException if name can not be found.
   * @throws NotContextException component of name is not bound to instance of ContextImpl, when
   *         name is not atomic name.
   * @throws NamingException if any other naming error occurs
   * 
   */
public Object lookup(Name name) throws NamingException {
    checkIsDestroyed();
    try {
        Name parsedName = getParsedName(name);
        String nameComponent = parsedName.get(0);
        Object res = ctxMaps.get(nameComponent);
        if (res instanceof UserTransactionImpl) {
            res = new UserTransactionImpl();
        }
        // if not found
        if (!ctxMaps.containsKey(nameComponent)) {
            throw new NameNotFoundException(LocalizedStrings.ContextImpl_NAME_0_NOT_FOUND.toLocalizedString(name));
        } else // if this is a compound name
        if (parsedName.size() > 1) {
            if (res instanceof ContextImpl) {
                res = ((ContextImpl) res).lookup(parsedName.getSuffix(1));
            } else {
                throw new NotContextException(LocalizedStrings.ContextImpl_EXPECTED_CONTEXTIMPL_BUT_FOUND_0.toLocalizedString(res));
            }
        }
        return res;
    } catch (NameNotFoundException e) {
        LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
        if (writer.infoEnabled())
            writer.info(LocalizedStrings.ContextImpl_CONTEXTIMPL_LOOKUP_ERROR_WHILE_LOOKING_UP_0, name, e);
        throw new NameNotFoundException(LocalizedStrings.ContextImpl_NAME_0_NOT_FOUND.toLocalizedString(new Object[] { name }));
    } catch (SystemException se) {
        LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
        if (writer.severeEnabled())
            writer.info(LocalizedStrings.ContextImpl_CONTEXTIMPL_LOOKUP_ERROR_WHILE_CREATING_USERTRANSACTION_OBJECT, se);
        throw new NameNotFoundException(LocalizedStrings.ContextImpl_CONTEXTIMPL_LOOKUP_ERROR_WHILE_CREATING_USERTRANSACTION_OBJECT.toLocalizedString());
    }
}
Also used : NotContextException(javax.naming.NotContextException) SystemException(javax.transaction.SystemException) NameNotFoundException(javax.naming.NameNotFoundException) UserTransactionImpl(org.apache.geode.internal.jta.UserTransactionImpl) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name)

Example 35 with LogWriterI18n

use of org.apache.geode.i18n.LogWriterI18n in project geode by apache.

the class JNDIInvoker method mapDatasource.

/**
   * Binds a single Datasource to the existing JNDI tree. The JNDI tree may be The Datasource
   * properties are contained in the map. The Datasource implementation class is populated based on
   * properties in the map.
   * 
   * @param map contains Datasource configuration properties.
   */
public static void mapDatasource(Map map, List props) {
    String value = (String) map.get("type");
    String jndiName = "";
    LogWriterI18n writer = TransactionUtils.getLogWriterI18n();
    Object ds = null;
    try {
        jndiName = (String) map.get("jndi-name");
        if (value.equals("PooledDataSource")) {
            ds = DataSourceFactory.getPooledDataSource(map, props);
            ctx.rebind("java:/" + jndiName, ds);
            dataSourceList.add(ds);
            if (writer.fineEnabled())
                writer.fine("Bound java:/" + jndiName + " to Context");
        } else if (value.equals("XAPooledDataSource")) {
            ds = DataSourceFactory.getTranxDataSource(map, props);
            ctx.rebind("java:/" + jndiName, ds);
            dataSourceList.add(ds);
            if (writer.fineEnabled())
                writer.fine("Bound java:/" + jndiName + " to Context");
        } else if (value.equals("SimpleDataSource")) {
            ds = DataSourceFactory.getSimpleDataSource(map, props);
            ctx.rebind("java:/" + jndiName, ds);
            if (writer.fineEnabled())
                writer.fine("Bound java:/" + jndiName + " to Context");
        } else if (value.equals("ManagedDataSource")) {
            ClientConnectionFactoryWrapper ds1 = DataSourceFactory.getManagedDataSource(map, props);
            ctx.rebind("java:/" + jndiName, ds1.getClientConnFactory());
            dataSourceList.add(ds1);
            if (writer.fineEnabled())
                writer.fine("Bound java:/" + jndiName + " to Context");
        } else {
            String exception = "JNDIInvoker::mapDataSource::No correct type of DataSource";
            if (writer.fineEnabled())
                writer.fine(exception);
            throw new DataSourceCreateException(exception);
        }
        ds = null;
    } catch (NamingException ne) {
        if (writer.infoEnabled())
            writer.info(LocalizedStrings.JNDIInvoker_JNDIINVOKER_MAPDATASOURCE_0_WHILE_BINDING_1_TO_JNDI_CONTEXT, new Object[] { "NamingException", jndiName });
    } catch (DataSourceCreateException dsce) {
        if (writer.infoEnabled())
            writer.info(LocalizedStrings.JNDIInvoker_JNDIINVOKER_MAPDATASOURCE_0_WHILE_BINDING_1_TO_JNDI_CONTEXT, new Object[] { "DataSourceCreateException", jndiName });
    }
}
Also used : ClientConnectionFactoryWrapper(org.apache.geode.internal.datasource.ClientConnectionFactoryWrapper) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) DataSourceCreateException(org.apache.geode.internal.datasource.DataSourceCreateException)

Aggregations

LogWriterI18n (org.apache.geode.i18n.LogWriterI18n)38 SystemException (javax.transaction.SystemException)11 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)8 HeuristicMixedException (javax.transaction.HeuristicMixedException)4 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)4 InvalidTransactionException (javax.transaction.InvalidTransactionException)4 NotSupportedException (javax.transaction.NotSupportedException)4 RollbackException (javax.transaction.RollbackException)4 CancelException (org.apache.geode.CancelException)4 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)4 Transaction (javax.transaction.Transaction)3 Region (org.apache.geode.cache.Region)3 Test (org.junit.Test)3 Iterator (java.util.Iterator)2 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)2 CacheWriterException (org.apache.geode.cache.CacheWriterException)2 CommitConflictException (org.apache.geode.cache.CommitConflictException)2 CommitIncompleteException (org.apache.geode.cache.CommitIncompleteException)2 Struct (org.apache.geode.cache.query.Struct)2 ClientHealthStats (org.apache.geode.internal.admin.remote.ClientHealthStats)2