Principle:Apache Dolphinscheduler DataSource Channel Pattern
| Knowledge Sources | |
|---|---|
| Domains | Plugin_Architecture, Data_Integration |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
An abstract factory pattern that produces database-specific client instances (ad-hoc and pooled) through a two-level factory hierarchy registered via Java SPI.
Description
The DataSource Channel Pattern provides a factory abstraction for creating database client objects. A DataSourceChannelFactory (discovered via SPI) creates a DataSourceChannel, which in turn produces AdHocDataSourceClient and PooledDataSourceClient instances. This two-level factory hierarchy allows the system to create the appropriate client type for any registered database without knowing the concrete implementation classes.
This pattern solves the problem of dynamically creating typed database clients at runtime based on the database type, while keeping the creation logic encapsulated within each plugin module.
Usage
Implement this pattern when registering a new datasource plugin with the DolphinScheduler plugin manager. The DataSourceChannelFactory is the SPI entry point that the DataSourcePluginManager discovers and uses to populate the channel registry.
Theoretical Basis
The DataSource Channel Pattern applies the Abstract Factory Pattern:
- Abstract Factory: DataSourceChannelFactory defines the factory interface
- Concrete Factory: Each plugin provides a factory (e.g., MySQLDataSourceChannelFactory)
- Abstract Product: DataSourceChannel defines client creation interface
- Concrete Product: Plugin-specific channels create typed clients
// Abstract Factory hierarchy
DataSourceChannelFactory // Level 1: Creates DataSourceChannel
└── create() -> DataSourceChannel
DataSourceChannel // Level 2: Creates clients
├── createAdHocDataSourceClient(param, dbType) -> AdHocDataSourceClient
└── createPooledDataSourceClient(param, dbType) -> PooledDataSourceClient