feat[graalvm]: detect graalvm

This commit is contained in:
sun
2023-09-01 18:12:32 +08:00
parent 1dfbab43b0
commit 764ac0b449
2 changed files with 34 additions and 4 deletions
@@ -21,6 +21,7 @@ import com.zfoo.event.model.vo.EventReceiverDefinition;
import com.zfoo.protocol.collection.ArrayUtils;
import com.zfoo.protocol.util.ReflectionUtils;
import com.zfoo.protocol.util.StringUtils;
import com.zfoo.util.GraalVmUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
@@ -81,10 +82,12 @@ public class EventRegisterProcessor implements BeanPostProcessor {
var bus = method.getDeclaredAnnotation(EventReceiver.class).value();
var receiverDefinition = new EventReceiverDefinition(bean, method, bus, eventClazz);
var enhanceReceiverDefinition = EnhanceUtils.createEventReceiver(receiverDefinition);
// key:class类型 value:观察者 注册Event的receiverMap中
EventBus.registerEventReceiver(eventClazz, enhanceReceiverDefinition);
if (GraalVmUtils.isGraalVM()) {
EventBus.registerEventReceiver(eventClazz, receiverDefinition);
} else {
// key:class类型 value:观察者 注册Event的receiverMap中
EventBus.registerEventReceiver(eventClazz, EnhanceUtils.createEventReceiver(receiverDefinition));
}
}
} catch (Throwable t) {
throw new RuntimeException(t);
@@ -0,0 +1,27 @@
package com.zfoo.util;
import java.util.List;
/**
* @author godotg
*/
public abstract class GraalVmUtils {
private static final boolean GRAALVM;
static {
var properties = List.of(System.getProperty("java.vm.name", "")
, System.getProperty("java.vm.version", "")
, System.getProperty("java.vendor.version", "")
, System.getProperty("java.vendor.url", "")
, System.getProperty("org.graalvm.nativeimage.imagecode", "")
);
GRAALVM = properties.stream().map(it -> it.toLowerCase()).anyMatch(it -> it.contains("graalvm"));
}
public static boolean isGraalVM() {
return GRAALVM;
}
}