KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > monitoring > ExchangeStateReport


1 /*
2  * PETALS: PETALS Services Platform
3  * Copyright (C) 2007 EBM WebSourcing
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 any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * Initial developer(s): Adrien LOUIS
21  * --------------------------------------------------------------------------
22  * $Id:
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.petals.monitoring;
27
28 import java.util.ArrayList JavaDoc;
29 import java.util.List JavaDoc;
30
31 import javax.jbi.messaging.ExchangeStatus;
32 import javax.jbi.messaging.MessageExchange.Role;
33
34 import org.objectweb.petals.jbi.messaging.MessageExchangeImpl;
35 import org.objectweb.petals.jbi.registry.AbstractEndpoint;
36
37 /**
38  * @version $Rev: 617 $ $Date: 2006-06-19 17:28:41 +0200 (lun, 19 jun 2006) $
39  * @since Petals 1.1
40  * @author alouis
41  *
42  * This class contains all the states of a messageexchange lifecyle.
43  */

44 public class ExchangeStateReport {
45
46     private String JavaDoc id;
47     
48     private List JavaDoc<ExchangeStateCapture> reportList = new ArrayList JavaDoc<ExchangeStateCapture>();
49
50     public ExchangeStateReport(MessageExchangeImpl exchange){
51         this.id=exchange.getExchangeId();
52         
53     }
54     
55     public void reportState(MessageExchangeImpl exchange) {
56         ExchangeStateCapture state = new ExchangeStateCapture();
57         state.time = System.currentTimeMillis();
58         state.status = exchange.getStatus();
59
60         state.role = exchange.getRole();
61         
62         if(Role.CONSUMER.equals(state.role)){
63             state.component=exchange.getConsumerEndpoint().getComponentName();
64         }else{
65             state.component=((AbstractEndpoint)exchange.getEndpoint()).getComponentName();
66         }
67         // set the message type. Set to null if no message found
68
if (ExchangeStatus.ACTIVE.equals(state.status)) {
69             // Assume there is only one message in the exchange.
70
if(exchange.getMessages() != null && exchange.getMessages().size()>0){
71                 state.messageType = exchange.getMessages().keySet().iterator()
72                 .next();
73             }
74             // check if the message is a fault
75
if (state.messageType == null && exchange.getFault() != null) {
76                 state.messageType = "fault";
77             }
78         }
79         reportList.add(state);
80     }
81
82     public String JavaDoc getId() {
83         return id;
84     }
85
86     public List JavaDoc<ExchangeStateCapture> getReportList() {
87         return reportList;
88     }
89 }
90
Popular Tags