Skip to content

Commit

Permalink
Fix publisher config injection error.
Browse files Browse the repository at this point in the history
  • Loading branch information
hexiaofeng committed May 22, 2024
1 parent 59f76cb commit 294daa4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ public TypeInfo(Class<?> rawType, Class<?> inboxType) {
this(rawType, inboxType, inboxType);
}

/**
* Constructs a new {@code TypeInfo} instance with the specified raw type.
*
* @param rawType the raw type of the class
*/
public TypeInfo(Class<?> rawType) {
this(rawType, rawType, rawType);
}

/**
* Determines if the raw type represents a collection.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
package com.jd.live.agent.core.inject.jbind.converter.supplier;

import com.jd.live.agent.core.extension.annotation.Extension;
import com.jd.live.agent.core.inject.jbind.Conversion;
import com.jd.live.agent.core.inject.jbind.ConversionType;
import com.jd.live.agent.core.inject.jbind.Converter;
import com.jd.live.agent.core.inject.jbind.ConverterSupplier;
import com.jd.live.agent.core.inject.jbind.*;

import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
Expand All @@ -48,21 +47,48 @@ public static class Map2MapConverter implements Converter {
@Override
public Object convert(final Conversion conversion) throws Exception {
Map<Object, Object> result = null;
Class<?> targetType = conversion.getTargetType().getRawType();
if (Map.class == targetType) {
TypeInfo typeInfo = conversion.getTargetType();
Class<?> targetClass = typeInfo.getRawType();
if (Map.class == targetClass) {
result = new HashMap<>();
} else if (ConcurrentMap.class == targetType) {
} else if (ConcurrentMap.class == targetClass) {
result = new ConcurrentHashMap<>();
} else if (SortedMap.class == targetType) {
} else if (SortedMap.class == targetClass) {
result = new TreeMap<>();
} else if (NavigableMap.class == targetType) {
} else if (NavigableMap.class == targetClass) {
result = new TreeMap<>();
} else if (ConcurrentNavigableMap.class == targetType) {
} else if (ConcurrentNavigableMap.class == targetClass) {
result = new ConcurrentSkipListMap<>();
} else if (!targetType.isInterface()) {
result = (Map<Object, Object>) targetType.newInstance();
} else if (!targetClass.isInterface()) {
result = (Map<Object, Object>) targetClass.newInstance();
}
if (result != null) {
Type type = typeInfo.getType();
if (type instanceof ParameterizedType) {
// parameterized conversion
ParameterizedType parameterizedType = (ParameterizedType) type;
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
if (actualTypeArguments != null
&& actualTypeArguments.length == 2
&& actualTypeArguments[0] instanceof Class
&& actualTypeArguments[1] instanceof Class) {
Map<?, ?> source = (Map<?, ?>) conversion.getSource();
TypeInfo targetKeyType = new TypeInfo((Class<?>) actualTypeArguments[0]);
TypeInfo targetValueType = new TypeInfo((Class<?>) actualTypeArguments[1]);
for (Map.Entry<?, ?> entry : source.entrySet()) {
Object key = entry.getKey();
Object value = entry.getValue();
TypeInfo srcKeyType = new TypeInfo(key.getClass());
TypeInfo srcValueType = new TypeInfo(value.getClass());
Converter keyConverter = conversion.getConverter(new ConversionType(srcKeyType, targetKeyType));
Converter valueConverter = conversion.getConverter(new ConversionType(srcValueType, targetValueType));
Conversion keyConversion = conversion.of(srcKeyType, targetKeyType, key);
Conversion valueConversion = conversion.of(srcValueType, targetValueType, value);
result.put(keyConverter.convert(keyConversion), valueConverter.convert(valueConversion));
}
return result;
}
}
result.putAll((Map<Object, Object>) conversion.getSource());
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class PublisherConfig {

public static final int DEFAULT_CAPACITY = 1000;

public static final int DEFAULT_TIMEOUT = 100;
public static final int DEFAULT_TIMEOUT = 0;

public static final int BATCH_SIZE = 100;

Expand Down
5 changes: 3 additions & 2 deletions joylive-package/src/main/assembly/config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ agent:
- com.huaweicloud.sermant.core.plugin.classloader.ServiceClassLoader
- com.alipay.sofa.ark.container.service.classloader.PluginClassLoader
publisher:
liveEvent:
capacity: 20000
configs:
traffic:
capacity: 20000
plugin:
systems:
- system
Expand Down

0 comments on commit 294daa4

Please sign in to comment.