KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > wsmgmt > msg > ApplicationMediator


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.admin.wsmgmt.msg;
24
25 import java.util.Map JavaDoc;
26 import java.util.Collection JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import java.util.Hashtable JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import com.sun.enterprise.admin.wsmgmt.config.spi.Constants;
31 import com.sun.enterprise.admin.wsmgmt.config.spi.ConfigFactory;
32 import com.sun.enterprise.admin.wsmgmt.config.spi.ConfigProvider;
33 import com.sun.enterprise.admin.wsmgmt.config.spi.WebServiceConfig;
34
35 import java.util.logging.Logger JavaDoc;
36 import java.util.logging.Level JavaDoc;
37 import com.sun.logging.LogDomains;
38 import com.sun.enterprise.util.i18n.StringManager;
39
40 /**
41  * Keeps track of SOAP messages per application or stand alone module.
42  */

43 class ApplicationMediator {
44
45     /**
46      * Constructor.
47      *
48      * @param id name of the application
49      */

50     ApplicationMediator(String JavaDoc id) throws MessageTraceException {
51
52         _applicationId = id;
53         _endpoints = new Hashtable JavaDoc();
54
55         // initializes the endpoint handler
56
try {
57             ConfigFactory cf = ConfigFactory.getConfigFactory();
58             ConfigProvider cp = cf.getConfigProvider();
59             WebServiceConfig[] wsc = cp.getWebserviceConfigs(id);
60
61             for (int i=0; i<wsc.length; i++) {
62                 String JavaDoc mLevel = wsc[i].getMonitoringLevel();
63
64                 // SOAP message visualization is only enabled for level HIGH
65
if (Constants.HIGH.equals(mLevel)) {
66                     EndpointHandler eph = new EndpointHandler(wsc[i], id);
67                     _endpoints.put(eph.getEndpointName(), eph);
68                 }
69             }
70         } catch (Exception JavaDoc e) {
71             String JavaDoc msg=_stringMgr.getString("ApplicationMediator_ConfigEx",id);
72             throw new MessageTraceException(msg, e);
73         }
74     }
75
76     /**
77      * Sets the number of messages stored in memory for this application.
78      * This method is called to dynamically reconfigure the size.
79      *
80      * @param wsEndpoint name of the webservice endpoint
81      * @param size number of message stored in memory
82      */

83     void setMessageHistorySize(String JavaDoc wsEndpoint, int size) {
84         EndpointHandler eph = (EndpointHandler) _endpoints.get(wsEndpoint);
85         if (eph != null) {
86             eph.setMessageHistorySize(size);
87         }
88     }
89
90     /**
91      * Disables monitoring for the endpoint.
92      *
93      * @param wsEndpoint name of the webservice endpoint
94      */

95     void disable(String JavaDoc wsEndpoint) {
96         EndpointHandler eph = (EndpointHandler) _endpoints.remove(wsEndpoint);
97         if (eph != null) {
98             eph.destroy();
99         }
100     }
101
102     /**
103      * Enables monitoring for the endpoint.
104      *
105      * @param wsEndpoint name of the webservice endpoint
106      * @param size max size of the messages in history
107      */

108     void enable(String JavaDoc wsEndpoint, int size) {
109         EndpointHandler eph =
110             new EndpointHandler(wsEndpoint, size, _applicationId);
111         _endpoints.put(wsEndpoint, eph);
112     }
113
114     /**
115      * Returns true if there are no endpoints in this application mediator.
116      *
117      * @return true if mediator is empty
118      */

119     boolean isEmpty() {
120         Collection JavaDoc c = _endpoints.values();
121         return c.isEmpty();
122     }
123
124     /**
125      * Returns messages for the given endpoint.
126      *
127      * @param wsEndpoint web service endpoint
128      * @return messages for the given endpoint
129      */

130     Collection JavaDoc getMessages(String JavaDoc wsEndpoint) {
131         EndpointHandler eph = (EndpointHandler) _endpoints.get(wsEndpoint);
132         if (eph != null) {
133             return eph.getMessages();
134         }
135         return null;
136     }
137
138     /**
139      * Returns all messages for this application.
140      *
141      * @return messages associated for this application
142      */

143     Collection JavaDoc getMessages() {
144
145         Collection JavaDoc c = new ArrayList JavaDoc();
146         Collection JavaDoc endpoints = _endpoints.values();
147         for (Iterator JavaDoc iter=endpoints.iterator(); iter.hasNext();) {
148             EndpointHandler eph = (EndpointHandler) iter.next();
149             if (eph != null) {
150                 c.addAll( eph.getMessages() );
151             }
152         }
153
154         return c;
155     }
156
157     /**
158      * Stops message visualization for this application.
159      */

160     void destroy() {
161         Collection JavaDoc endpoints = _endpoints.values();
162         for (Iterator JavaDoc iter=endpoints.iterator(); iter.hasNext();) {
163             EndpointHandler eph = (EndpointHandler) iter.next();
164             if (eph != null) {
165                 eph.destroy();
166             }
167         }
168         _endpoints.clear();
169         _endpoints = null;
170         _logger.finer("Message trace mediator destroyed for " + _applicationId);
171     }
172
173     // ---- VARIABLES - PRIVATE ---------------------------------------
174
private Map JavaDoc _endpoints = null;
175     private String JavaDoc _applicationId = null;
176     private static final Logger JavaDoc _logger =
177         Logger.getLogger(LogDomains.ADMIN_LOGGER);
178     private static final StringManager _stringMgr =
179         StringManager.getManager(ApplicationMediator.class);
180
181 }
182
Popular Tags