-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Robin Han <[email protected]>
- Loading branch information
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
automq-shell/src/main/java/com/automq/shell/util/CLIUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2024, AutoMQ HK Limited. | ||
* | ||
* The use of this file is governed by the Business Source License, | ||
* as detailed in the file "/LICENSE.S3Stream" included in this repository. | ||
* | ||
* As of the Change Date specified in that file, in accordance with | ||
* the Business Source License, use of this software will be governed | ||
* by the Apache License, Version 2.0 | ||
*/ | ||
|
||
package com.automq.shell.util; | ||
|
||
import java.util.Collections; | ||
import org.apache.kafka.clients.ApiVersions; | ||
import org.apache.kafka.clients.ClientUtils; | ||
import org.apache.kafka.clients.CommonClientConfigs; | ||
import org.apache.kafka.clients.ManualMetadataUpdater; | ||
import org.apache.kafka.clients.MetadataRecoveryStrategy; | ||
import org.apache.kafka.clients.NetworkClient; | ||
import org.apache.kafka.clients.admin.AdminClientConfig; | ||
import org.apache.kafka.common.metrics.Metrics; | ||
import org.apache.kafka.common.network.ChannelBuilder; | ||
import org.apache.kafka.common.network.NetworkReceive; | ||
import org.apache.kafka.common.network.Selector; | ||
import org.apache.kafka.common.utils.LogContext; | ||
import org.apache.kafka.common.utils.Time; | ||
|
||
public class CLIUtils { | ||
public static NetworkClient buildNetworkClient( | ||
String prefix, | ||
AdminClientConfig config, | ||
Metrics metrics, | ||
Time time, | ||
LogContext logContext) { | ||
ChannelBuilder channelBuilder = ClientUtils.createChannelBuilder(config, time, logContext); | ||
|
||
String metricGroupPrefix = prefix + "-channel"; | ||
|
||
Selector selector = new Selector( | ||
NetworkReceive.UNLIMITED, | ||
config.getLong(CommonClientConfigs.CONNECTIONS_MAX_IDLE_MS_CONFIG), | ||
metrics, | ||
time, | ||
metricGroupPrefix, | ||
Collections.emptyMap(), | ||
false, | ||
channelBuilder, | ||
logContext | ||
); | ||
|
||
String clientId = prefix + "-network-client"; | ||
return new NetworkClient( | ||
selector, | ||
new ManualMetadataUpdater(), | ||
clientId, | ||
100, | ||
config.getLong(CommonClientConfigs.RECONNECT_BACKOFF_MS_CONFIG), | ||
config.getLong(CommonClientConfigs.RECONNECT_BACKOFF_MAX_MS_CONFIG), | ||
config.getInt(CommonClientConfigs.SEND_BUFFER_CONFIG), | ||
config.getInt(CommonClientConfigs.RECEIVE_BUFFER_CONFIG), | ||
config.getInt(CommonClientConfigs.REQUEST_TIMEOUT_MS_CONFIG), | ||
config.getLong(CommonClientConfigs.SOCKET_CONNECTION_SETUP_TIMEOUT_MS_CONFIG), | ||
config.getLong(CommonClientConfigs.SOCKET_CONNECTION_SETUP_TIMEOUT_MAX_MS_CONFIG), | ||
time, | ||
false, | ||
new ApiVersions(), | ||
logContext, | ||
MetadataRecoveryStrategy.NONE | ||
); | ||
} | ||
} |