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


Java XAResourceProducer类代码示例

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


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

示例1: instantiate

import bitronix.tm.resource.common.XAResourceProducer; //导入依赖的package包/类
/**
 * Create an unitialized {@link XAResourceProducer} implementation which depends on the XA resource class name.
 * @param xaResourceClassName an XA resource class name.
 * @return a {@link XAResourceProducer} implementation.
 * @throws ClassNotFoundException if the {@link XAResourceProducer} cannot be instantiated.
 * @throws IllegalAccessException if the {@link XAResourceProducer} cannot be instantiated.
 * @throws InstantiationException if the {@link XAResourceProducer} cannot be instantiated.
 */
private static XAResourceProducer instantiate(String xaResourceClassName) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
    Class<?> clazz = ClassLoaderUtils.loadClass(xaResourceClassName);

    // resource classes are instantiated via reflection so that there is no hard class binding between this internal
    // transaction manager service and 3rd party libraries like the JMS ones.
    // This allows using the TM with a 100% JDBC application without requiring JMS libraries.

    if (XADataSource.class.isAssignableFrom(clazz)) {
        return (XAResourceProducer) ClassLoaderUtils.loadClass(JDBC_RESOURCE_CLASSNAME).newInstance();
    }
    else if (XAConnectionFactory.class.isAssignableFrom(clazz)) {
        return (XAResourceProducer) ClassLoaderUtils.loadClass(JMS_RESOURCE_CLASSNAME).newInstance();
    }
    else
        return null;
}
 
开发者ID:bitronix,项目名称:btm,代码行数:25,代码来源:ResourceLoader.java

示例2: register

import bitronix.tm.resource.common.XAResourceProducer; //导入依赖的package包/类
/**
 * Register a {@link XAResourceProducer}. If registration happens after the transaction manager started, incremental
 * recovery is run on that resource.
 * @param producer the {@link XAResourceProducer}.
 * @throws RecoveryException When an error happens during recovery.
 */
public static void register(XAResourceProducer producer) throws RecoveryException {
    try {
        final boolean alreadyRunning = TransactionManagerServices.isTransactionManagerRunning();
        final ProducerHolder holder = alreadyRunning ? new InitializableProducerHolder(producer) : new ProducerHolder(producer);

        if (resources.add(holder)) {
            if (holder instanceof InitializableProducerHolder) {
                boolean recovered = false;
                try {
                    if (log.isDebugEnabled()) { log.debug("Transaction manager is running, recovering resource '" + holder.getUniqueName() + "'."); }
                    IncrementalRecoverer.recover(producer);
                    ((InitializableProducerHolder) holder).initialize();
                    recovered = true;
                } finally {
                    if (!recovered) { resources.remove(holder); }
                }
            }
        } else {
            throw new IllegalStateException("A resource with uniqueName '" + holder.getUniqueName() + "' has already been registered. " +
                    "Cannot register XAResourceProducer '" + producer + "'.");
        }
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("Cannot register the XAResourceProducer '" + producer + "' caused by invalid input.", e);
    }
}
 
开发者ID:bitronix,项目名称:btm,代码行数:32,代码来源:ResourceRegistrar.java

示例3: findXAResourceHolder

import bitronix.tm.resource.common.XAResourceProducer; //导入依赖的package包/类
/**
 * Find in the registered {@link XAResourceProducer}s the {@link XAResourceHolder} from which the specified {@link XAResource} comes from.
 *
 * @param xaResource the {@link XAResource} to look for
 * @return the associated {@link XAResourceHolder} or null if it cannot be found.
 */
public static XAResourceHolder findXAResourceHolder(XAResource xaResource) {
    final boolean debug = log.isDebugEnabled();

    for (ProducerHolder holder : resources) {
        if (!holder.isInitialized())
            continue;

        final XAResourceProducer producer = holder.producer;
        final XAResourceHolder resourceHolder = producer.findXAResourceHolder(xaResource);
        if (resourceHolder != null) {
            if (debug) { log.debug("XAResource " + xaResource + " belongs to " + resourceHolder + " that itself belongs to " + producer); }
            return resourceHolder;
        }
        if (debug) { log.debug("XAResource " + xaResource + " does not belong to any resource of " + producer); }
    }

    return null;
}
 
开发者ID:bitronix,项目名称:btm,代码行数:25,代码来源:ResourceRegistrar.java

示例4: ProducerHolder

import bitronix.tm.resource.common.XAResourceProducer; //导入依赖的package包/类
private ProducerHolder(XAResourceProducer producer) {
    if (producer == null)
        throw new IllegalArgumentException("XAResourceProducer may not be 'null'. Verify your call to ResourceRegistrar.[un]register(...).");

    final String uniqueName = producer.getUniqueName();
    if (uniqueName == null || uniqueName.length() == 0)
        throw new IllegalArgumentException("The given XAResourceProducer '" + producer + "' does not specify a uniqueName.");

    final String transcodedUniqueName = new String(uniqueName.getBytes(UNIQUE_NAME_CHARSET), UNIQUE_NAME_CHARSET);
    if (!transcodedUniqueName.equals(uniqueName)) {
        throw new IllegalArgumentException("The given XAResourceProducer's uniqueName '" + uniqueName + "' is not compatible with the charset " +
                "'US-ASCII' (transcoding results in '" + transcodedUniqueName + "'). " + System.getProperty("line.separator") +
                "BTM requires unique names to be compatible with US-ASCII when used with a transaction journal.");
    }

    this.producer = producer;
}
 
开发者ID:bitronix,项目名称:btm,代码行数:18,代码来源:ResourceRegistrar.java

示例5: createMockProducer

import bitronix.tm.resource.common.XAResourceProducer; //导入依赖的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

示例6: registerBlockingProducer

import bitronix.tm.resource.common.XAResourceProducer; //导入依赖的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

示例7: testFindXAResourceHolderDelegatesAndDoesNotCallUninitialized

import bitronix.tm.resource.common.XAResourceProducer; //导入依赖的package包/类
@Test
public void testFindXAResourceHolderDelegatesAndDoesNotCallUninitialized() throws Exception {
    final XAResource resource = mock(XAResource.class);
    final XAResourceProducer uninitializedProducer = createMockProducer("uninitialized");

    CountDownLatch border = new CountDownLatch(1);
    Future future = registerBlockingProducer(uninitializedProducer, border);

    ResourceRegistrar.findXAResourceHolder(resource);
    verify(producer, times(1)).findXAResourceHolder(resource);
    verify(uninitializedProducer, times(0)).findXAResourceHolder(resource);

    border.countDown();
    future.get();

    ResourceRegistrar.findXAResourceHolder(resource);
    verify(producer, times(2)).findXAResourceHolder(resource);
    verify(uninitializedProducer, times(1)).findXAResourceHolder(resource);
}
 
开发者ID:bitronix,项目名称:btm,代码行数:20,代码来源:ResourceRegistrarTest.java

示例8: shutdown

import bitronix.tm.resource.common.XAResourceProducer; //导入依赖的package包/类
@Override
public synchronized void shutdown() {
    if (log.isDebugEnabled()) { log.debug("resource loader has registered " + resourcesByUniqueName.entrySet().size() + " resource(s), unregistering them now"); }
    for (Map.Entry<String, XAResourceProducer> entry : resourcesByUniqueName.entrySet()) {
        XAResourceProducer producer = entry.getValue();
        if (log.isDebugEnabled()) { log.debug("closing " + producer); }
        try {
            producer.close();
        } catch (Exception ex) {
            log.warn("error closing resource " + producer, ex);
        }
    }
    resourcesByUniqueName.clear();
}
 
开发者ID:bitronix,项目名称:btm,代码行数:15,代码来源:ResourceLoader.java

示例9: initXAResourceProducers

import bitronix.tm.resource.common.XAResourceProducer; //导入依赖的package包/类
/**
 * Initialize {@link XAResourceProducer}s given a set of properties.
 * @param properties the properties to use for initialization.
 * @return the number of resources which failed to initialize.
 */
int initXAResourceProducers(Properties properties) {
    Map<String, List<PropertyPair>> entries = buildConfigurationEntriesMap(properties);
    int errorCount = 0;

    for (Map.Entry<String, List<PropertyPair>> entry : entries.entrySet()) {
        String uniqueName = entry.getKey();
        List<PropertyPair> propertyPairs = entry.getValue();
        XAResourceProducer producer = buildXAResourceProducer(uniqueName, propertyPairs);

        if (ResourceRegistrar.get(producer.getUniqueName()) != null) {
            if (log.isDebugEnabled()) { log.debug("resource already registered, skipping it:" + producer.getUniqueName()); }
            continue;
        }

        if (log.isDebugEnabled()) { log.debug("creating resource " + producer); }
        try {
            producer.init();
        } catch (ResourceConfigurationException ex) {
            log.warn("unable to create resource with unique name " + producer.getUniqueName(), ex);
            producer.close();
            errorCount++;
        }

        resourcesByUniqueName.put(producer.getUniqueName(), producer);
    }

    return errorCount;
}
 
开发者ID:bitronix,项目名称:btm,代码行数:34,代码来源:ResourceLoader.java

示例10: createBean

import bitronix.tm.resource.common.XAResourceProducer; //导入依赖的package包/类
/**
 * Create an unpopulated, uninitialized {@link XAResourceProducer} instance depending on the className value.
 * @param configuredName the properties configured name.
 * @param propertyPairs a list of {@link PropertyPair}s.
 * @return a {@link XAResourceProducer}.
 * @throws ClassNotFoundException if the {@link XAResourceProducer} cannot be instantiated.
 * @throws IllegalAccessException if the {@link XAResourceProducer} cannot be instantiated.
 * @throws InstantiationException if the {@link XAResourceProducer} cannot be instantiated.
 */
private XAResourceProducer createBean(String configuredName, List<PropertyPair> propertyPairs) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
    for (PropertyPair propertyPair : propertyPairs) {
        if (propertyPair.getName().equals("className")) {
            String className = propertyPair.getValue();
            XAResourceProducer producer = instantiate(className);
            if (producer == null)
                throw new ResourceConfigurationException("property [className] " +
                        "of resource [" + configuredName + "] in resources configuration file " +
                        "must be the name of a class implementing either javax.sql.XADataSource or javax.jms.XAConnectionFactory");
            return producer;
        }
    }
    throw new ResourceConfigurationException("missing mandatory property [className] for resource [" + configuredName + "] in resources configuration file");
}
 
开发者ID:bitronix,项目名称:btm,代码行数:24,代码来源:ResourceLoader.java

示例11: get

import bitronix.tm.resource.common.XAResourceProducer; //导入依赖的package包/类
/**
 * Get a registered {@link XAResourceProducer}.
 *
 * @param uniqueName the name of the recoverable resource producer.
 * @return the {@link XAResourceProducer} or null if there was none registered under that name.
 */
public static XAResourceProducer get(final String uniqueName) {
    if (uniqueName != null) {
        for (ProducerHolder holder : resources) {
            if (!holder.isInitialized())
                continue;
            if (uniqueName.equals(holder.getUniqueName()))
                return holder.producer;
        }
    }
    return null;
}
 
开发者ID:bitronix,项目名称:btm,代码行数:18,代码来源:ResourceRegistrar.java

示例12: unregister

import bitronix.tm.resource.common.XAResourceProducer; //导入依赖的package包/类
/**
 * Unregister a previously registered {@link XAResourceProducer}.
 * @param producer the {@link XAResourceProducer}.
 */
public static void unregister(XAResourceProducer producer) {
    final ProducerHolder holder = new ProducerHolder(producer);

    if (!resources.remove(holder)) {
        if (log.isDebugEnabled()) { log.debug("resource with uniqueName '{}' has not been registered", holder.getUniqueName()); }
    }
}
 
开发者ID:bitronix,项目名称:btm,代码行数:12,代码来源:ResourceRegistrar.java

示例13: recover

import bitronix.tm.resource.common.XAResourceProducer; //导入依赖的package包/类
/**
 * Run the recovery process on the target resource.
 * Step 1.
 * @return a Set of BitronixXids.
 * @param producer the {@link XAResourceProducer} to recover.
 * @throws javax.transaction.xa.XAException if {@link XAResource#recover(int)} call fails.
 * @throws RecoveryException if an error preventing recovery happened.
 */
private Set<BitronixXid> recover(XAResourceProducer producer) throws XAException, RecoveryException {
    if (producer == null)
        throw new IllegalArgumentException("recoverable resource cannot be null");

    try {
        if (log.isDebugEnabled()) { log.debug("running recovery on " + producer); }
        XAResourceHolderState xaResourceHolderState = producer.startRecovery();
        return RecoveryHelper.recover(xaResourceHolderState);
    } finally {
        producer.endRecovery();
    }
}
 
开发者ID:bitronix,项目名称:btm,代码行数:21,代码来源:Recoverer.java

示例14: commit

import bitronix.tm.resource.common.XAResourceProducer; //导入依赖的package包/类
/**
 * Commit the specified branch of a dangling transaction.
 * Step 2.
 * @param uniqueName the unique name of the resource on which the commit should be done.
 * @param xid the {@link Xid} to commit.
 * @return true when commit was successful.
 * @throws RecoveryException if an error preventing recovery happened.
 */
private boolean commit(String uniqueName, Xid xid) throws RecoveryException {
    XAResourceProducer producer = registeredResources.get(uniqueName);
    try {
        XAResourceHolderState xaResourceHolderState = producer.startRecovery();
        return RecoveryHelper.commit(xaResourceHolderState, xid);
    } finally {
        producer.endRecovery();
    }
}
 
开发者ID:bitronix,项目名称:btm,代码行数:18,代码来源:Recoverer.java

示例15: rollback

import bitronix.tm.resource.common.XAResourceProducer; //导入依赖的package包/类
/**
 * Rollback the specified branch of a dangling transaction.
 * Step 3.
 * @param uniqueName the unique name of the resource on which to rollback branches.
 * @param xid the {@link Xid} to rollback.
 * @return true when rollback was successful.
 * @throws RecoveryException if an error preventing recovery happened.
 */
private boolean rollback(String uniqueName, Xid xid) throws RecoveryException {
    XAResourceProducer producer = registeredResources.get(uniqueName);
    if (producer == null) {
        if (log.isDebugEnabled()) { log.debug("resource " + uniqueName + " has not recovered, skipping rollback"); }
        return false;
    }

    try {
        XAResourceHolderState xaResourceHolderState = producer.startRecovery();
        return RecoveryHelper.rollback(xaResourceHolderState, xid);
    } finally {
        producer.endRecovery();
    }
}
 
开发者ID:bitronix,项目名称:btm,代码行数:23,代码来源:Recoverer.java


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