Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Apache Shardingsphere ContextManagerBuilderParameter Constructor

From Leeroopedia
Revision as of 14:23, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Apache_Shardingsphere_ContextManagerBuilderParameter_Constructor.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Cluster_Mode, Distributed_Coordination
Last Updated 2026-02-10 00:00 GMT

Overview

Concrete tool for assembling all bootstrap configuration into an immutable parameter object provided by the ShardingSphere mode module.

Description

ContextManagerBuilderParameter is a final, immutable data class that aggregates every piece of configuration required to bootstrap a ShardingSphere context manager. It is annotated with Lombok's @RequiredArgsConstructor to generate a constructor accepting all final fields, and @Getter to expose them as read-only properties.

The class contains seven fields: the mode configuration, a map of per-database configurations, a map of global data sources, a collection of global rule configurations, system properties, instance labels, and instance metadata. The modeConfig field has its getter suppressed via @Getter(AccessLevel.NONE) and replaced with a custom getModeConfiguration() method that returns a default Standalone configuration when the field is null.

This ensures that any downstream consumer -- whether it is the Cluster builder, the Standalone builder, or any future mode builder -- always receives a non-null, valid mode configuration without requiring null-check logic at the call site.

Usage

Construct this object at the entry point of the ShardingSphere bootstrap process (JDBC driver initialization or Proxy startup). Pass it to a ContextManagerBuilder implementation loaded via SPI.

Code Reference

Source Location

  • Repository: Apache ShardingSphere
  • File: mode/core/src/main/java/org/apache/shardingsphere/mode/manager/builder/ContextManagerBuilderParameter.java
  • Lines: 38-63

Signature

@RequiredArgsConstructor
@Getter
public final class ContextManagerBuilderParameter {

    @Getter(AccessLevel.NONE)
    private final ModeConfiguration modeConfig;

    private final Map<String, DatabaseConfiguration> databaseConfigs;

    private final Map<String, DataSource> globalDataSources;

    private final Collection<RuleConfiguration> globalRuleConfigs;

    private final Properties props;

    private final Collection<String> labels;

    private final InstanceMetaData instanceMetaData;

    public ModeConfiguration getModeConfiguration() {
        return null == modeConfig ? new ModeConfiguration("Standalone", null) : modeConfig;
    }
}

Import

import org.apache.shardingsphere.mode.manager.builder.ContextManagerBuilderParameter;

I/O Contract

Inputs

Name Type Required Description
modeConfig ModeConfiguration No Mode configuration (Standalone/Cluster); defaults to Standalone if null
databaseConfigs Map<String, DatabaseConfiguration> Yes Per-database configurations keyed by database name
globalDataSources Map<String, DataSource> Yes Globally shared data sources keyed by name
globalRuleConfigs Collection<RuleConfiguration> Yes Global rule configurations (authority, transaction, etc.)
props Properties Yes System-level properties
labels Collection<String> Yes Labels for compute node identification
instanceMetaData InstanceMetaData Yes Metadata describing the current compute node

Outputs

Name Type Description
(instance) ContextManagerBuilderParameter Immutable parameter object holding all bootstrap configuration

Usage Examples

// Constructing a ContextManagerBuilderParameter for Cluster mode bootstrap
ModeConfiguration modeConfig = new ModeConfiguration("Cluster",
    new ClusterPersistRepositoryConfiguration("ZooKeeper", "governance-namespace", "localhost:2181", new Properties()));

Map<String, DatabaseConfiguration> databaseConfigs = new LinkedHashMap<>();
// ... populate databaseConfigs ...

ContextManagerBuilderParameter param = new ContextManagerBuilderParameter(
    modeConfig,
    databaseConfigs,
    Collections.emptyMap(),       // globalDataSources
    Collections.emptyList(),      // globalRuleConfigs
    new Properties(),             // props
    Collections.emptyList(),      // labels
    instanceMetaData              // instanceMetaData
);

// The mode configuration is guaranteed non-null
ModeConfiguration mode = param.getModeConfiguration(); // returns the Cluster config

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment