Unlocking Alibaba’s Alicom-Frame: DAO, Caching, Distributed Locks & More

This article introduces the Alicom‑Frame library from Alibaba’s Telecom Billing Refactor project, detailing its modular utilities such as flexible DAO with sharding support, method‑level caching, Diamond‑based configuration tools, distributed locks, and various helper classes, illustrating how they simplify backend development.

21CTO
21CTO
21CTO
Unlocking Alibaba’s Alicom-Frame: DAO, Caching, Distributed Locks & More

Overall

During the Alibaba Telecom Billing Refactor project, a set of reusable utility classes were extracted into a base library called Alicom‑Frame. The article introduces its main components.

DAO Operations – Flexible Sharding Support

1. Traditional Spring‑iBatis DAO

Configuration steps include datasource setup (using TDDL group layer), sqlMap files per table, sqlMapClient or sqlMapClientTemplate configuration, and DAO class implementation. For sharding, table names are built dynamically via TableRoute, and different DataSources are selected via DbRoute.

<dependency>
  <groupId>com.alicom</groupId>
  <artifactId>alicom-frame</artifactId>
  <version>1.0.7</version>
</dependency>

2. What the framework provides

Configuration files (persistence.xml, sql‑map‑config.xml, sql‑map‑null.xml) with automatic DAO path and datasource mapping; naming conventions (DAO under dao, DO under dataobject, Impl suffixes); BaseDAO with @SQLMap annotation; BaseDO with set_TABLE_NAME_() for sharding; automatic code generation for DAO/DO and sqlMap files.

3. Implementation Details

AbstractConvert defines sharding rules; BaseDAO initializes templates based on @SQLMap, @DbDefine, @TableDefine annotations; at runtime the appropriate datasource and table name are resolved.

Diamond Utility – FrameDiamondUtil

1. Basic usage

Diamond provides dynamic configuration via Diamond.getConfig and listeners. The utility wraps these calls.

2. What the framework provides

Static methods getConfig(String dataId, String group, long timeoutMs) and an overloaded version with a Convert implementation for custom conversion.

3. Implementation

Internally maintains a Map keyed by group^dataId. On first call it fetches the config from Diamond and registers a listener to update the map when the config changes.

Method‑Level Caching via Annotations

1. Problem addressed

Separate caching logic from business code using Spring Cache with extensions for Diamond‑driven cache lifecycle.

2. What the framework provides

Annotations to enable local JVM or Tair caching (LRU policy), automatic cache refresh based on Diamond configuration timestamps, and custom KeyGenerator that prefixes keys with the Diamond timestamp.

Distributed Lock

1. Overview

Implements a distributed lock using Tair atomic operations.

2. Usage

Implement TairLockObject, create a lock instance (e.g., AcctIdLock lock = new AcctIdLock(123L)), then call lock.acquire() and lock.release().

3. Implementation

Lock acquisition uses tairManager.incr on a generated key; release uses tairManager.delete. Configuration determines key prefix and retry policy.

Conclusion

The Alicom‑Frame library demonstrates how a project can evolve reusable backend infrastructure—DAO sharding, configuration management, caching, and distributed locking—reducing duplicated effort in future developments.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Javadistributed-lockdaoDiamond
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.