Implementation:Apache Shardingsphere StandaloneContextManagerBuilder Build
| Knowledge Sources | |
|---|---|
| Domains | Mode_Management, Standalone |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
StandaloneContextManagerBuilder is an SPI builder that constructs standalone-mode ContextManager instances with repository loading, worker ID initialization, and metadata context creation.
Description
StandaloneContextManagerBuilder implements ContextManagerBuilder and is identified by the type string "Standalone" with isDefault returning true, making it the default mode. The build method performs four steps: (1) creates a ComputeNodeInstanceContext and initializes it with StandaloneWorkerIdGenerator, (2) loads a StandalonePersistRepository via TypedSPILoader based on the configured repository type and properties (defaulting to null type and empty properties if no config), (3) creates an ExclusiveOperatorEngine with StandaloneExclusiveOperatorContext, and (4) builds MetaDataContexts through MetaDataContextsFactory backed by a MetaDataPersistFacade wrapping the repository. These are assembled into a ContextManager.
Usage
This builder is loaded via SPI when ShardingSphere starts in standalone mode. It is the default ContextManagerBuilder used when no explicit mode type is configured, or when "Standalone" is specified. It supports JDBC and Memory repository backends.
Code Reference
Source Location
- Repository: Apache_Shardingsphere
- File: StandaloneContextManagerBuilder.java
- Lines: 1-65
Signature
public final class StandaloneContextManagerBuilder implements ContextManagerBuilder {
public ContextManager build(final ContextManagerBuilderParameter param,
final EventBusContext eventBusContext) throws SQLException
public String getType()
public boolean isDefault()
}
Import
import org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| param | ContextManagerBuilderParameter | Yes | Contains mode configuration, instance metadata, and data source configs |
| eventBusContext | EventBusContext | Yes | Event bus context for instance communication |
Outputs
| Name | Type | Description |
|---|---|---|
| contextManager | ContextManager | Fully initialized standalone context manager with metadata, repository, and exclusive engine |
Usage Examples
// Typically loaded via SPI:
ContextManagerBuilder builder = TypedSPILoader.getService(ContextManagerBuilder.class, "Standalone");
ContextManager contextManager = builder.build(param, eventBusContext);
// Or used as the default when no mode is specified