use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.
the class KafkaListenerContainerInterceptor method tryRefreshBeanFactory.
private boolean tryRefreshBeanFactory(Object target) {
try {
KafkaMessageListenerContainer kafkaMessageListenerContainer = Reflect.on(target).get("this$0");
ApplicationEventPublisher applicationEventPublisher = kafkaMessageListenerContainer.getApplicationEventPublisher();
if (applicationEventPublisher instanceof AnnotationConfigApplicationContext) {
PradarSpringUtil.refreshBeanFactory((DefaultListableBeanFactory) ((AnnotationConfigApplicationContext) applicationEventPublisher).getAutowireCapableBeanFactory());
return true;
} else if (applicationEventPublisher instanceof AbstractRefreshableApplicationContext) {
PradarSpringUtil.refreshBeanFactory((DefaultListableBeanFactory) ((AbstractRefreshableApplicationContext) applicationEventPublisher).getAutowireCapableBeanFactory());
return true;
} else {
try {
PradarSpringUtil.refreshBeanFactory((DefaultListableBeanFactory) Reflect.on(applicationEventPublisher).call("getAutowireCapableBeanFactory").get());
return true;
} catch (ReflectException e) {
logger.warn("tryRefreshBeanFactory fail spring-kafka version is not support, applicationEventPublisher is a " + applicationEventPublisher.getClass().getName());
}
}
} catch (Exception e) {
logger.warn("kafka tryRefreshBeanFactory fail", e);
}
return false;
}
use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.
the class RedissonNodesStrategy method getAddress.
public static List getAddress(Config config) {
SingleServerConfig singleServerConfig = null;
try {
singleServerConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_SINGLE_SERVER_CONFIG);
} catch (ReflectException e) {
}
ClusterServersConfig clusterServersConfig = null;
try {
clusterServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_CLUSTER_SERVERS_CONFIG);
} catch (ReflectException e) {
}
SentinelServersConfig sentinelServersConfig = null;
try {
sentinelServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_SENTINEL_SERVERS_CONFIG);
} catch (ReflectException e) {
}
ReplicatedServersConfig replicatedServersConfig = null;
try {
replicatedServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_REPLICATED_SERVERS_CONFIG);
} catch (ReflectException e) {
}
MasterSlaveServersConfig masterSlaveServersConfig = null;
try {
masterSlaveServersConfig = Reflect.on(config).get(RedissonConstants.DYNAMIC_FIELD_MASTER_SLAVE_SERVERS_CONFIG);
} catch (ReflectException e) {
}
if (singleServerConfig != null) {
// 在这里返回的address在不同版本可能返回String,可能返回URI在这里做处理
Object address = Reflect.on(singleServerConfig).get("address");
String addressConvert = null;
if (address instanceof URI) {
URI uriConvert = (URI) address;
addressConvert = RedissonUtils.addPre(new StringBuilder().append(uriConvert.getHost()).append(":").append(uriConvert.getPort()).toString());
} else if (address instanceof String) {
addressConvert = (String) address;
}
return RedissonUtils.removePre(addressConvert);
} else if (clusterServersConfig != null) {
return RedissonUtils.removePre(clusterServersConfig.getNodeAddresses());
} else if (sentinelServersConfig != null) {
List<String> result = RedissonUtils.removePre(sentinelServersConfig.getSentinelAddresses());
result.add(sentinelServersConfig.getMasterName());
return result;
} else if (replicatedServersConfig != null) {
return RedissonUtils.removePre(replicatedServersConfig.getNodeAddresses());
} else if (masterSlaveServersConfig != null) {
String master = masterSlaveServersConfig.getMasterAddress();
Set<String> slave = masterSlaveServersConfig.getSlaveAddresses();
List<String> result = new ArrayList(RedissonUtils.removePre(slave));
result.addAll(RedissonUtils.removePre(master));
return result;
}
return null;
}
use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.
the class HttpClientInterceptor method doBefore.
@Override
public void doBefore(Advice advice) {
InnerWhiteListCheckUtil.check();
Object target = advice.getTarget();
ClusterTestUtils.validateClusterTest();
HttpClient client = (HttpClient) target;
MessageHeader header = null;
try {
initField(client);
header = Reflect.on(client).get(FIELD);
} catch (ReflectException e) {
LOGGER.warn("{} has not field {}", client.getClass().getName(), JdkHttpConstants.DYNAMIC_FIELD_REQUESTS);
}
if (header == null) {
header = new MessageHeader();
}
Map<String, String> ctx = Pradar.getInvokeContextTransformMap();
for (Map.Entry<String, String> entry : ctx.entrySet()) {
header.set(entry.getKey(), entry.getValue());
}
try {
Reflect.on(client).set(FIELD, header);
} catch (ReflectException e) {
LOGGER.warn("{} has not field {}", client.getClass().getName(), JdkHttpConstants.DYNAMIC_FIELD_REQUESTS);
}
}
use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.
the class HttpURLConnectionInterceptor method beforeTrace.
@Override
public SpanRecord beforeTrace(Advice advice) {
InnerWhiteListCheckUtil.check();
Object target = advice.getTarget();
final HttpURLConnection request = (HttpURLConnection) target;
boolean connected = false;
try {
initConnectedField(target);
connected = Reflect.on(target).get(CONNECTED_FiELD);
} catch (ReflectException e) {
LOGGER.warn("{} has not field {}", target.getClass().getName(), JdkHttpConstants.DYNAMIC_FIELD_CONNECTED);
}
boolean connecting = false;
try {
initConnectingField(target);
connecting = Reflect.on(target).get(CONNECTING_FiELD);
} catch (ReflectException e) {
LOGGER.warn("{} has not field {}", target.getClass().getName(), JdkHttpConstants.DYNAMIC_FIELD_CONNECTING);
}
if (connected) {
advice.mark(MARK_CONNECTED);
}
if (connecting) {
advice.mark(MARK_CONNECTING);
}
if (connected || connecting) {
return null;
}
SpanRecord record = new SpanRecord();
String host = request.getURL().getHost();
int port = request.getURL().getPort();
String path = request.getURL().getPath();
record.setService(path);
record.setMethod(StringUtils.upperCase(request.getRequestMethod()));
record.setRemoteIp(host);
record.setPort(port);
return record;
}
use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.
the class ConsumerMetaData method build.
public static ConsumerMetaData build(KafkaConsumer consumer) {
Set<String> topics = consumer.subscription();
try {
Object coordinator = Reflect.on(consumer).get(KafkaConstants.REFLECT_FIELD_COORDINATOR);
Object groupId = ReflectUtil.reflectSlience(consumer, KafkaConstants.REFLECT_FIELD_GROUP_ID);
if (groupId == null) {
groupId = ReflectUtil.reflectSlience(coordinator, KafkaConstants.REFLECT_FIELD_GROUP_ID);
if (groupId == null) {
throw new PressureMeasureError("未支持的kafka版本!未能获取groupId");
}
}
String bootstrapServers = KafkaUtils.getBootstrapServers(consumer);
String groupIdStr = "";
if (groupId instanceof String) {
groupIdStr = (String) groupId;
} else {
groupIdStr = ReflectUtil.reflectSlience(groupId, "value");
}
return new ConsumerMetaData(topics, groupIdStr, bootstrapServers);
} catch (ReflectException e) {
throw new PressureMeasureError(e);
}
}
Aggregations