Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Server Starup Issue #12692

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading