Skip to content

Commit

Permalink
[INLONG-10387][Audit] Optimization function name
Browse files Browse the repository at this point in the history
  • Loading branch information
doleyzi committed Jun 13, 2024
1 parent e4a90f0 commit bf0e477
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public static Map<String, String> getAuthHeader(AuthConfig authConfig) {
}
return header;
}
public static String sendGet(String component, String url, AuthConfig authConfig, int timeoutMs) {

public static String httpGet(String component, String url, AuthConfig authConfig, int timeoutMs) {
if (httpClient == null) {
LOGGER.error("httpClient is null");
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public void setAuditProxy(HashSet<String> ipPortList) {
*/
public void setAuditProxy(AuditComponent component, String managerHost, AuthConfig authConfig) {
checkInitStatus();
ProxyManager.getInstance().setAuditProxy(component, managerHost, authConfig);
ProxyManager.getInstance().setManagerConfig(component, managerHost, authConfig);
}

private synchronized void checkInitStatus() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class ProxyManager {
private AuthConfig authConfig;
private String auditProxyApiUrl;
private AuditComponent component;
private volatile boolean timerStarted = false;

private ProxyManager() {
}
Expand All @@ -66,7 +67,7 @@ public synchronized void setAuditProxy(HashSet<String> ipPortList) {
}
}

public synchronized void setAuditProxy(AuditComponent component, String managerHost, AuthConfig authConfig) {
public synchronized void setManagerConfig(AuditComponent component, String managerHost, AuthConfig authConfig) {
if (!managerHost.endsWith("/")) {
managerHost = managerHost + "/";
}
Expand All @@ -79,16 +80,16 @@ public synchronized void setAuditProxy(AuditComponent component, String managerH
this.authConfig = authConfig;
this.component = component;

requestFromManager();
updateAuditProxy();

if (autoUpdateAuditProxy) {
updateAuditProxy();
startTimer();
LOGGER.info("Auto Update from manager");
}
}

private void requestFromManager() {
String response = HttpUtils.sendGet(component.getComponent(), auditProxyApiUrl, authConfig, timeoutMs);
private void updateAuditProxy() {
String response = HttpUtils.httpGet(component.getComponent(), auditProxyApiUrl, authConfig, timeoutMs);
if (response == null) {
LOGGER.error("Response is null: {} {} {} ", component.getComponent(), auditProxyApiUrl, authConfig);
return;
Expand All @@ -107,11 +108,15 @@ private void requestFromManager() {
LOGGER.info("Get audit proxy from manager: {}", proxyList);
}

private void updateAuditProxy() {
timer.scheduleWithFixedDelay(this::requestFromManager,
private synchronized void startTimer() {
if (timerStarted) {
return;
}
timer.scheduleWithFixedDelay(this::updateAuditProxy,
0,
updateInterval,
TimeUnit.MILLISECONDS);
timerStarted = true;
}

public void setManagerTimeout(int timeoutMs) {
Expand Down

0 comments on commit bf0e477

Please sign in to comment.