use of com.pamirs.attach.plugin.apache.kafka.origin.ConsumerProxy in project LinkAgent by shulieTech.
the class AbstractProxiedConsumerInterceptor method cutoff0.
@Override
public CutOffResult cutoff0(Advice advice) throws Throwable {
ConsumerProxy consumerProxy = ConsumerHolder.getProxy(advice.getTarget());
if (consumerProxy == null) {
return CutOffResult.passed();
}
Object result = doCutoff(consumerProxy, advice);
if (result instanceof CutOffResult) {
return (CutOffResult) result;
} else {
return CutOffResult.cutoff(result);
}
}
use of com.pamirs.attach.plugin.apache.kafka.origin.ConsumerProxy in project LinkAgent by shulieTech.
the class ConsumerPollInterceptor method doOriginIntercept.
private CutOffResult doOriginIntercept(Advice advice) {
if (GlobalConfig.getInstance().getMqWhiteList() == null || GlobalConfig.getInstance().getMqWhiteList().isEmpty()) {
return CutOffResult.PASSED;
}
KafkaConsumer consumer = (KafkaConsumer) advice.getTarget();
ConsumerMetaData consumerMetaData = ConsumerHolder.getConsumerMetaData(consumer);
if (consumerMetaData == null) {
return CutOffResult.passed();
}
Object[] args = advice.getParameterArray();
long timeout = 100L;
if (args[0] instanceof Long) {
timeout = (Long) args[0];
} else /* else if (args[0] instanceof Duration) {
timeout = ((Duration)args[0]).toMillis();
} */
if (args[0] instanceof Timer) {
timeout = ((Timer) args[0]).remainingMs();
}
if (consumerMetaData.isHasShadow()) {
ConsumerProxy consumerProxy = ConsumerHolder.getProxyOrCreate(consumer, timeout);
if (consumerProxy == null) {
return CutOffResult.PASSED;
}
return CutOffResult.cutoff(consumerProxy.poll(timeout));
} else {
if (warnAlready.compareAndSet(false, true)) {
LOGGER.warn("consumer with group id : {} topic : {} doesn't has shadow consumer config", consumerMetaData.getGroupId(), consumerMetaData.getTopics());
}
return CutOffResult.passed();
}
}
use of com.pamirs.attach.plugin.apache.kafka.origin.ConsumerProxy in project LinkAgent by shulieTech.
the class ShadowConsumerDisableListenerImpl method disableBatchOriginKafka.
private void disableBatchOriginKafka(String key, String topic, String group) {
try {
int code = ConsumerHolder.getShadowProxyMapping().get(key);
ConsumerProxy consumerProxy = ConsumerHolder.getProxyMapping().get(code);
consumerProxy.closePtConsumer();
ConsumerHolder.getProxyMapping().remove(code);
ConsumerHolder.getCache().remove(code);
for (Map.Entry<Integer, ConsumerMetaData> entry : ConsumerHolder.getCache().entrySet()) {
if (entry.getValue().getTopics().contains(Pradar.addClusterTestPrefix(topic)) && entry.getValue().getGroupId().equals(Pradar.addClusterTestPrefix(group))) {
ConsumerHolder.getCache().remove(entry.getKey());
break;
}
}
ConsumerHolder.getShadowProxyMapping().remove(key);
} catch (Throwable t) {
logger.error("[apache-kafka]: {}", Throwables.getStackTraceAsString(t));
}
}
use of com.pamirs.attach.plugin.apache.kafka.origin.ConsumerProxy in project LinkAgent by shulieTech.
the class ShadowConsumerDisableListenerImpl method disableAllOriginKafka.
private void disableAllOriginKafka() {
for (ConsumerProxy consumerProxy : ConsumerHolder.getProxyMapping().values()) {
consumerProxy.closePtConsumer();
}
ConsumerHolder.getProxyMapping().clear();
ConsumerHolder.getCache().clear();
ConsumerHolder.getShadowProxyMapping().clear();
}
Aggregations