Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Apache Dolphinscheduler Clients Proxy Factory

From Leeroopedia


Knowledge Sources
Domains Distributed_Systems, RPC
Last Updated 2026-02-10 00:00 GMT

Overview

Concrete tool for creating RPC client proxies using the Clients fluent API and JdkDynamicRpcClientProxyFactory with Guava cache.

Description

Clients provides a fluent builder: withService(Class<T>) returns a builder, withHost(String) resolves the proxy via JdkDynamicRpcClientProxyFactory. The factory maintains a Guava LoadingCache keyed by (host, interfaceClass) pairs with 1-hour expireAfterAccess eviction. On cache miss, newProxyClient() creates a JDK dynamic proxy backed by ClientInvocationHandler which delegates to NettyRemotingClient.sendSync().

Usage

Call Clients.withService(IMyService.class).withHost("host:port") to obtain a proxy. The proxy is cached and reused for subsequent calls to the same host and service interface.

Code Reference

Source Location

  • Repository: dolphinscheduler
  • File: dolphinscheduler-extract/dolphinscheduler-extract-base/src/main/java/org/apache/dolphinscheduler/extract/base/client/Clients.java (L37-53)
  • File: dolphinscheduler-extract/dolphinscheduler-extract-base/src/main/java/org/apache/dolphinscheduler/extract/base/client/JdkDynamicRpcClientProxyFactory.java (L45-74)

Signature

public class Clients {
    public static <T> JdkDynamicRpcClientProxyBuilder<T> withService(Class<T> serviceClazz);

    public static class JdkDynamicRpcClientProxyBuilder<T> {
        public T withHost(String serviceHost);
    }
}

public class JdkDynamicRpcClientProxyFactory {
    // Guava LoadingCache with 1-hour expiry
    private static final LoadingCache<String, Object> proxyClientCache;

    public static <T> T getProxyClient(String serviceHost, Class<T> serviceClazz);
    private static <T> T newProxyClient(String serviceHost, Class<T> serviceClazz);
}

Import

import org.apache.dolphinscheduler.extract.base.client.Clients;

I/O Contract

Inputs

Name Type Required Description
serviceClazz Class<T> Yes @RpcService annotated interface class
serviceHost String Yes Target server address (host:port)

Outputs

Name Type Description
Proxy instance T JDK dynamic proxy implementing the service interface

Usage Examples

Creating a Workflow Control Client

// Get a proxy to the master's workflow control service
IWorkflowControlClient client = Clients
    .withService(IWorkflowControlClient.class)
    .withHost("master-host:5678");

// Call remote method as if local
WorkflowManualTriggerResponse response = client.manualTriggerWorkflow(
    WorkflowManualTriggerRequest.builder()
        .userId(1)
        .workflowDefinitionCode(123456L)
        .workflowDefinitionVersion(1)
        .build()
);

Creating a Task Executor Client

IPhysicalTaskExecutorOperator taskClient = Clients
    .withService(IPhysicalTaskExecutorOperator.class)
    .withHost("worker-host:1234");

taskClient.dispatchTask(taskDispatchRequest);

Related Pages

Implements Principle

Requires Environment

Page Connections

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