KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > kernel > world > cmc > GetServiceParticipationJMX


1 /*
2  * Copyright 2002 by
3  * <a HREF="http://www.coridan.com">Coridan</a>
4  * <a HREF="mailto: support@coridan.com ">support@coridan.com</a>
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is "MantaRay" (TM).
17  *
18  * The Initial Developer of the Original Code is lital kasif.
19  * Portions created by the Initial Developer are Copyright (C) 2006
20  * Coridan Inc. All Rights Reserved.
21  *
22  * Contributor(s): all the names of the contributors are added in the source
23  * code where applicable.
24  *
25  * Alternatively, the contents of this file may be used under the terms of the
26  * LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE"), in which case the
27  * provisions of LGPL are applicable instead of those above. If you wish to
28  * allow use of your version of this file only under the terms of the LGPL
29  * License and not to allow others to use your version of this file under
30  * the MPL, indicate your decision by deleting the provisions above and
31  * replace them with the notice and other provisions required by the LGPL.
32  * If you do not delete the provisions above, a recipient may use your version
33  * of this file under either the MPL or the GNU LESSER GENERAL PUBLIC LICENSE.
34  
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Lesser General Public License as published by the Free Software Foundation;
39  * either version 2.1 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
44  * License for more details.
45  *
46  * Created on Sep 22, 2004
47  *
48  */

49 package org.mr.kernel.world.cmc;
50
51 import java.util.*;
52
53 import javax.management.MBeanAttributeInfo JavaDoc;
54 import javax.management.MBeanInfo JavaDoc;
55 import javax.management.NotCompliantMBeanException JavaDoc;
56 import javax.management.StandardMBean JavaDoc;
57
58 import org.apache.commons.logging.Log;
59 import org.apache.commons.logging.LogFactory;
60 import org.mr.MantaAgent;
61 import org.mr.kernel.world.WorldModeler;
62 import org.mr.kernel.services.MantaService;
63 import org.mr.kernel.services.ServiceConsumer;
64
65 /**
66  * returns all the services the agent is producing and consuming
67  *
68  * @author lital kasif
69  */

70 public class GetServiceParticipationJMX extends StandardMBean JavaDoc implements GetServiceParticipationJMXMBean{
71     public Log log;
72
73     public GetServiceParticipationJMX()throws NotCompliantMBeanException JavaDoc{
74         super(GetServiceParticipationJMXMBean.class);
75         log=LogFactory.getLog("GetServiceParticipationJMX");
76     }
77
78     /**
79      * returns all the toStrings of all the services the agent produces.
80      * @return Set containing the toStrings of the produced services.
81      */

82     public Set getProduced(){
83         WorldModeler modeler = MantaAgent.getInstance().
84         getSingletonRepository().getWorldModeler();
85         Set setProduced = modeler.getMyProducedServices();
86         Iterator i;
87         i=setProduced.iterator();
88         Set stringsSetProduced = new HashSet();
89         while (i.hasNext()) {
90             stringsSetProduced.add(i.next().toString());
91         }
92         return stringsSetProduced;
93     }//Produced()
94

95     /**
96      * returns all the toStrings of all the services the agent consumes.
97      * @return Set containing the toStrings of the consumed services.
98      */

99     public Set getConsumed(){
100         WorldModeler modeler = MantaAgent.getInstance().
101         getSingletonRepository().getWorldModeler();
102         Set setConsumed = modeler.getMyConsumedServices();
103         Iterator i;
104         i=setConsumed.iterator();
105         Set stringsSetConsumed = new HashSet();
106         while (i.hasNext()) {
107             stringsSetConsumed.add(i.next().toString());
108         }//while
109
return stringsSetConsumed;
110     }//getConsumed
111

112     /**
113      * returns all the toStrings of all the topics the agent durably consumes.
114      * @return Set containing the toStrings of the durably consumed services.
115      */

116     public Set getDurablyConsumed(){
117         WorldModeler modeler = MantaAgent.getInstance().
118         getSingletonRepository().getWorldModeler();
119         Set setConsumed = modeler.getMyConsumedServices();
120         Iterator i;
121         i=setConsumed.iterator();
122         Set stringsSetDurablyConsumed = new HashSet();
123         while (i.hasNext()) {
124             MantaService service=(MantaService)i.next();
125             if(service.getServiceType()==MantaService.SERVICE_TYPE_TOPIC){
126                 ArrayList serviceConsumers =service.getConsumersByAgentId(MantaAgent.getInstance().getAgentName());
127                 for(int j=0; j<serviceConsumers.size(); j++){
128                     ServiceConsumer consumer=(ServiceConsumer) serviceConsumers.get(j);
129                     if(consumer.isDurable())
130                               stringsSetDurablyConsumed.add(service.toString());
131                 }
132             }
133         }//while
134
return stringsSetDurablyConsumed;
135     }
136
137     /**
138      * returns all the toStrings of all the Queues the Agent is a Coordinator of.
139      * @return Set containing the toStrings of the coordinated services.
140      */

141     public Set getCoordinated(){
142         WorldModeler modeler = MantaAgent.getInstance().
143         getSingletonRepository().getWorldModeler();
144         Set setCoordinated = modeler.getMyCoordinatedServices();
145         Iterator i;
146         i=setCoordinated.iterator();
147         Set stringSetCoordinated = new HashSet();
148         while (i.hasNext()) {
149             stringSetCoordinated.add(i.next().toString());
150         }
151         return stringSetCoordinated;
152     }
153
154     protected String JavaDoc getDescription(MBeanInfo JavaDoc i_mBeanInfo) {
155         return "returns information regarding this peer's service participation";
156     }
157
158     protected String JavaDoc getDescription(MBeanAttributeInfo JavaDoc i_mBeanAttributeInfo) {
159         if(i_mBeanAttributeInfo.getName().equals("Consumed"))
160                return "returns details about the services this layer is a consumer of";
161            if(i_mBeanAttributeInfo.getName().equals("Produced"))
162                return "returns details about the services this layer is a producer of";
163            if(i_mBeanAttributeInfo.getName().equals("Coordinated"))
164             return "returns details about the Queue services this layer is a coordinator of";
165         return "managed string";
166     }
167
168 }//GetServiceParticipationJMX
169
Popular Tags