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


Java ConnectionContext.isInTransaction方法代码示例

本文整理汇总了Java中org.apache.activemq.broker.ConnectionContext.isInTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectionContext.isInTransaction方法的具体用法?Java ConnectionContext.isInTransaction怎么用?Java ConnectionContext.isInTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.activemq.broker.ConnectionContext的用法示例。


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

示例1: doMessageSend

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
/**
 * do send the message - this needs to be synchronized to ensure messages
 * are stored AND dispatched in the right order
 *
 * @param producerExchange
 * @param message
 * @throws IOException
 * @throws Exception
 */
synchronized void doMessageSend(final ProducerBrokerExchange producerExchange, final Message message)
        throws IOException, Exception {
    final ConnectionContext context = producerExchange.getConnectionContext();
    message.setRegionDestination(this);
    message.getMessageId().setBrokerSequenceId(getDestinationSequenceId());
    Future<Object> result = null;

    if (topicStore != null && message.isPersistent() && !canOptimizeOutPersistence()) {
        if (systemUsage.getStoreUsage().isFull(getStoreUsageHighWaterMark())) {
            final String logMessage = "Persistent store is Full, " + getStoreUsageHighWaterMark() + "% of "
                    + systemUsage.getStoreUsage().getLimit() + ". Stopping producer (" + message.getProducerId()
                    + ") to prevent flooding " + getActiveMQDestination().getQualifiedName() + "."
                    + " See http://activemq.apache.org/producer-flow-control.html for more info";
            if (!context.isNetworkConnection() && systemUsage.isSendFailIfNoSpace()) {
                throw new javax.jms.ResourceAllocationException(logMessage);
            }

            waitForSpace(context,producerExchange, systemUsage.getStoreUsage(), getStoreUsageHighWaterMark(), logMessage);
        }
        result = topicStore.asyncAddTopicMessage(context, message,isOptimizeStorage());
    }

    message.incrementReferenceCount();

    if (context.isInTransaction()) {
        context.getTransaction().addSynchronization(new Synchronization() {
            @Override
            public void afterCommit() throws Exception {
                // It could take while before we receive the commit
                // operation.. by that time the message could have
                // expired..
                if (broker.isExpired(message)) {
                    getDestinationStatistics().getExpired().increment();
                    broker.messageExpired(context, message, null);
                    message.decrementReferenceCount();
                    return;
                }
                try {
                    dispatch(context, message);
                } finally {
                    message.decrementReferenceCount();
                }
            }
        });

    } else {
        try {
            dispatch(context, message);
        } finally {
            message.decrementReferenceCount();
        }
    }

    if (result != null && !result.isCancelled()) {
        try {
            result.get();
        } catch (CancellationException e) {
            // ignore - the task has been cancelled if the message
            // has already been deleted
        }
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:72,代码来源:Topic.java

示例2: acknowledge

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
@Override
public synchronized void acknowledge(final ConnectionContext context, final MessageAck ack) throws Exception {
    super.acknowledge(context, ack);

    // Handle the standard acknowledgment case.
    if (ack.isStandardAck() || ack.isPoisonAck() || ack.isIndividualAck()) {
        if (context.isInTransaction()) {
            context.getTransaction().addSynchronization(new Synchronization() {

                @Override
                public void afterCommit() throws Exception {
                   synchronized (TopicSubscription.this) {
                        if (singleDestination && destination != null) {
                            destination.getDestinationStatistics().getDequeues().add(ack.getMessageCount());
                        }
                    }
                    dequeueCounter.addAndGet(ack.getMessageCount());
                    dispatchMatched();
                }
            });
        } else {
            if (singleDestination && destination != null) {
                destination.getDestinationStatistics().getDequeues().add(ack.getMessageCount());
                destination.getDestinationStatistics().getInflight().subtract(ack.getMessageCount());
            }
            dequeueCounter.addAndGet(ack.getMessageCount());
        }
        dispatchMatched();
        return;
    } else if (ack.isDeliveredAck()) {
        // Message was delivered but not acknowledged: update pre-fetch counters.
        // also. get these for a consumer expired message.
        if (destination != null && !ack.isInTransaction()) {
            destination.getDestinationStatistics().getDequeues().add(ack.getMessageCount());
            destination.getDestinationStatistics().getInflight().subtract(ack.getMessageCount());
        }
        dequeueCounter.addAndGet(ack.getMessageCount());
        dispatchMatched();
        return;
    } else if (ack.isRedeliveredAck()) {
        // nothing to do atm
        return;
    }
    throw new JMSException("Invalid acknowledgment: " + ack);
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:46,代码来源:TopicSubscription.java

示例3: doMessageSend

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
void doMessageSend(final ProducerBrokerExchange producerExchange, final Message message) throws IOException,
        Exception {
    final ConnectionContext context = producerExchange.getConnectionContext();
    Future<Object> result = null;

    producerExchange.incrementSend();
    checkUsage(context, producerExchange, message);
    sendLock.lockInterruptibly();
    try {
        if (store != null && message.isPersistent()) {
            message.getMessageId().setBrokerSequenceId(getDestinationSequenceId());
            if (messages.isCacheEnabled()) {
                result = store.asyncAddQueueMessage(context, message, isOptimizeStorage());
            } else {
                store.addMessage(context, message);
            }
            if (isReduceMemoryFootprint()) {
                message.clearMarshalledState();
            }
        }
        if (context.isInTransaction()) {
            // If this is a transacted message.. increase the usage now so that
            // a big TX does not blow up
            // our memory. This increment is decremented once the tx finishes..
            message.incrementReferenceCount();

            registerSendSync(message, context);
        } else {
            // Add to the pending list, this takes care of incrementing the
            // usage manager.
            sendMessage(message);
        }
    } finally {
        sendLock.unlock();
    }
    if (!context.isInTransaction()) {
        messageSent(context, message);
    }
    if (result != null && !result.isCancelled()) {
        try {
            result.get();
        } catch (CancellationException e) {
            // ignore - the task has been cancelled if the message
            // has already been deleted
        }
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:48,代码来源:Queue.java

示例4: acknowledge

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
/**
 */
public void acknowledge(ConnectionContext context, String clientId, String subscriptionName,
                        final MessageId messageId, MessageAck originalAck) throws IOException {
    final boolean debug = LOG.isDebugEnabled();

    JournalTopicAck ack = new JournalTopicAck();
    ack.setDestination(destination);
    ack.setMessageId(messageId);
    ack.setMessageSequenceId(messageId.getBrokerSequenceId());
    ack.setSubscritionName(subscriptionName);
    ack.setClientId(clientId);
    ack.setTransactionId(context.getTransaction() != null
        ? context.getTransaction().getTransactionId() : null);
    final RecordLocation location = peristenceAdapter.writeCommand(ack, false);

    final SubscriptionKey key = new SubscriptionKey(clientId, subscriptionName);
    if (!context.isInTransaction()) {
        if (debug) {
            LOG.debug("Journalled acknowledge for: " + messageId + ", at: " + location);
        }
        acknowledge(messageId, location, key);
    } else {
        if (debug) {
            LOG.debug("Journalled transacted acknowledge for: " + messageId + ", at: " + location);
        }
        synchronized (this) {
            inFlightTxLocations.add(location);
        }
        transactionStore.acknowledge(this, ack, location);
        context.getTransaction().addSynchronization(new Synchronization() {
            public void afterCommit() throws Exception {
                if (debug) {
                    LOG.debug("Transacted acknowledge commit for: " + messageId + ", at: " + location);
                }
                synchronized (JournalTopicMessageStore.this) {
                    inFlightTxLocations.remove(location);
                    acknowledge(messageId, location, key);
                }
            }

            public void afterRollback() throws Exception {
                if (debug) {
                    LOG.debug("Transacted acknowledge rollback for: " + messageId + ", at: " + location);
                }
                synchronized (JournalTopicMessageStore.this) {
                    inFlightTxLocations.remove(location);
                }
            }
        });
    }

}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:54,代码来源:JournalTopicMessageStore.java

示例5: addMessage

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
/**
 * Not synchronized since the Journal has better throughput if you increase
 * the number of concurrent writes that it is doing.
 */
public void addMessage(ConnectionContext context, final Message message) throws IOException {

    final MessageId id = message.getMessageId();

    final boolean debug = LOG.isDebugEnabled();
    message.incrementReferenceCount();

    final RecordLocation location = peristenceAdapter.writeCommand(message, message.isResponseRequired());
    if (!context.isInTransaction()) {
        if (debug) {
            LOG.debug("Journalled message add for: " + id + ", at: " + location);
        }
        addMessage(message, location);
    } else {
        if (debug) {
            LOG.debug("Journalled transacted message add for: " + id + ", at: " + location);
        }
        synchronized (this) {
            inFlightTxLocations.add(location);
        }
        transactionStore.addMessage(this, message, location);
        context.getTransaction().addSynchronization(new Synchronization() {
            public void afterCommit() throws Exception {
                if (debug) {
                    LOG.debug("Transacted message add commit for: " + id + ", at: " + location);
                }
                synchronized (JournalMessageStore.this) {
                    inFlightTxLocations.remove(location);
                    addMessage(message, location);
                }
            }

            public void afterRollback() throws Exception {
                if (debug) {
                    LOG.debug("Transacted message add rollback for: " + id + ", at: " + location);
                }
                synchronized (JournalMessageStore.this) {
                    inFlightTxLocations.remove(location);
                }
                message.decrementReferenceCount();
            }
        });
    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:49,代码来源:JournalMessageStore.java

示例6: removeMessage

import org.apache.activemq.broker.ConnectionContext; //导入方法依赖的package包/类
/**
 */
public void removeMessage(ConnectionContext context, final MessageAck ack) throws IOException {
    final boolean debug = LOG.isDebugEnabled();
    JournalQueueAck remove = new JournalQueueAck();
    remove.setDestination(destination);
    remove.setMessageAck(ack);

    final RecordLocation location = peristenceAdapter.writeCommand(remove, ack.isResponseRequired());
    if (!context.isInTransaction()) {
        if (debug) {
            LOG.debug("Journalled message remove for: " + ack.getLastMessageId() + ", at: " + location);
        }
        removeMessage(ack, location);
    } else {
        if (debug) {
            LOG.debug("Journalled transacted message remove for: " + ack.getLastMessageId() + ", at: " + location);
        }
        synchronized (this) {
            inFlightTxLocations.add(location);
        }
        transactionStore.removeMessage(this, ack, location);
        context.getTransaction().addSynchronization(new Synchronization() {
            public void afterCommit() throws Exception {
                if (debug) {
                    LOG.debug("Transacted message remove commit for: " + ack.getLastMessageId() + ", at: " + location);
                }
                synchronized (JournalMessageStore.this) {
                    inFlightTxLocations.remove(location);
                    removeMessage(ack, location);
                }
            }

            public void afterRollback() throws Exception {
                if (debug) {
                    LOG.debug("Transacted message remove rollback for: " + ack.getLastMessageId() + ", at: " + location);
                }
                synchronized (JournalMessageStore.this) {
                    inFlightTxLocations.remove(location);
                }
            }
        });

    }
}
 
开发者ID:DiamondLightSource,项目名称:daq-eclipse,代码行数:46,代码来源:JournalMessageStore.java


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