Skip to content

Commit

Permalink
Update Resilience4jUtils.java
Browse files Browse the repository at this point in the history
  • Loading branch information
mercyblitz committed Jan 21, 2025
1 parent 1cb3186 commit ea40541
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@
package io.microsphere.resilience4j.util;

import io.github.resilience4j.core.Registry;
import io.microsphere.reflect.MethodUtils;
import io.microsphere.resilience4j.common.Resilience4jModule;
import io.microsphere.util.BaseUtils;

import java.lang.invoke.MethodHandle;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import static io.microsphere.invoke.MethodHandleUtils.findVirtual;
import static io.microsphere.reflect.MethodUtils.findMethod;
import static io.microsphere.reflect.MethodUtils.invokeMethod;
import static io.microsphere.resilience4j.common.Resilience4jModule.valueOf;
Expand All @@ -42,19 +39,18 @@
*/
public abstract class Resilience4jUtils extends BaseUtils {


private static final Map<Resilience4jModule, Method> getEntryMethodsCache;

static {
Resilience4jModule[] modules = Resilience4jModule.values();
Map<Resilience4jModule, Method> methodsCache = new HashMap<>(modules.length);
for (Resilience4jModule module : modules) {
initGetEntryMethodHandlesCache(module, methodsCache);
initGetEntryMethodsCache(module, methodsCache);
}
getEntryMethodsCache = unmodifiableMap(methodsCache);
}

private static void initGetEntryMethodHandlesCache(Resilience4jModule module, Map<Resilience4jModule, Method> methodsCache) {
private static void initGetEntryMethodsCache(Resilience4jModule module, Map<Resilience4jModule, Method> methodsCache) {
Class<?> entryClass = module.getEntryClass();
Class<?> configClass = module.getConfigurationClass();
Class<?> registryClass = module.getRegistryClass();
Expand All @@ -63,6 +59,10 @@ private static void initGetEntryMethodHandlesCache(Resilience4jModule module, Ma
methodsCache.put(module, method);
}

public static <E, C> E getEntry(Registry<E, C> registry, String name) {
return getEntry(registry, name, registry.getDefaultConfig());
}

public static <E, C> E getEntry(Registry<E, C> registry, String name, C configuration) {
Resilience4jModule module = valueOf(registry.getClass());
Method method = getEntryMethodsCache.get(module);
Expand Down

0 comments on commit ea40541

Please sign in to comment.