public class TunnelWorker extends Object implements ITunnelWorker
2. Perform Heartbeat at fixed intervals, determined by the heartbeatIntervalInSec parameter in TunnelWorkerConfig. 2.1 Perform a heartbeat request to get the latest available Channel list from the Tunnel server. The Channels will include ChannelId, Channel version, and Channel status information. 2.2 Merge the Channel list obtained from the server with the local memory Channel list, then create and update ChannelConnects according to the following rules: 1) Merge: For Channels with the same ChannelId, the one with the higher version number is considered the latest state and will be directly overwritten. If a Channel does not appear in the local list, it will be directly inserted. 2) Create new ChannelConnect: If there is no existing ChannelConnect corresponding to this Channel, a new WAIT state ChannelConnect will be created. If the Channel's state is OPEN, the data processing cyclic pipeline task (ReadRecords && ProcessRecords) on the ChannelConnect will also be started. For more details, refer to ProcessDataPipeline. 3) Update existing ChannelConnect: After merging, if a ChannelConnect exists for the corresponding Channel, its state will be updated according to the state of the Channel with the same ChannelId. For example, if the Channel is in the Close state, the ChannelConnect state will also be set to Closed, thereby terminating the pipeline task. For more details, see the ChannelConnect.notifyStatus method.
3. Automated load balancing and good horizontal scalability When multiple TunnelWorkers consume the same Tunnel (with the same TunnelId), during the execution of Heartbeat, the Tunnel server will automatically redistribute Channel resources so that active Channels are evenly distributed across each TunnelWorker, achieving resource load balancing. In terms of horizontal scalability, users can easily increase the number of TunnelWorkers, which can be deployed on the same machine or different machines.
4. Automated resource cleanup and fault-tolerant handling 4.1 Resource cleanup: When the client (TunnelWorker) is not properly shut down (e.g., abnormal exit or manual termination), we will automatically help users reclaim resources, including releasing thread pools, automatically calling the shutdown methods registered by users on the Channel, and closing Tunnel connections. 4.2 Fault-tolerant handling: When the client encounters non-parameter errors such as Heartbeat timeouts, we will automatically Renew the connection for the user to ensure that data consumption can continue stably and continuously.
| 构造器和说明 |
|---|
TunnelWorker(String tunnelId,
TunnelClientInterface client,
TunnelWorkerConfig workerConfig) |
TunnelWorker(String tunnelId,
TunnelClientInterface client,
TunnelWorkerConfig workerConfig,
IChannelProcessorFactory factory) |
public TunnelWorker(String tunnelId, TunnelClientInterface client, TunnelWorkerConfig workerConfig)
public TunnelWorker(String tunnelId, TunnelClientInterface client, TunnelWorkerConfig workerConfig, IChannelProcessorFactory factory)
public void connectAndWorking()
throws Exception
connectAndWorking 在接口中 ITunnelWorkerExceptionpublic void shutdown()
shutdown 在接口中 ITunnelWorkerCopyright © 2025. All Rights Reserved.