java.lang.Object
com.darkcollective.relix.processor.connector.internal.ConnectorRegistry
All Implemented Interfaces:
AutoCloseable

public final class ConnectorRegistry extends Object implements AutoCloseable
The open dispatch point for connectors — it replaces the hardcoded CompositeDataSourceConnector switch.

The registry indexes every available RelixConnector by the type tokens it handles and resolves a connector for a token via forType(String). Built-in connectors are discovered from the module path with ServiceLoader; external connectors are loaded from the connector directory by a ConnectorPluginLoader.

Token resolution is case-insensitive. When two connectors claim the same token, the first registered wins and a warning is logged — built-ins are registered before external plugins, so a plugin cannot silently shadow a built-in.

  • Method Details

    • create

      public static ConnectorRegistry create()
      Builds a registry from the installed connector providers (module-path or classpath ServiceLoader) plus external plugins from the default connector directory ($RELIX_CONNECTORS, default ~/.relix/connectors/).

      The engine provides none of them itself: the standard CSV/JSON/HTTP/JDBC set is a discovered provider on exactly the footing an out-of-tree plugin has. A runtime with no provider installed yields an empty registry, and a source declaration then reports an unknown connector type.

      Returns:
      a registry over all discovered connectors
    • create

      public static ConnectorRegistry create(Path pluginDirectory)
      Builds a registry from the installed providers plus external plugins in the given directory, rather than the default one.
      Parameters:
      pluginDirectory - the connector-plugin directory to scan
      Returns:
      a registry over all discovered connectors
    • createWith

      public static ConnectorRegistry createWith(List<RelixConnector> extra)
      Builds a registry over connectors the caller supplies directly, ahead of the discovered and plugin ones.

      For a program that holds a connector instance rather than a service declaration — an embedder wiring a backend of its own without a META-INF/services entry, or a test standing one in. The SPI's argument is that anything a shipped connector can do a third party can do; needing a service declaration to exercise that inside one's own program would be a gap in the claim rather than a feature of it.

      Supplied connectors are indexed first, so one claiming a token a discovered connector also claims wins it — the caller named this instance explicitly, which is a stronger statement than a classpath scan.

      Parameters:
      extra - the caller's connectors, in priority order; must not be null
      Returns:
      a registry over the supplied, discovered and plugin connectors
    • createWith

      public static ConnectorRegistry createWith(List<RelixConnector> extra, Path pluginDirectory)
      Builds a registry over caller-supplied connectors plus the installed providers and the plugins in the given directory.
      Parameters:
      extra - the caller's connectors, in priority order; must not be null
      pluginDirectory - the connector-plugin directory to scan
      Returns:
      a registry over all three sources
    • forType

      public Optional<RelixConnector> forType(String token)
      Resolves the connector for a declaration's type token (case-insensitive).
      Parameters:
      token - the type token (e.g. "jdbc", "csv", "mongodb")
      Returns:
      the handling connector, or empty when no connector handles the token
    • types

      public Set<String> types()
      Returns:
      the set of type tokens this registry can dispatch, lower-cased
    • close

      public void close()
      Closes every connector this registry discovered, suppressing individual failures. A connector supplied by the caller is left open — see createWith(List).
      Specified by:
      close in interface AutoCloseable