com.alibaba.tmq.client.logger.ClientLoggerEvent Maven / Gradle / Ivy
package com.alibaba.tmq.client.logger;
import java.util.Collections;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.alibaba.tmq.client.context.ClientContext;
import com.alibaba.tmq.client.remoting.ClientRemoting;
import com.alibaba.tmq.client.util.StringUtil;
import com.alibaba.tmq.common.constants.Constants;
import com.alibaba.tmq.common.context.InvocationContext;
import com.alibaba.tmq.common.domain.TracePoint;
import com.alibaba.tmq.common.domain.remoting.ConnectionChannel;
import com.alibaba.tmq.common.domain.result.Result;
import com.alibaba.tmq.common.logger.LoggerEvent;
import com.alibaba.tmq.common.util.ListUtil;
public class ClientLoggerEvent extends ClientContext implements LoggerEvent, Constants {
private static final Log logger = LogFactory.getLog(ClientLoggerEvent.class);
@Override
public void onEvent(List tracePointList) {
// List serverList = clientRemoting.getServerList();
List serverList = null;
if(StringUtil.isNotBlank(clientConfig.getBackupDomainName())) {
// serverList = clientRemoting.getbackupServerList();
serverList = null;
}
if(ListUtil.isEmpty(serverList)) {
// logger.error("[ClientLoggerEvent]: serverList is empty, clientConfig:" + clientConfig);
return ;
}
/** 随机列表顺序 */
Collections.shuffle(serverList);
for(String server : serverList) {
Result connectResult = null;
try {
ConnectionChannel connectionChannel = new ConnectionChannel(server, ROLE_TYPE_PRODUCER, null);
InvocationContext.setConnectionChannel(connectionChannel);
connectResult = ClientRemoting.serverService.trace(tracePointList);
} catch (Throwable e) {
logger.warn("[ClientLoggerEvent]: trace error"
+ ", clientConfig:" + clientConfig
+ ", server:" + server
+ ", tracePointList:" + tracePointList, e);
}
if(connectResult != null && connectResult.getData().booleanValue()) {
return ;
} else {
logger.warn("[ClientLoggerEvent]: trace failed"
+ ", clientConfig:" + clientConfig
+ ", server:" + server
+ ", tracePointList:" + tracePointList);
}
}
}
}