Package org.apache.geronimo.transaction.context

Examples of org.apache.geronimo.transaction.context.TransactionContext


        for (long i = 0; i < COUNT; i++) {
            workInfos[(int) i] = timer.scheduleAtFixedRate(key, userTaskFactory, userId, userKey, DELAY, DELAY);
        }
        Thread.currentThread().sleep(SLOP + DELAY);
        assertEquals(COUNT, counter.get());
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        for (int i = 0; i < workInfos.length; i++) {
            workInfos[i].getExecutorFeedingTimerTask().cancel();
        }
        Thread.currentThread().sleep(SLOP + DELAY);
        assertEquals(COUNT, counter.get());
        transactionContext.commit();
        Thread.currentThread().sleep(SLOP + DELAY);
        assertEquals(COUNT, counter.get());
    }
View Full Code Here


        for (long i = 0; i < COUNT; i++) {
            workInfos[(int) i] = timer.scheduleAtFixedRate(key, userTaskFactory, userId, userKey, DELAY, DELAY);
        }
        Thread.currentThread().sleep(SLOP + DELAY);
        assertEquals(COUNT, counter.get());
        TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
        for (int i = 0; i < workInfos.length; i++) {
            workInfos[i].getExecutorFeedingTimerTask().cancel();
        }
        Thread.currentThread().sleep(SLOP + DELAY);
        assertEquals(COUNT, counter.get());
        transactionContext.rollback();
        Thread.currentThread().sleep(SLOP + DELAY);
        // Catches up with two periods.
        assertEquals(3 * COUNT, counter.get());
    }
View Full Code Here

    public void main(String[] args) throws Exception {
        Thread thread = Thread.currentThread();

        ClassLoader contextClassLoader = thread.getContextClassLoader();
        thread.setContextClassLoader(classLoader);
        TransactionContext oldTransactionContext = transactionContextManager.getContext();
        TransactionContext currentTransactionContext = null;
        try {
            jndiContext.startClient(appClientModuleName);
            currentTransactionContext = transactionContextManager.newUnspecifiedTransactionContext();
            mainMethod.invoke(null, new Object[]{args});

        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            if (cause instanceof Exception) {
                throw (Exception) cause;
            } else if (cause instanceof Error) {
                throw (Error) cause;
            }
            throw new Error(e);
        } finally {
            jndiContext.stopClient(appClientModuleName);

            thread.setContextClassLoader(contextClassLoader);
            transactionContextManager.setContext(oldTransactionContext);
            currentTransactionContext.commit();
        }
    }
View Full Code Here

    public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
        next.getConnection(connectionInfo);
        try {
            ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
            TransactionContext transactionContext = transactionContextManager.getContext();
            if (transactionContext != null && transactionContext.isActive()) {
                XAResource xares = mci.getXAResource();
                transactionContext.getTransaction().enlistResource(xares);
            }

        } catch (SystemException e) {
            throw new ResourceException("Could not get transaction", e);
        } catch (RollbackException e) {
View Full Code Here

     */
    public void returnConnection(ConnectionInfo connectionInfo,
                                 ConnectionReturnAction connectionReturnAction) {
        try {
            ManagedConnectionInfo mci = connectionInfo.getManagedConnectionInfo();
            TransactionContext transactionContext = transactionContextManager.getContext();
            if (transactionContext != null && transactionContext.isActive()) {
                XAResource xares = mci.getXAResource();
                transactionContext.getTransaction().delistResource(xares, XAResource.TMSUSPEND);
            }

        } catch (SystemException e) {
            //maybe we should warn???
            connectionReturnAction = ConnectionReturnAction.DESTROY;
View Full Code Here

        try {
            // set up java:comp JNDI Context
            RootContext.setComponentContext(componentContext);


            TransactionContext oldTransactionContext = transactionContextManager.getContext();
            TransactionContext newTransactionContext = null;
            if (oldTransactionContext == null || !(oldTransactionContext instanceof InheritableTransactionContext)) {
                newTransactionContext = transactionContextManager.newUnspecifiedTransactionContext();
            }

            try {
                try {
                    oldInstanceContext = trackedConnectionAssociator.enter(new DefaultInstanceContext(unshareableResources, applicationManagedSecurityResources));
                } catch (ResourceException e) {
                    throw new RuntimeException(e);
                }

                super.handle(pathInContext, pathParams, httpRequest, httpResponse);
            } finally {
                try {
                    if (newTransactionContext != null) {
                        if (newTransactionContext != transactionContextManager.getContext()) {
                            transactionContextManager.getContext().rollback();
                            newTransactionContext.rollback();
                            throw new HttpException(500, "WRONG EXCEPTION! returned from servlet call with wrong tx context");
                        }
                        newTransactionContext.commit();

                    } else {
                        if (oldTransactionContext != transactionContextManager.getContext()) {
                            if (transactionContextManager.getContext() != null) {
                                transactionContextManager.getContext().rollback();
View Full Code Here

            ReadOnlyContext oldComponentContext = RootContext.getComponentContext();
            InstanceContext oldInstanceContext = null;
            try {
                RootContext.setComponentContext(componentContext);
//TODO FIXME!!!
                TransactionContext transactionContext = transactionContextManager.getContext();
                if (transactionContext == null) {
                    transactionContext = transactionContextManager.newUnspecifiedTransactionContext();
                } else {
                    transactionContext = null;
                }

                try {

                    try {
                        oldInstanceContext = trackedConnectionAssociator.enter(new DefaultInstanceContext(unshareableResources, applicationManagedSecurityResources));
                    } catch (ResourceException e) {
                        throw new RuntimeException(e);
                    }

                    super.doStart();
                } finally {
                    if (transactionContext != null) {
                        transactionContextManager.setContext(null);
                        try {
                            transactionContext.commit();
                        } catch (Exception e) {
                            //TODO this is undoubtedly the wrong error code!
                            throw (HttpException) new HttpException(500, "Problem committing unspecified transaction context").initCause(e);
                        }
                    }
View Full Code Here

            ReadOnlyContext oldComponentContext = RootContext.getComponentContext();
            InstanceContext oldInstanceContext = null;
            try {
                RootContext.setComponentContext(componentContext);

                TransactionContext transactionContext = transactionContextManager.getContext();
                if (transactionContext == null) {
                    transactionContext = transactionContextManager.newUnspecifiedTransactionContext();
                } else {
                    transactionContext = null;
                }
                try {

                    try {
                        oldInstanceContext = trackedConnectionAssociator.enter(new DefaultInstanceContext(unshareableResources, applicationManagedSecurityResources));
                    } catch (ResourceException e) {
                        throw new RuntimeException(e);
                    }

                    while (true) {
                        try {
                            super.doStop();
                            break;
                        } catch (InterruptedException e) {
                            continue;
                        }
                    }
                } finally {
                    if (transactionContext != null) {
                        transactionContextManager.setContext(null);
                        try {
                            transactionContext.commit();
                        } catch (Exception e) {
                            //TODO this is undoubtedly the wrong error code!
                            throw (HttpException) new HttpException(500, "Problem committing unspecified transaction context").initCause(e);
                        }
                    }
View Full Code Here

        workInfo.initialize(worker, executorTask);
        return workInfo;
    }

    void registerSynchronization(Synchronization sync) throws RollbackException, SystemException {
        TransactionContext transactionContext = transactionContextManager.getContext();
        //TODO move the registerSynchronization to the TransactionContext
        Transaction transaction = transactionContext == null? null: transactionContext.getTransaction();
        if (transaction == null) {
            sync.beforeCompletion();
            sync.afterCompletion(Status.STATUS_COMMITTED);
        } else {
            assert transactionContext.isActive(): "Trying to register a sync on an inactive transaction context";
            transaction.registerSynchronization(sync);
        }
    }
View Full Code Here

    public TransactionCachingInterceptor(final ConnectionInterceptor next) {
        this.next = next;
    }

    public void getConnection(ConnectionInfo connectionInfo) throws ResourceException {
        TransactionContext transactionContext = TransactionContext.getContext();
        ManagedConnectionInfos managedConnectionInfos = (ManagedConnectionInfos) transactionContext.getManagedConnectionInfo(this);
        if (managedConnectionInfos == null) {
            managedConnectionInfos = new ManagedConnectionInfos();
            transactionContext.setManagedConnectionInfo(this, managedConnectionInfos);
        }
        if (connectionInfo.isUnshareable()) {
            if (!managedConnectionInfos.containsUnshared(connectionInfo.getManagedConnectionInfo())) {
                next.getConnection(connectionInfo);
                managedConnectionInfos.addUnshared(connectionInfo.getManagedConnectionInfo());
View Full Code Here

TOP

Related Classes of org.apache.geronimo.transaction.context.TransactionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.