1 22 23 package org.objectweb.petals.kernel.admin.service; 24 25 import java.util.ArrayList ; 26 import java.util.HashMap ; 27 import java.util.List ; 28 import java.util.Map ; 29 30 import javax.jbi.messaging.ExchangeStatus; 31 import javax.jbi.messaging.MessageExchange.Role; 32 33 import org.objectweb.petals.monitoring.ExchangeStateCapture; 34 import org.objectweb.petals.monitoring.ExchangeStateReport; 35 36 41 public class MonitoringService { 42 43 public static List <List <Map <String ,Object >>> bulkData(List <ExchangeStateReport> reports) { 44 List <List <Map <String ,Object >>> bulk = new ArrayList <List <Map <String ,Object >>>(reports.size()); 45 46 for (ExchangeStateReport report : reports) { 47 bulk.add(reportToRaw(report)); 48 } 49 return bulk; 50 } 51 52 60 protected static List <Map <String ,Object >> reportToRaw(ExchangeStateReport report) { 61 62 List <Map <String ,Object >> rawCaptures = new ArrayList <Map <String ,Object >>(); 63 for (ExchangeStateCapture capture : report.getReportList()) { 64 rawCaptures.add(captureToRaw(report.getId(),capture)); 65 } 66 return rawCaptures; 67 } 68 69 81 protected static Map <String ,Object > captureToRaw(String exchangeId, ExchangeStateCapture capture) { 82 83 Map <String ,Object > rawCapture = new HashMap <String ,Object >(); 84 rawCapture.put("id", exchangeId); 85 rawCapture.put("time", capture.time); 86 rawCapture.put("component", capture.component); 87 rawCapture.put("role", roleToRaw(capture.role)); 88 rawCapture.put("type", capture.messageType); 89 rawCapture.put("status", statusToRaw(capture.status)); 90 91 return rawCapture; 92 } 93 94 99 protected static String roleToRaw(Role role){ 100 return (Role.CONSUMER.equals(role))?"consumer":"provider"; 101 } 102 103 108 protected static String statusToRaw(ExchangeStatus status){ 109 return (ExchangeStatus.DONE.equals(status))?"done":(ExchangeStatus.ACTIVE.equals(status))?"active":"error"; 110 } 111 } 112 | Popular Tags |