当前位置: 首页>>代码示例>>Java>>正文


Java XAResourceHolderState类代码示例

本文整理汇总了Java中bitronix.tm.internal.XAResourceHolderState的典型用法代码示例。如果您正苦于以下问题:Java XAResourceHolderState类的具体用法?Java XAResourceHolderState怎么用?Java XAResourceHolderState使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


XAResourceHolderState类属于bitronix.tm.internal包,在下文中一共展示了XAResourceHolderState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRecovery

import bitronix.tm.internal.XAResourceHolderState; //导入依赖的package包/类
@Test
public void testRecovery() throws RecoveryException {
	MicroserviceResourceFactory msrFactory = mock(MicroserviceResourceFactory.class);
	when(msrFactory.build()).thenReturn(new MicroserviceXAResource("a", null));
	MicroserviceResourceProducer.registerMicroserviceResourceFactory("a", msrFactory);
	MicroserviceResourceProducer producer = MicroserviceResourceProducer.getProducers().values().iterator().next();
	
	XAResourceHolderState rh = producer.startRecovery();
	assertTrue(rh.getXAResource() instanceof MicroserviceXAResource);
	
	try{
       	//TEST
		rh = producer.startRecovery();
		fail("no exception");
	}catch(RecoveryException e){
		//ok, since recovery is already started
	}
	
   	//TEST
	producer.endRecovery(); //check theres no exception
}
 
开发者ID:maxant,项目名称:genericconnector,代码行数:22,代码来源:MicroserviceResourceProducerTest.java

示例2: getLatestAlreadyEnlistedXAResourceHolderState

import bitronix.tm.internal.XAResourceHolderState; //导入依赖的package包/类
private static XAResourceHolderState getLatestAlreadyEnlistedXAResourceHolderState(XAResourceHolder xaResourceHolder, final BitronixTransaction currentTransaction) {
    if (currentTransaction == null)
        return null;

    class LocalVisitor implements XAResourceHolderStateVisitor {
        private XAResourceHolderState latestEnlistedHolder;

        @Override
        public boolean visit(XAResourceHolderState xaResourceHolderState) {
            if (xaResourceHolderState != null && xaResourceHolderState.getXid() != null) {
                BitronixXid bitronixXid = xaResourceHolderState.getXid();
                Uid resourceGtrid = bitronixXid.getGlobalTransactionIdUid();
                Uid currentTransactionGtrid = currentTransaction.getResourceManager().getGtrid();

                if (currentTransactionGtrid.equals(resourceGtrid)) {
                    latestEnlistedHolder = xaResourceHolderState;
                }
            }
            return true;  // continue visitation
        }
    }
    LocalVisitor xaResourceHolderStateVisitor = new LocalVisitor();
    xaResourceHolder.acceptVisitorForXAResourceHolderStates(currentTransaction.getResourceManager().getGtrid(), xaResourceHolderStateVisitor);

    return xaResourceHolderStateVisitor.latestEnlistedHolder;
}
 
开发者ID:bitronix,项目名称:btm,代码行数:27,代码来源:TransactionContextHelper.java

示例3: acceptVisitorForXAResourceHolderStates

import bitronix.tm.internal.XAResourceHolderState; //导入依赖的package包/类
@Override
public void acceptVisitorForXAResourceHolderStates(Uid gtrid, XAResourceHolderStateVisitor visitor) {
    rwLock.readLock().lock();
    try {
        Map<Uid, XAResourceHolderState> statesForGtrid = xaResourceHolderStates.get(gtrid);
        if (statesForGtrid != null) {
            for (XAResourceHolderState xaResourceHolderState : statesForGtrid.values()) {
                if (!visitor.visit(xaResourceHolderState)) {
                    break;
                }
            }
        }
    } finally {
        rwLock.readLock().unlock();
    }
}
 
开发者ID:bitronix,项目名称:btm,代码行数:17,代码来源:AbstractXAResourceHolder.java

示例4: hasStateForXAResource

import bitronix.tm.internal.XAResourceHolderState; //导入依赖的package包/类
@Override
public boolean hasStateForXAResource(XAResourceHolder<? extends XAResourceHolder> xaResourceHolder) {
    rwLock.readLock().lock();
    try {
        for (Map<Uid, XAResourceHolderState> statesForGtrid : xaResourceHolderStates.values()) {
            for (XAResourceHolderState otherXaResourceHolderState : statesForGtrid.values()) {
                if (otherXaResourceHolderState.getXAResource() == xaResourceHolder.getXAResource()) {
                    if (log.isDebugEnabled()) { log.debug("resource " + xaResourceHolder + " is enlisted in another transaction with " + otherXaResourceHolderState.getXid().toString()); }
                    return true;
                }
            }
        }

        if (log.isDebugEnabled()) { log.debug("resource not enlisted in any transaction: " + xaResourceHolder); }
        return false;
    }
    finally {
        rwLock.readLock().unlock();
    }
}
 
开发者ID:bitronix,项目名称:btm,代码行数:21,代码来源:AbstractXAResourceHolder.java

示例5: isParticipatingInActiveGlobalTransaction

import bitronix.tm.internal.XAResourceHolderState; //导入依赖的package包/类
/**
 * If this method returns false, then local transaction calls like Connection.commit() can be made.
 * @return true if start() has been successfully called but not end() yet <i>and</i> the transaction is not suspended.
 */
public boolean isParticipatingInActiveGlobalTransaction() {
    rwLock.readLock().lock();
    try {
        BitronixTransaction currentTransaction = TransactionContextHelper.currentTransaction();
        Uid gtrid = currentTransaction == null ? null : currentTransaction.getResourceManager().getGtrid();
        if (gtrid == null)
            return false;

        Map<Uid, XAResourceHolderState> statesForGtrid = xaResourceHolderStates.get(gtrid);
        if (statesForGtrid == null)
            return false;

        for (XAResourceHolderState xaResourceHolderState : statesForGtrid.values()) {
            if (xaResourceHolderState != null &&
                    xaResourceHolderState.isStarted() &&
                    !xaResourceHolderState.isSuspended() &&
                    !xaResourceHolderState.isEnded())
                return true;
        }
        return false;
    }
    finally {
        rwLock.readLock().unlock();
    }
}
 
开发者ID:bitronix,项目名称:btm,代码行数:30,代码来源:AbstractXAResourceHolder.java

示例6: collectResourcesNames

import bitronix.tm.internal.XAResourceHolderState; //导入依赖的package包/类
/**
 * Create a String representation of a list of {@link bitronix.tm.resource.common.XAResourceHolder}s. This
 * String will contain each resource's unique name.
 * @param resources a list of {@link bitronix.tm.resource.common.XAResourceHolder}s.
 * @return a String representation of the list.
 */
public static String collectResourcesNames(Collection<XAResourceHolderState> resources) {
    StringBuilder sb = new StringBuilder();
    sb.append("[");

    Iterator<XAResourceHolderState> it = resources.iterator();
    while (it.hasNext()) {
        XAResourceHolderState resourceHolderState = it.next();
        sb.append(resourceHolderState.getUniqueName());

        if (it.hasNext())
            sb.append(", ");
    }

    sb.append("]");
    return sb.toString();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:23,代码来源:Decoder.java

示例7: delistResource

import bitronix.tm.internal.XAResourceHolderState; //导入依赖的package包/类
private boolean delistResource(XAResourceHolderState resourceHolderState, int flag) throws BitronixSystemException {
    try {
       return resourceManager.delist(resourceHolderState, flag);
    }
    catch (XAException ex) {
        // if the resource could not be delisted, the transaction must not commit -> mark it as rollback only
        if (status != Status.STATUS_MARKED_ROLLBACK)
            setStatus(Status.STATUS_MARKED_ROLLBACK);

        String extraErrorDetails = TransactionManagerServices.getExceptionAnalyzer().extractExtraXAExceptionDetails(ex);
        if (BitronixXAException.isUnilateralRollback(ex)) {
            // The resource unilaterally rolled back here. We have to throw an exception to indicate this but
            // The signature of this method is inherited from javax.transaction.Transaction. Thereof, we have choice
            // between creating a sub-exception of SystemException or using a RuntimeException. Is that the best way
            // forward as this 'hidden' exception can be left throw out at unexpected locations where SystemException
            // should be rethrown but the exception thrown here should be catched & handled... ?
            throw new BitronixRollbackSystemException("resource " + resourceHolderState + " unilaterally rolled back, error=" +
                    Decoder.decodeXAExceptionErrorCode(ex) + (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex);
        }
        throw new BitronixSystemException("cannot delist " + resourceHolderState + ", error=" + Decoder.decodeXAExceptionErrorCode(ex) +
                (extraErrorDetails == null ? "" : ", extra error=" + extraErrorDetails), ex);
    }
}
 
开发者ID:bitronix,项目名称:btm,代码行数:24,代码来源:BitronixTransaction.java

示例8: rollbackPrepareFailure

import bitronix.tm.internal.XAResourceHolderState; //导入依赖的package包/类
/**
 * Rollback resources after a phase 1 prepare failure. All resources must be rolled back as prepared ones
 * are in-doubt and non-prepared ones have started/ended work done that must also be cleaned.
 * @param rbEx the thrown rollback exception.
 * @throws BitronixSystemException when a resource could not rollback prepapared state.
 */
private void rollbackPrepareFailure(RollbackException rbEx) throws BitronixSystemException {
    List<XAResourceHolderState> interestedResources = resourceManager.getAllResources();
    try {
        rollbacker.rollback(this, interestedResources);
        if (log.isDebugEnabled()) { log.debug("rollback after prepare failure succeeded"); }
    } catch (Exception ex) {
        // let's merge both exceptions' PhaseException to report a complete error message
        PhaseException preparePhaseEx = (PhaseException) rbEx.getCause();
        PhaseException rollbackPhaseEx = (PhaseException) ex.getCause();

        List<Exception> exceptions = new ArrayList<Exception>();
        List<XAResourceHolderState> resources = new ArrayList<XAResourceHolderState>();

        exceptions.addAll(preparePhaseEx.getExceptions());
        exceptions.addAll(rollbackPhaseEx.getExceptions());
        resources.addAll(preparePhaseEx.getResourceStates());
        resources.addAll(rollbackPhaseEx.getResourceStates());

        throw new BitronixSystemException("transaction partially prepared and only partially rolled back. Some resources might be left in doubt!", new PhaseException(exceptions, resources));
    }
}
 
开发者ID:bitronix,项目名称:btm,代码行数:28,代码来源:BitronixTransaction.java

示例9: handleXAException

import bitronix.tm.internal.XAResourceHolderState; //导入依赖的package包/类
private void handleXAException(XAResourceHolderState failedResourceHolder, XAException xaException) throws XAException {
    switch (xaException.errorCode) {
        case XAException.XA_HEURRB:
            forgetHeuristicRollback(failedResourceHolder);
            return;

        case XAException.XA_HEURCOM:
        case XAException.XA_HEURHAZ:
        case XAException.XA_HEURMIX:
            log.error("heuristic rollback is incompatible with the global state of this transaction - guilty: " + failedResourceHolder);
            throw xaException;

        default:
            String extraErrorDetails = TransactionManagerServices.getExceptionAnalyzer().extractExtraXAExceptionDetails(xaException);
            log.warn("resource '" + failedResourceHolder.getUniqueName() + "' reported " + Decoder.decodeXAExceptionErrorCode(xaException) +
                    " when asked to rollback transaction branch. Transaction is prepared and will rollback via recovery service when resource availability allows."
                    + (extraErrorDetails == null ? "" : " Extra error=" + extraErrorDetails), xaException);
    }
}
 
开发者ID:bitronix,项目名称:btm,代码行数:20,代码来源:Rollbacker.java

示例10: createMockProducer

import bitronix.tm.internal.XAResourceHolderState; //导入依赖的package包/类
private XAResourceProducer createMockProducer(String uniqueName) throws RecoveryException {
    XAResourceProducer producer;
    producer = mock(XAResourceProducer.class);
    when(producer.getUniqueName()).thenReturn(uniqueName);

    ResourceBean resourceBean = mock(ResourceBean.class);
    when(resourceBean.getUniqueName()).thenReturn(uniqueName);

    XAResourceHolder resourceHolder = mock(XAResourceHolder.class);
    when(resourceHolder.getResourceBean()).thenReturn(resourceBean);

    XAResource xaResource = mock(XAResource.class);
    when(resourceHolder.getXAResource()).thenReturn(xaResource);

    when(producer.startRecovery()).thenReturn(new XAResourceHolderState(resourceHolder, resourceBean));
    return producer;
}
 
开发者ID:bitronix,项目名称:btm,代码行数:18,代码来源:ResourceRegistrarTest.java

示例11: registerBlockingProducer

import bitronix.tm.internal.XAResourceHolderState; //导入依赖的package包/类
private Future registerBlockingProducer(final XAResourceProducer producer, final CountDownLatch border) throws RecoveryException {
    final XAResourceHolderState resourceHolderState = producer.startRecovery();
    when(producer.startRecovery()).thenAnswer(new Answer<Object>() {
        public Object answer(InvocationOnMock invocation) throws Throwable {
            border.await();
            return resourceHolderState;
        }
    });

    return executorService.submit(new Callable<Object>() {
        public Object call() throws Exception {
            ResourceRegistrar.register(producer);
            return null;
        }
    });
}
 
开发者ID:bitronix,项目名称:btm,代码行数:17,代码来源:ResourceRegistrarTest.java

示例12: testRemove

import bitronix.tm.internal.XAResourceHolderState; //导入依赖的package包/类
public void testRemove() {
    Scheduler<XAResourceHolderState> resourceScheduler = new Scheduler<XAResourceHolderState>();

    XAResourceHolderState xarhs0 = new XAResourceHolderState(null, new MockResourceBean(0));
    XAResourceHolderState xarhs1 = new XAResourceHolderState(null, new MockResourceBean(1));

    resourceScheduler.add(xarhs0, xarhs0.getTwoPcOrderingPosition());
    resourceScheduler.add(xarhs1, xarhs1.getTwoPcOrderingPosition());

    resourceScheduler.remove(xarhs0);
    resourceScheduler.add(xarhs0, xarhs0.getTwoPcOrderingPosition());

    Iterator<XAResourceHolderState> it = resourceScheduler.iterator();
    assertTrue(it.hasNext());
    assertTrue(xarhs0 == it.next());
    it.remove();
    assertTrue(xarhs1 == it.next());
    it.remove();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:20,代码来源:SchedulerTest.java

示例13: testReverseRemove

import bitronix.tm.internal.XAResourceHolderState; //导入依赖的package包/类
public void testReverseRemove() {
    Scheduler<XAResourceHolderState> resourceScheduler = new Scheduler<XAResourceHolderState>();

    XAResourceHolderState xarhs0 = new XAResourceHolderState(null, new MockResourceBean(0));
    XAResourceHolderState xarhs1 = new XAResourceHolderState(null, new MockResourceBean(1));

    resourceScheduler.add(xarhs0, xarhs0.getTwoPcOrderingPosition());
    resourceScheduler.add(xarhs1, xarhs1.getTwoPcOrderingPosition());

    resourceScheduler.remove(xarhs0);
    resourceScheduler.add(xarhs0, xarhs0.getTwoPcOrderingPosition());

    Iterator<XAResourceHolderState> it = resourceScheduler.reverseIterator();
    assertTrue(it.hasNext());
    assertTrue(xarhs1 == it.next());
    it.remove();
    assertTrue(xarhs0 == it.next());
    it.remove();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:20,代码来源:SchedulerTest.java

示例14: startRecovery

import bitronix.tm.internal.XAResourceHolderState; //导入依赖的package包/类
@Override
public XAResourceHolderState startRecovery() throws RecoveryException {
    init();
    if (recoveryConnectionHandle != null)
        throw new RecoveryException("recovery already in progress on " + this);

    try {
        recoveryConnectionHandle = (Connection) pool.getConnectionHandle(false);
        PooledConnectionProxy pooledConnection = (PooledConnectionProxy) recoveryConnectionHandle;
        recoveryXAResourceHolder = pooledConnection.getPooledConnection().createRecoveryXAResourceHolder();
        return new XAResourceHolderState(pooledConnection.getPooledConnection(), this);
    } catch (Exception ex) {
        throw new RecoveryException("cannot start recovery on " + this, ex);
    }
}
 
开发者ID:bitronix,项目名称:btm,代码行数:16,代码来源:PoolingDataSource.java

示例15: startRecovery

import bitronix.tm.internal.XAResourceHolderState; //导入依赖的package包/类
@Override
public XAResourceHolderState startRecovery() throws RecoveryException {
    init();
    if (recoveryPooledConnection != null)
        throw new RecoveryException("recovery already in progress on " + this);

    try {
        recoveryConnectionHandle = (JmsConnectionHandle) pool.getConnectionHandle(false);
        recoveryPooledConnection = recoveryConnectionHandle.getPooledConnection();
        recoveryXAResourceHolder = recoveryPooledConnection.createRecoveryXAResourceHolder();
        return new XAResourceHolderState(recoveryXAResourceHolder, recoveryPooledConnection.getPoolingConnectionFactory());
    } catch (Exception ex) {
        throw new RecoveryException("error starting recovery", ex);
    }
}
 
开发者ID:bitronix,项目名称:btm,代码行数:16,代码来源:PoolingConnectionFactory.java


注:本文中的bitronix.tm.internal.XAResourceHolderState类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。