KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > kernel > admin > service > MonitoringService


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: PetalsAdminService.java 16:40:52 alouis $
20  * -------------------------------------------------------------------------
21  */

22
23 package org.objectweb.petals.kernel.admin.service;
24
25 import java.util.ArrayList JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.List JavaDoc;
28 import java.util.Map JavaDoc;
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 /**
37  * This class is used for monitoring service
38  *
39  * @author alouis - eBMWebsourcing
40  */

41 public class MonitoringService {
42
43     public static List JavaDoc<List JavaDoc<Map JavaDoc<String JavaDoc,Object JavaDoc>>> bulkData(List JavaDoc<ExchangeStateReport> reports) {
44         List JavaDoc<List JavaDoc<Map JavaDoc<String JavaDoc,Object JavaDoc>>> bulk = new ArrayList JavaDoc<List JavaDoc<Map JavaDoc<String JavaDoc,Object JavaDoc>>>(reports.size());
45
46         for (ExchangeStateReport report : reports) {
47             bulk.add(reportToRaw(report));
48         }
49         return bulk;
50     }
51
52     /**
53      * Transform a report to a raw format :
54      * <code>List(Map<String,Object>)</code> list of raw captures
55      *
56      * @see captureToRaw(ExchangeStateCapture capture)
57      * @param report
58      * @return
59      */

60     protected static List JavaDoc<Map JavaDoc<String JavaDoc,Object JavaDoc>> reportToRaw(ExchangeStateReport report) {
61         
62         List JavaDoc<Map JavaDoc<String JavaDoc,Object JavaDoc>> rawCaptures = new ArrayList JavaDoc<Map JavaDoc<String JavaDoc,Object JavaDoc>>();
63         for (ExchangeStateCapture capture : report.getReportList()) {
64             rawCaptures.add(captureToRaw(report.getId(),capture));
65         }
66         return rawCaptures;
67     }
68
69     /**
70      * transform a capture to a raw Map :
71      * "id" = <code>String</code> exchangeId <br>
72      * "time" = <code>long</code> capture.time <br>
73      * "component" = <code>String</code> capture.component<br>
74      * "role" = <code>String</code> capture.role<br>
75      * "type" = <code>String</code> capture.messageType <br>
76      * "status" = <code>String</code> capture.status <br>
77      *
78      * @param capture
79      * @return
80      */

81     protected static Map JavaDoc<String JavaDoc,Object JavaDoc> captureToRaw(String JavaDoc exchangeId, ExchangeStateCapture capture) {
82         
83         Map JavaDoc<String JavaDoc,Object JavaDoc> rawCapture = new HashMap JavaDoc<String JavaDoc,Object JavaDoc>();
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     /**
95      * Convert a Role to a string representation
96      * @param role
97      * @return "consumer" or "provider
98      */

99     protected static String JavaDoc roleToRaw(Role role){
100         return (Role.CONSUMER.equals(role))?"consumer":"provider";
101     }
102
103     /**
104      * Convert a status to a string representation
105      * @param status
106      * @return "active" or "done" or "error"
107      */

108     protected static String JavaDoc statusToRaw(ExchangeStatus status){
109         return (ExchangeStatus.DONE.equals(status))?"done":(ExchangeStatus.ACTIVE.equals(status))?"active":"error";
110     }
111 }
112
Popular Tags