聊聊artemis的persistenceEnabled
序
本文主要研究一下artemis的persistenceEnabled
persistenceEnabled
activemq-artemis-2.11.0/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java
public class ConfigurationImpl implements Configuration, Serializable {? ? //......? ? private boolean persistenceEnabled = ActiveMQDefaultConfiguration.isDefaultPersistenceEnabled();? ? public boolean isPersistenceEnabled() { ? ? return persistenceEnabled; ? }? ? public ConfigurationImpl setPersistenceEnabled(final boolean enable) { ? ? persistenceEnabled = enable; ? ? return this; ? }? ? //......} ? - ConfigurationImpl定义了persistenceEnabled属性,默认为ActiveMQDefaultConfiguration.isDefaultPersistenceEnabled()(true)
createStorageManager
activemq-artemis-2.11.0/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
public class ActiveMQServerImpl implements ActiveMQServer {? ? //......? ? protected StorageManager createStorageManager() { ? ? if (configuration.isPersistenceEnabled()) { ? ? ? ? if (configuration.getStoreConfiguration() != null && configuration.getStoreConfiguration().getStoreType() == StoreConfiguration.StoreType.DATABASE) { ? ? ? ? ? JDBCJournalStorageManager journal = new JDBCJournalStorageManager(configuration, getCriticalAnalyzer(), getScheduledPool(), executorFactory, ioExecutorFactory, shutdownOnCriticalIO); ? ? ? ? ? this.getCriticalAnalyzer().add(journal); ? ? ? ? ? return journal; ? ? ? ? } else { ? ? ? ? ? // Default to File Based Storage Manager, (Legacy default configuration). ? ? ? ? ? JournalStorageManager journal = new JournalStorageManager(configuration, getCriticalAnalyzer(), executorFactory, scheduledPool, ioExecutorFactory, shutdownOnCriticalIO); ? ? ? ? ? this.getCriticalAnalyzer().add(journal); ? ? ? ? ? return journal; ? ? ? ? } ? ? } ? ? return new NullStorageManager(); ? }? ? //......}- ActiveMQServerImpl的createStorageManager方法在configuration.isPersistenceEnabled()为true时创建的StorageManager是JDBCJournalStorageManager或者JournalStorageManager;否则创建的StorageManager是NullStorageManager
processRoute
activemq-artemis-2.11.0/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java
public class PostOfficeImpl implements PostOffice, NotificationListener, BindingsFactory {? ? //......? ? public void processRoute(final Message message, ? ? ? ? ? ? ? ? ? ? ? ? ? final RoutingContext context, ? ? ? ? ? ? ? ? ? ? ? ? ? final boolean direct) throws Exception { ? ? final List<MessageReference> refs = new ArrayList<>();? ? ? Transaction tx = context.getTransaction();? ? ? Long deliveryTime = message.getScheduledDeliveryTime();? ? ? for (Map.Entry<SimpleString, RouteContextList> entry : context.getContexListing().entrySet()) { ? ? ? ? PagingStore store = pagingManager.getPageStore(entry.getKey());? ? ? ? ? if (store != null && storageManager.addToPage(store, message, context.getTransaction(), entry.getValue())) { ? ? ? ? ? if (message.isLargeMessage()) { ? ? ? ? ? ? ? confirmLargeMessageSend(tx, message); ? ? ? ? ? }? ? ? ? ? ? // We need to kick delivery so the Queues may check for the cursors case they are empty ? ? ? ? ? schedulePageDelivery(tx, entry); ? ? ? ? ? continue; ? ? ? ? }? ? ? ? ? for (Queue queue : entry.getValue().getNonDurableQueues()) { ? ? ? ? ? MessageReference reference = MessageReference.Factory.createReference(message, queue);? ? ? ? ? ? if (deliveryTime != null) { ? ? ? ? ? ? ? reference.setScheduledDeliveryTime(deliveryTime); ? ? ? ? ? } ? ? ? ? ? refs.add(reference);? ? ? ? ? ? message.incrementRefCount(); ? ? ? ? }? ? ? ? ? Iterator<Queue> iter = entry.getValue().getDurableQueues().iterator();? ? ? ? ? while (iter.hasNext()) { ? ? ? ? ? Queue queue = iter.next();? ? ? ? ? ? MessageReference reference = MessageReference.Factory.createReference(message, queue);? ? ? ? ? ? if (context.isAlreadyAcked(context.getAddress(message), queue)) { ? ? ? ? ? ? ? reference.setAlreadyAcked(); ? ? ? ? ? ? ? if (tx != null) { ? ? ? ? ? ? ? ? queue.acknowledge(tx, reference); ? ? ? ? ? ? ? } ? ? ? ? ? }? ? ? ? ? ? if (deliveryTime != null) { ? ? ? ? ? ? ? reference.setScheduledDeliveryTime(deliveryTime); ? ? ? ? ? } ? ? ? ? ? refs.add(reference);? ? ? ? ? ? if (message.isDurable()) { ? ? ? ? ? ? ? int durableRefCount = message.incrementDurableRefCount();? ? ? ? ? ? ? ? if (durableRefCount == 1) { ? ? ? ? ? ? ? ? if (tx != null) { ? ? ? ? ? ? ? ? ? ? storageManager.storeMessageTransactional(tx.getID(), message); ? ? ? ? ? ? ? ? } else { ? ? ? ? ? ? ? ? ? ? storageManager.storeMessage(message); ? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? ? if (message.isLargeMessage()) { ? ? ? ? ? ? ? ? ? ? confirmLargeMessageSend(tx, message); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? if (tx != null) { ? ? ? ? ? ? ? ? storageManager.storeReferenceTransactional(tx.getID(), queue.getID(), message.getMessageID());? ? ? ? ? ? ? ? ? tx.setContainsPersistent(); ? ? ? ? ? ? ? } else { ? ? ? ? ? ? ? ? storageManager.storeReference(queue.getID(), message.getMessageID(), !iter.hasNext()); ? ? ? ? ? ? ? }? ? ? ? ? ? ? ? if (deliveryTime != null && deliveryTime > 0) { ? ? ? ? ? ? ? ? if (tx != null) { ? ? ? ? ? ? ? ? ? ? storageManager.updateScheduledDeliveryTimeTransactional(tx.getID(), reference); ? ? ? ? ? ? ? ? } else { ? ? ? ? ? ? ? ? ? ? storageManager.updateScheduledDeliveryTime(reference); ? ? ? ? ? ? ? ? } ? ? ? ? ? ? ? } ? ? ? ? ? }? ? ? ? ? ? message.incrementRefCount(); ? ? ? ? } ? ? }? ? ? if (tx != null) { ? ? ? ? tx.addOperation(new AddOperation(refs)); ? ? } else { ? ? ? ? // This will use the same thread if there are no pending operations ? ? ? ? // avoiding a context switch on this case ? ? ? ? storageManager.afterCompleteOperations(new IOCallback() { ? ? ? ? ? @Override ? ? ? ? ? public void onError(final int errorCode, final String errorMessage) { ? ? ? ? ? ? ? ActiveMQServerLogger.LOGGER.ioErrorAddingReferences(errorCode, errorMessage); ? ? ? ? ? }? ? ? ? ? ? @Override ? ? ? ? ? public void done() { ? ? ? ? ? ? ? context.processReferences(refs, direct); ? ? ? ? ? } ? ? ? ? }); ? ? } ? }? ? //......}- PostOfficeImpl的processRoute方法会判断message.isDurable(),若为true且durableRefCount为1则会执行storageManager.storeMessage或者storageManager.storeMessageTransactional方法
storeMessage
AbstractJournalStorageManager
activemq-artemis-2.11.0/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/AbstractJournalStorageManager.java
public abstract class AbstractJournalStorageManager extends CriticalComponentImpl implements StorageManager {? ? //......? ? protected Journal messageJournal;? ? //......? ? public void storeMessage(final Message message) throws Exception { ? ? if (message.getMessageID() <= 0) { ? ? ? ? // Sanity check only... this shouldn't happen unless there is a bug ? ? ? ? throw ActiveMQMessageBundle.BUNDLE.messageIdNotAssigned(); ? ? }? ? ? readLock(); ? ? try { ? ? ? ? // Note that we don't sync, the add reference that comes immediately after will sync if ? ? ? ? // appropriate? ? ? ? ? if (message.isLargeMessage()) { ? ? ? ? ? messageJournal.appendAddRecord(message.getMessageID(), JournalRecordIds.ADD_LARGE_MESSAGE, LargeMessagePersister.getInstance(), message, false, getContext(false)); ? ? ? ? } else { ? ? ? ? ? messageJournal.appendAddRecord(message.getMessageID(), JournalRecordIds.ADD_MESSAGE_PROTOCOL, message.getPersister(), message, false, getContext(false)); ? ? ? ? } ? ? } finally { ? ? ? ? readUnLock(); ? ? } ? }? ? //......}- JDBCJournalStorageManager及JournalStorageManager都继承了AbstractJournalStorageManager,其storeMessage方法会调用messageJournal.appendAddRecord方法;二者的messageJournal实现不同,一个是JDBCJournalImpl,一个是JournalImpl
NullStorageManager
activemq-artemis-2.11.0/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/nullpm/NullStorageManager.java
public class NullStorageManager implements StorageManager {? ? //......? ? public void storeMessage(final Message message) throws Exception { ? }? ? //......}- NullStorageManager实现了StorageManager接口,其storeMessage为空方法
小结
ConfigurationImpl定义了persistenceEnabled属性,默认为ActiveMQDefaultConfiguration.isDefaultPersistenceEnabled()(true);ActiveMQServerImpl的createStorageManager方法在configuration.isPersistenceEnabled()为true时创建的StorageManager是JDBCJournalStorageManager或者JournalStorageManager;否则创建的StorageManager是NullStorageManager;PostOfficeImpl的processRoute方法会判断message.isDurable(),若为true且durableRefCount为1则会执行storageManager.storeMessage或者storageManager.storeMessageTransactional方法
doc
- ConfigurationImpl
版权声明:
作者: FreeClashNode
链接: https://www.freeclashnode.com/news/article-2165.htm
来源: www.freeclashnode.com
文章版权归作者所有,未经允许请勿转载。
热门文章
- 11月2日免费节点分享|22.5M/S,V2ray节点/Clash节点/SSR节点/Singbox节点|免费上网梯子每天更新
- 10月31日免费节点分享|18.7M/S,Shadowrocket节点/Clash节点/V2ray节点/Singbox节点|免费上网梯子每天更新
- 10月27日免费节点分享|20M/S,Shadowrocket节点/Singbox节点/V2ray节点/Clash节点|免费上网梯子每天更新
- 10月26日免费节点分享|21.5M/S,V2ray节点/SSR节点/Singbox节点/Clash节点|免费上网梯子每天更新
- 10月28日免费节点分享|22.8M/S,Singbox节点/SSR节点/V2ray节点/Clash节点|免费上网梯子每天更新
- 10月30日免费节点分享|20.4M/S,V2ray节点/SSR节点/Singbox节点/Clash节点|免费上网梯子每天更新
- 11月1日免费节点分享|20.3M/S,V2ray节点/Shadowrocket节点/Clash节点/Singbox节点|免费上网梯子每天更新
- 10月29日免费节点分享|21.6M/S,SSR节点/Clash节点/V2ray节点/Singbox节点|免费上网梯子每天更新
- 11月7日免费节点分享|22.9M/S,Shadowrocket节点/V2ray节点/Singbox节点/Clash节点|免费上网梯子每天更新
- 11月6日免费节点分享|20.9M/S,Shadowrocket节点/V2ray节点/Singbox节点/Clash节点|免费上网梯子每天更新
最新文章
- 11月24日免费节点分享|22.6M/S,V2ray节点/Shadowrocket节点/Clash节点/Singbox节点|免费上网梯子每天更新
- 11月23日免费节点分享|21.4M/S,Shadowrocket节点/Clash节点/V2ray节点/Singbox节点|免费上网梯子每天更新
- 解锁全球视野:谷歌地图科学上网全攻略,让你畅行无阻
- 11月22日免费节点分享|22.8M/S,Clash节点/SSR节点/Singbox节点/V2ray节点|免费上网梯子每天更新
- 星卡V2rayNG免流终极指南:解锁零流量上网新姿势
- 11月21日免费节点分享|21.4M/S,V2ray节点/Singbox节点/Shadowrocket节点/Clash节点|免费上网梯子每天更新
- 深度解析Clash后台退出问题:操作系统、内存与配置的全面应对策略
- 11月20日免费节点分享|19.1M/S,V2ray节点/Clash节点/Shadowrocket节点/Singbox节点|免费上网梯子每天更新
- 御坂网络科学上网全攻略:解锁全球互联网的自由之门
- 11月19日免费节点分享|18.1M/S,Clash节点/V2ray节点/SSR节点/Singbox节点|免费上网梯子每天更新
- 掌上护盾的艺术:全面拆解clash手机壳的硬核实力与选购哲学
- 11月18日免费节点分享|21M/S,Clash节点/Singbox节点/V2ray节点/SSR节点|免费上网梯子每天更新
- 苹果设备解锁网络自由:科学上网全攻略与深度解析
- 11月17日免费节点分享|20.3M/S,Singbox节点/V2ray节点/Clash节点/Shadowrocket节点|免费上网梯子每天更新
- 突破网络瓶颈:全方位优化v2ray速度的终极指南
- 11月16日免费节点分享|18.2M/S,Singbox节点/Shadowrocket节点/V2ray节点/Clash节点|免费上网梯子每天更新
- 彻底解决vmess协议上传故障:从原理到实践的完整指南
- 11月15日免费节点分享|18M/S,Singbox节点/Clash节点/SSR节点/V2ray节点|免费上网梯子每天更新
- 付费V2Ray节点全指南:如何选择、配置与优化使用体验
- 11月14日免费节点分享|22.5M/S,SSR节点/Singbox节点/V2ray节点/Clash节点|免费上网梯子每天更新
- 从 Clash 到 V2Ray:订阅地址转换的全面指南
- 11月13日免费节点分享|19.3M/S,Singbox节点/Shadowrocket节点/Clash节点/V2ray节点|免费上网梯子每天更新
- V2RayNG连接故障全面解析:从原因排查到高效解决的终极指南
- 11月12日免费节点分享|22.4M/S,V2ray节点/Clash节点/Singbox节点/Shadowrocket节点|免费上网梯子每天更新
- 蓝灯破壁:一部跨越网络疆域的完整科学上网指南
- 11月11日免费节点分享|19.6M/S,Clash节点/V2ray节点/Singbox节点/Shadowrocket节点|免费上网梯子每天更新
- R8000科学上网终极指南:全面掌握Shadowsocks配置与优化技巧
- 11月10日免费节点分享|19M/S,Clash节点/SSR节点/V2ray节点/Singbox节点|免费上网梯子每天更新
- 解锁全球视野:星愿浏览器科学上网终极指南
- 11月9日免费节点分享|22.3M/S,Shadowrocket节点/Clash节点/V2ray节点/Singbox节点|免费上网梯子每天更新
- 轻松翻越网络高墙:Shadowrocket一键导入配置全攻略
- 11月8日免费节点分享|21.3M/S,Clash节点/V2ray节点/Singbox节点/SSR节点|免费上网梯子每天更新
- 当Vmess突然失效:一场技术与封锁的无声博弈
- 11月7日免费节点分享|22.9M/S,Shadowrocket节点/V2ray节点/Singbox节点/Clash节点|免费上网梯子每天更新
- 梅林固件科学上网完全指南:从入门到精通,零成本解锁网络自由
- 11月6日免费节点分享|20.9M/S,Shadowrocket节点/V2ray节点/Singbox节点/Clash节点|免费上网梯子每天更新
- 幸运破解器科学上网全解析:解锁数字世界的终极指南
- 11月5日免费节点分享|21.9M/S,Shadowrocket节点/Singbox节点/V2ray节点/Clash节点|免费上网梯子每天更新
- 11月4日免费节点分享|18M/S,Clash节点/Singbox节点/SSR节点/V2ray节点|免费上网梯子每天更新
- 穿越数字迷雾:深度解析V2Ray中转迟滞之谜与极速优化指南
- 跨越数字边界:科学上网的终极指南与深度思考
- 从连接到掌控:深入理解 Quantumult 的工作流程与网络管理哲学
- 11月2日免费节点分享|22.5M/S,V2ray节点/Clash节点/SSR节点/Singbox节点|免费上网梯子每天更新
- 深度解析《荒野冲突》:征服与策略的终极对决
- 11月1日免费节点分享|20.3M/S,V2ray节点/Shadowrocket节点/Clash节点/Singbox节点|免费上网梯子每天更新
- 斐讯路由器刷机配置v2ray全攻略:打造安全高效的翻墙网络环境
- 10月31日免费节点分享|18.7M/S,Shadowrocket节点/Clash节点/V2ray节点/Singbox节点|免费上网梯子每天更新
- 谷歌浏览器科学上网扩展全攻略:从入门到精通
- 10月30日免费节点分享|20.4M/S,V2ray节点/SSR节点/Singbox节点/Clash节点|免费上网梯子每天更新
- 苹果手机V2Ray完全指南:从零开始打造安全上网环境
归档
- 2026-11 45
- 2026-10 61
- 2026-09 58
- 2026-08 63
- 2026-07 61
- 2026-06 55
- 2026-05 56
- 2026-04 51
- 2026-03 60
- 2026-02 52
- 2026-01 56
- 2025-12 59
- 2025-11 55
- 2025-10 56
- 2025-09 55
- 2025-08 49
- 2025-07 31
- 2025-06 30
- 2025-05 31
- 2025-04 30
- 2025-03 388
- 2025-02 360
- 2025-01 403
- 2024-12 403
- 2024-11 390
- 2024-10 403
- 2024-09 388
- 2024-08 402
- 2024-07 427
- 2024-06 442
- 2024-05 181
- 2024-04 33
- 2024-03 31
- 2024-02 29
- 2024-01 51
- 2023-12 52
- 2023-11 32
- 2023-10 32
- 2023-09 3