Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
BLasan committed Nov 27, 2024
1 parent a1781ac commit 6439354
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.wso2.carbon.apimgt.gateway.throttling.util.BlockingConditionRetriever;
import org.wso2.carbon.apimgt.gateway.throttling.util.KeyTemplateRetriever;
import org.wso2.carbon.apimgt.gateway.utils.GatewayUtils;
import org.wso2.carbon.apimgt.gateway.utils.InternalServiceCall;
import org.wso2.carbon.apimgt.gateway.webhooks.WebhooksDataHolder;
import org.wso2.carbon.apimgt.impl.APIConstants;
import org.wso2.carbon.apimgt.impl.certificatemgt.exceptions.CertificateManagementException;
Expand Down Expand Up @@ -66,6 +67,8 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Stream;

/**
Expand All @@ -80,6 +83,7 @@ public class GatewayStartupListener extends AbstractAxis2ConfigurationContextObs
private JMSTransportHandler jmsTransportHandlerForTrafficManager;
private JMSTransportHandler jmsTransportHandlerForEventHub;
private ThrottleProperties throttleProperties;
private ExecutorService service = Executors.newFixedThreadPool(3, new InternalServiceCall());
private GatewayArtifactSynchronizerProperties gatewayArtifactSynchronizerProperties;
private boolean isAPIsDeployedInSyncMode = false;
private boolean isGatewayPoliciesDeployedInSyncMode = false;
Expand Down Expand Up @@ -192,11 +196,13 @@ public void completedServerStartup() {
}
}).start();
SubscriptionDataHolder.getInstance().registerTenantSubscriptionStore(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
try {
retrieveAllAPIMetadata();
} catch (DataLoadingException e) {
log.error("Error while loading All API Metadata", e);
}
service.execute(() -> {
try {
retrieveAllAPIMetadata();
} catch (DataLoadingException e) {
log.error("Error while loading All API Metadata", e);
}
});
if (GatewayUtils.isOnDemandLoading()) {
try {
new EndpointCertificateDeployer().deployAllCertificatesAtStartup();
Expand All @@ -222,9 +228,13 @@ public void completedServerStartup() {
jmsTransportHandlerForEventHub.subscribeForJmsEvents(APIConstants.TopicNames.TOPIC_ASYNC_WEBHOOKS_DATA,
new GatewayJMSMessageListener());
copyTenantArtifacts();
APILoggerManager.getInstance().initializeAPILoggerList();
LLMProviderManager.getInstance().initializeLLMProviderConfigurations(
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
service.execute(() -> {
APILoggerManager.getInstance().initializeAPILoggerList();
});
service.execute(() -> {
LLMProviderManager.getInstance()
.initializeLLMProviderConfigurations(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
});
} else {
log.info("Running on migration enabled mode: Stopped at Gateway Startup listener completed");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com/).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.apimgt.gateway.utils;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

public class InternalServiceCall implements ThreadFactory {
private static final AtomicInteger POOL_NUMBER = new AtomicInteger(1);
private final ThreadGroup group;
private final AtomicInteger threadNumber = new AtomicInteger(1);
private final String namePrefix;

public InternalServiceCall() {
SecurityManager securityManager = System.getSecurityManager();
group = (securityManager != null) ? securityManager.getThreadGroup() : Thread.currentThread().getThreadGroup();
namePrefix = "InternalServiceCall-pool-" + POOL_NUMBER.getAndIncrement() + "-thread-";
}

@Override
public Thread newThread(Runnable runnable) {
Thread thread = new Thread(group, runnable, namePrefix + threadNumber.getAndIncrement(), 0);
if (thread.isDaemon()) {
thread.setDaemon(false);
}
if (thread.getPriority() != Thread.NORM_PRIORITY) {
thread.setPriority(Thread.NORM_PRIORITY);
}
return thread;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ public void completedServerStartup() {
} else {
log.info("Running on migration enabled mode: Stopped at ServerStartupListener completed");
}
CorrelationConfigManager.getInstance().initializeCorrelationComponentList();

Thread thread = new Thread(() -> {
CorrelationConfigManager.getInstance().initializeCorrelationComponentList();
});
thread.start();
}

/**
Expand Down

0 comments on commit 6439354

Please sign in to comment.