public class EventPublisher implements ServiceStatsProcessor {
private static Log log = LogFactory.getLog(EventPublisher.class);
public void process(StatisticData[] statisticData) {
EventBroker broker = StatisticsServiceComponent.getEventBroker();
Message message = new Message();
OMElement eventPayLoad = null;
for (StatisticData statistic : statisticData) {
eventPayLoad = constructEventPayLoad(statistic);
message.setMessage(eventPayLoad);
try {
SuperTenantCarbonContext.startTenantFlow();
int tenantId = SuperTenantCarbonContext.getCurrentContext(StatisticsServiceComponent.getConfigurationContext()).getTenantId();
SuperTenantCarbonContext.getCurrentContext().setTenantId(tenantId);
SuperTenantCarbonContext.getCurrentContext().getTenantDomain(true);
broker.publishRobust(message, ServiceStatisticsPublisherConstants.BAM_REG_PATH);
} catch (EventBrokerException e) {
log.error("Can not publish the message ", e);
} finally {
SuperTenantCarbonContext.endTenantFlow();