MatrixAnalyzer extends AbstractMessageAnalyzer<MatrixReport> implements LogEnabled { @Override public void process(MessageTree tree) { String domain = tree.getDomain(); MatrixReport report = m_reportManager.getHourlyReport(getStartTime(), domain, true); Message message = tree.getMessage(); if (message instanceof Transaction) { String messageType = message.getType(); if (messageType.equals("URL") || messageType.equals("Service") || messageType.equals("PigeonService")) { Matrix matrix = report.findOrCreateMatrix(message.getName()); matrix.setType(message.getType()); matrix.setName(message.getName()); long duration = ((Transaction) message).getDurationInMicros(); matrix.incCount(); matrix.setTotalTime(matrix.getTotalTime() + duration); Map<String, Ratio> ratios = new HashMap<String, Ratio>(); ratios.put("Call", new Ratio()); ratios.put("SQL", new Ratio()); ratios.put("Cache", new Ratio()); processTransaction(tree, (Transaction) message, ratios); for (Entry<String, Ratio> entry : ratios.entrySet()) { String type = entry.getKey(); Ratio ratio = entry.getValue(); int count = ratio.getTotalCount(); long time = ratio.getTotalTime(); Ratio real = matrix.findOrCreateRatio(type); if (real.getMin() > count || real.getMin() == 0) { real.setMin(count); } if (real.getMax() < count) { real.setMax(count); real.setUrl(tree.getMessageId()); } real.setTotalCount(real.getTotalCount() + count); real.setTotalTime(real.getTotalTime() + time); } if (matrix.getUrl() == null) { matrix.setUrl(tree.getMessageId()); } } } }  @Override synchronized void doCheckpoint(boolean atEnd); @Override void enableLogging(Logger logger); @Override MatrixReport getReport(String domain); @Override ReportManager<MatrixReport> getReportManager(); @Override boolean isEligable(MessageTree tree); @Override void process(MessageTree tree); static final String ID; }
@Test public void testProcess() throws Exception { for (int i = 1; i <= 100; i++) { MessageTree tree = generateMessageTree(i); m_analyzer.process(tree); } MatrixReport report = m_analyzer.getReport(m_domain); String expected = Files.forIO().readFrom(getClass().getResourceAsStream("matrix_analyzer.xml"), "utf-8"); MatrixReport expected4report = com.dianping.cat.consumer.matrix.model.transform.DefaultSaxParser.parse(expected); Assert.assertTrue(TestHelper.isEquals(expected4report,report)); }