This file provides guidance to an AI coding tool when working with code in this repository.
hugegraph-commons is a shared utility module for Apache HugeGraph and its peripheral components. It provides core infrastructure components (locks, config, events, iterators, REST client, RPC framework) to simplify development across the HugeGraph ecosystem.
Technology Stack:
- Java 8+ (compiler source/target: 1.8)
- Apache Maven 3.5+
- Apache Commons Configuration2 for config management
- OkHttp 4.10.0 for REST client (hugegraph-common)
- Sofa-RPC 5.7.6 for RPC framework (hugegraph-rpc)
- JUnit 4.13.1 and Mockito 4.1.0 for testing
This is a Maven multi-module project with 2 main modules:
-
hugegraph-common: Core utilities library
- Lock implementations (atomic, key, row, lock groups)
- Configuration system with type-safe options
- Event hub for async notifications
- Iterator utilities (map, filter, flat-map, batch)
- RESTful client (OkHttp-based)
- Utilities (perf analysis, version checking, collections, logging)
- License management
-
hugegraph-rpc: RPC communication framework
- Sofa-RPC based client/server implementation
- Consumer and provider configuration
- Service registration and discovery
- Depends on hugegraph-common
-
Type-Safe Configuration System:
HugeConfig+OptionSpacepattern- Config options defined as typed
ConfigOptionobjects - Supports both
.propertiesand.yamlfiles - Options organized in
OptionSpacegroups for validation - Security checks on load
- Config options defined as typed
-
Lock Hierarchy: Multiple lock implementations for different use cases
AtomicLock: Basic atomic lockingKeyLock: Lock by specific keyRowLock: Row-level locking for table-like structuresLockGroup: Manage multiple related locksLockManager: Central lock coordination
-
Event System: Async event notification
EventHub: Central event dispatcherEventListener: Typed event handlers- Thread-safe event publishing
-
Iterator Composition: Chainable iterator wrappers
MapperIterator,FilterIterator,LimitIteratorFlatMapperIteratorfor nested iterationBatchMapperIteratorfor batch processing- All extend
ExtendableIteratorbase
-
RPC Architecture: Sofa-RPC abstraction layer
RpcServer: Service provider sideRpcClientProvider: Service consumer sideRpcProviderConfig/RpcConsumerConfig: Configuration wrappers- Supports multiple protocols (bolt, rest, grpc)
# Verify Java version (8+ required)
java -version
# Verify Maven version (3.5+ required)
mvn -version# Clean build without tests (fastest)
mvn clean install -DskipTests
# Build with tests enabled
mvn clean install
# Build specific module only
mvn clean install -pl hugegraph-common -DskipTests
mvn clean install -pl hugegraph-rpc -am -DskipTests # -am includes dependencies
# Compile with warnings visible
mvn clean compile -Dmaven.javadoc.skip=trueNote: Tests are skipped by default via <skipCommonsTests>true</skipCommonsTests> in pom.xml. To run tests, override with -DskipCommonsTests=false.
# Run all tests (override default skip)
mvn test -DskipCommonsTests=false
# Run tests for specific module
mvn test -pl hugegraph-common -DskipCommonsTests=false
mvn test -pl hugegraph-rpc -am -DskipCommonsTests=false
# Run single test class
mvn test -pl hugegraph-common -Dtest=HugeConfigTest -DskipCommonsTests=false
# Run test suite (includes all unit tests)
mvn test -pl hugegraph-common -Dtest=UnitTestSuite -DskipCommonsTests=false# License header check (Apache RAT)
mvn apache-rat:check
# Checkstyle validation
mvn checkstyle:check
# Both checks run automatically during validate phase
mvn validate# Generate JaCoCo coverage report
mvn clean test -DskipCommonsTests=false
# Report: target/jacoco/index.html-
hugegraph-common sources:
hugegraph-common/src/main/java/org/apache/hugegraph/concurrent/: Lock implementationsconfig/: Configuration system (HugeConfig, OptionSpace, ConfigOption)event/: Event hub and listenersiterator/: Iterator utilitiesrest/: REST client implementationutil/: Various utilities (collections, logging, version, etc.)perf/: Performance measurement (PerfUtil, Stopwatch)license/: License management
-
hugegraph-rpc sources:
hugegraph-rpc/src/main/java/org/apache/hugegraph/rpc/: RPC server and client implementationsconfig/: RPC-specific config options
- Unit tests:
hugegraph-{module}/src/test/java/org/apache/hugegraph/unit/ - Test suites:
UnitTestSuite.javalists all test classes - Test utilities:
hugegraph-common/src/main/java/org/apache/hugegraph/testutil/Whitebox: Reflection utilities for testing private membersAssert: Enhanced assertion utilities
- Parent POM:
pom.xml(defines all dependencies and versions) - Module POMs:
hugegraph-{module}/pom.xml - Test resources:
hugegraph-rpc/src/test/resources/*.properties - Checkstyle config:
style/checkstyle.xml(referenced in parent POM)
- Version property:
${revision}in pom.xml (currently 1.7.0) - Version classes:
hugegraph-common/src/main/java/org/apache/hugegraph/version/CommonVersion.javahugegraph-rpc/src/main/java/org/apache/hugegraph/version/RpcVersion.java
- IMPORTANT: When changing version in pom.xml, also update version in these Java files
Dependency order:
hugegraph-common (no internal dependencies)
↓
hugegraph-rpc (depends on hugegraph-common)
When making changes:
- Changes to
hugegraph-commonrequire rebuildinghugegraph-rpc - Always build common first:
mvn install -pl hugegraph-common -DskipTests - Then build rpc:
mvn install -pl hugegraph-rpc -am -DskipTests
When adding new configuration options:
- Define
ConfigOptionin appropriate config class (e.g.,RpcOptions.java) - Register option in an
OptionSpacefor validation - Load via
HugeConfig.get(option)orconfig.get(option) - Example:
public static final ConfigOption<String> RPC_SERVER_HOST =
new ConfigOption<>("rpc.server_host", "...", "127.0.0.1");RPC configuration pattern:
- Server side: Create
RpcServerwithHugeConfig - Client side: Use
RpcClientProviderfor service proxies - Config files: Properties format with
rpc.*keys - Protocol: Default is Sofa-Bolt (binary protocol)
- Unit tests extend
BaseUnitTest(for common module) or use standard JUnit - Test organization: Tests mirror source package structure
- Naming:
{ClassName}Test.javafor unit tests - Mocking: Use Mockito for external dependencies
- Reflection testing: Use
Whitebox.setInternalState()for private field access
When adding third-party dependencies:
- Add to
dependencyManagementsection in parent pom if used by multiple modules - Declare version in
<properties>section - Add license info to
hugegraph-dist/release-docs/licenses/ - Update
hugegraph-dist/release-docs/LICENSE - Update
hugegraph-dist/release-docs/NOTICEif upstream has NOTICE
# Single test class
mvn test -pl hugegraph-common -Dtest=HugeConfigTest -DskipCommonsTests=false
# Single test method
mvn test -pl hugegraph-common -Dtest=HugeConfigTest#testGetOption -DskipCommonsTests=false
# Pattern matching
mvn test -pl hugegraph-common -Dtest=*ConfigTest -DskipCommonsTests=false- Enable debug logging: Modify
log4j2.xmlin test resources - Maven debug output: Add
-Xflag to any Maven command - Skip checkstyle temporarily: Add
-Dcheckstyle.skip=true - Force dependency updates:
mvn clean install -U
This module has a parent POM (../pom.xml - hugegraph main project). If working standalone:
- The
<revision>property comes from parent (1.7.0) - Flatten Maven plugin resolves
${revision}to actual version .flattened-pom.xmlis auto-generated (excluded from RAT checks)
Three places to update when changing version:
pom.xml:<revision>propertyhugegraph-common/.../CommonVersion.java: Update version constanthugegraph-rpc/.../RpcVersion.java: Update version constant
The REST client in hugegraph-common/rest/ uses OkHttp (not Jersey as older docs suggest):
- Switched from Jersey to OkHttp in recent versions
- Supports connection pooling, timeouts, interceptors
- See
AbstractRestClient.javafor base implementation
hugegraph-rpc uses Sofa-RPC 5.7.6 which has known security issues. There's a TODO to upgrade to 5.12+:
- See comment in
hugegraph-rpc/pom.xml:65-66 - This is a known technical debt item
Checkstyle runs during validate phase by default:
- Config:
style/checkstyle.xml - Failures block the build
- Skip with
-Dcheckstyle.skip=truefor quick iteration - Always fix before committing