Add application profile enum.

pull/1133/head
yanrongzhen 3 years ago
parent 382ff3a0ec
commit 5a9a16d1e4

@ -17,6 +17,7 @@
package cn.hippo4j.common.config; package cn.hippo4j.common.config;
import cn.hippo4j.common.enums.ProfileEnum;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
@ -90,4 +91,12 @@ public class ApplicationContextHolder implements ApplicationContextAware {
public static ApplicationContext getInstance() { public static ApplicationContext getInstance() {
return CONTEXT; return CONTEXT;
} }
/**
* Get current application profile.
*/
public static ProfileEnum getActiveProfile() {
return ProfileEnum.of(CONTEXT.getEnvironment().getActiveProfiles()[0]);
}
} }

@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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 cn.hippo4j.common.enums;
import java.util.Arrays;
/**
* Application profile enum.
*/
public enum ProfileEnum {
UNKNOWN,
DEV,
TEST01,
PRE,
PROD;
public static ProfileEnum of(String profileStr) {
return Arrays.stream(values())
.filter(v -> v.name().equalsIgnoreCase(profileStr))
.findFirst()
.orElse(UNKNOWN);
}
}

@ -33,20 +33,28 @@ import org.springframework.beans.factory.annotation.Value;
@Slf4j @Slf4j
public class WebThreadPoolConfigChangeHandler implements ThreadPoolConfigChange<WebChangeParameterNotifyRequest> { public class WebThreadPoolConfigChangeHandler implements ThreadPoolConfigChange<WebChangeParameterNotifyRequest> {
@Value("${spring.profiles.active:UNKNOWN}")
private String active;
@Value("${spring.dynamic.thread-pool.item-id:}")
private String itemId;
@Value("${spring.application.name:UNKNOWN}") @Value("${spring.application.name:UNKNOWN}")
private String applicationName; private String applicationName;
private final Hippo4jSendMessageService hippo4jSendMessageService; private final Hippo4jSendMessageService hippo4jSendMessageService;
/** /**
* Send pool config change. * Send pool config change message for web.
* *
* @param requestParam change parameter notify request * @param requestParam change parameter notify request
*/ */
@Override @Override
public void sendPoolConfigChange(WebChangeParameterNotifyRequest requestParam) { public void sendPoolConfigChange(WebChangeParameterNotifyRequest requestParam) {
try { try {
requestParam.setAppName(applicationName); requestParam.setActive(active.toUpperCase());
String appName = StringUtil.isBlank(itemId) ? applicationName : itemId;
requestParam.setAppName(appName);
requestParam.setIdentify(IdentifyUtil.getIdentify()); requestParam.setIdentify(IdentifyUtil.getIdentify());
hippo4jSendMessageService.sendChangeMessage(requestParam); hippo4jSendMessageService.sendChangeMessage(requestParam);
} catch (Throwable th) { } catch (Throwable th) {

Loading…
Cancel
Save