KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
27 import java.util.Hashtable JavaDoc;
28 import java.util.Collection JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import com.sun.enterprise.admin.wsmgmt.config.spi.ConfigFactory;
32 import com.sun.enterprise.admin.wsmgmt.config.spi.ConfigProvider;
33 import com.sun.appserv.management.ext.wsmgmt.MessageTrace;
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  * Backend facade for the SOAP message visualization.
42  */

43 public class MessageTraceMgr {
44
45     /**
46      * Returns the singleton instance of this class.
47      *
48      * @return singleton instance of this class
49      */

50     public static MessageTraceMgr getInstance() {
51         if (_instance == null) {
52             _instance = new MessageTraceMgr();
53         }
54
55         return _instance;
56     }
57
58     /**
59      * Private constructor.
60      */

61     private MessageTraceMgr() {
62         _applications = new Hashtable JavaDoc();
63
64     }
65
66     /**
67      * Initializes the message visualization service.
68      */

69     public void init() {
70         try {
71             ConfigFactory cf = ConfigFactory.getConfigFactory();
72             ConfigProvider cp = cf.getConfigProvider();
73             List JavaDoc list = cp.getManagedWebserviceApplicationIds();
74             for (Iterator JavaDoc iter=list.iterator(); iter.hasNext();) {
75                 String JavaDoc appId = (String JavaDoc) iter.next();
76                 try {
77                     ApplicationMediator am = new ApplicationMediator(appId);
78                     _applications.put(appId, am);
79                 } catch (MessageTraceException me) {
80                     String JavaDoc msg="Initialization error for application: " + appId;
81                     _logger.log(Level.FINE, msg, me);
82                 }
83             }
84         } catch (Exception JavaDoc e) {
85             String JavaDoc msg="Configuration initialization error.";
86             _logger.log(Level.FINE, msg, e);
87         }
88     }
89
90     /**
91      * Disables message trace for the given web service endpoint. This
92      * method is called to dynamically reconfigure the size.
93      *
94      * @param appId name of the application
95      * @param endpoint partially qualified endpoint name
96      *
97      * @throws MessageTraceException if application id is invalid
98      */

99     public void disable(String JavaDoc appId, String JavaDoc endpoint)
100             throws MessageTraceException {
101
102         ApplicationMediator am = (ApplicationMediator) _applications.get(appId);
103         if (am != null) {
104             am.disable(endpoint);
105             if (am.isEmpty()) {
106                 _applications.remove(appId);
107             }
108         } else {
109             String JavaDoc msg = _stringMgr.getString("MessageTraceMgr_InvalidAppEx",
110                                     appId, endpoint);
111             throw new MessageTraceException(msg);
112         }
113     }
114
115     /**
116      * Enables message visualization for the given webservice endpoint.
117      *
118      * @param appId name of the application
119      * @param endpoint partially qualified endpoint name
120      * @param size max size of messages in history
121      *
122      * @throws MessageTraceException if a configuration initialization exception
123      */

124     public void enable(String JavaDoc appId, String JavaDoc endpoint, int size)
125             throws MessageTraceException {
126
127         ApplicationMediator am = (ApplicationMediator) _applications.get(appId);
128         if (am != null) {
129             am.enable(endpoint, size);
130         } else {
131             am = new ApplicationMediator(appId);
132             am.enable(endpoint, size);
133             _applications.put(appId, am);
134         }
135     }
136
137     /**
138      * Sets the number of messages stored in memory. This method is
139      * called to dynamically reconfigure the size.
140      *
141      * @param appId name of the application
142      * @param endpoint partially qualified endpoint name
143      * @param size number of message stored in memory
144      *
145      * @throws MessageTraceException if an invalid application id
146      */

147     public void setMessageHistorySize(String JavaDoc appId, String JavaDoc endpoint, int size)
148             throws MessageTraceException {
149
150         ApplicationMediator am = (ApplicationMediator) _applications.get(appId);
151         if (am != null) {
152             am.setMessageHistorySize(endpoint, size);
153         } else {
154             String JavaDoc msg = _stringMgr.getString("MessageTraceMgr_InvalidAppEx",
155                                     appId, endpoint);
156             throw new MessageTraceException(msg);
157         }
158     }
159
160     /**
161      * Shuts down message visualization.
162      */

163     public void stop() {
164         Collection JavaDoc mediators = _applications.values();
165         for (Iterator JavaDoc itr=mediators.iterator(); itr.hasNext();) {
166             ApplicationMediator am = (ApplicationMediator) itr.next();
167             am.destroy();
168         }
169         _applications.clear();
170     }
171
172     /**
173      * Returns the available messages.
174      *
175      * @return array of message trace objects currently available
176      */

177     public MessageTrace[] getMessages() {
178         Collection JavaDoc c = new ArrayList JavaDoc();
179
180         Collection JavaDoc mediators = _applications.values();
181         for (Iterator JavaDoc itr=mediators.iterator(); itr.hasNext();) {
182             ApplicationMediator am = (ApplicationMediator) itr.next();
183             c.addAll( am.getMessages() );
184         }
185
186         MessageTrace[] trace = new MessageTrace[c.size()];
187         return ((MessageTrace[]) c.toArray(trace));
188     }
189
190     /**
191      * Returns messages for a web service endpoint.
192      *
193      * @param appId name of the application
194      * @param endpoint partially qualified endpoint name
195      *
196      * @return messages for the given endpoint
197      */

198     public MessageTrace[] getMessages(String JavaDoc appId, String JavaDoc endpoint) {
199         Collection JavaDoc c = null;
200         ApplicationMediator am = (ApplicationMediator) _applications.get(appId);
201         if (am != null) {
202             c = am.getMessages(endpoint);
203         }
204         MessageTrace[] trace = null;
205         if ( c != null) {
206             trace = new MessageTrace[c.size()];
207             return ((MessageTrace[]) c.toArray(trace));
208         } else {
209             return null;
210         }
211     }
212
213     // ---- VARIABLES - PRIVATE ---------------------------------------
214
private Map JavaDoc _applications = null;
215     private static MessageTraceMgr _instance = null;
216     private static final Logger JavaDoc _logger =
217         Logger.getLogger(LogDomains.ADMIN_LOGGER);
218     private static final StringManager _stringMgr =
219         StringManager.getManager(MessageTraceMgr.class);
220
221 }
222
Popular Tags