KickJava   Java API By Example, From Geeks To Geeks.

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


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.Collection JavaDoc;
26 import com.sun.enterprise.admin.wsmgmt.config.spi.Constants;
27 import com.sun.enterprise.admin.wsmgmt.config.spi.ConfigFactory;
28 import com.sun.enterprise.admin.wsmgmt.config.spi.ConfigProvider;
29 import com.sun.enterprise.admin.wsmgmt.config.spi.WebServiceConfig;
30 import com.sun.enterprise.admin.wsmgmt.pool.spi.Pool;
31 import com.sun.enterprise.admin.wsmgmt.pool.impl.BoundedPool;
32 import com.sun.enterprise.admin.wsmgmt.filter.spi.Filter;
33 import com.sun.enterprise.admin.wsmgmt.filter.spi.FilterRegistry;
34 import com.sun.appserv.management.ext.wsmgmt.MessageTrace;
35
36 import java.util.logging.Logger JavaDoc;
37 import java.util.logging.Level JavaDoc;
38 import com.sun.logging.LogDomains;
39 import com.sun.enterprise.util.i18n.StringManager;
40
41 /**
42  * Keeps track of SOAP messages per endpoint.
43  */

44 class EndpointHandler {
45
46     /**
47      * Constructor.
48      *
49      * @param endpoint name of the endpoint
50      */

51     EndpointHandler(WebServiceConfig wsc, String JavaDoc appId) {
52
53         _applicationId = appId;
54         _endpointId = wsc.getName();
55         String JavaDoc mLevel = wsc.getMonitoringLevel();
56
57         // SOAP message visualization is only enabled for level HIGH
58
if (Constants.HIGH.equals(mLevel)) {
59             _pool = new BoundedPool(wsc.getName(), wsc.getMaxHistorySize());
60             registerFilter();
61         }
62     }
63
64     /**
65      * Constructor.
66      *
67      * @param endpoint name of the endpoint
68      * @param size max size of the pool
69      */

70     EndpointHandler(String JavaDoc endpoint, int size, String JavaDoc appId) {
71         _applicationId = appId;
72         _endpointId = endpoint;
73         _pool = new BoundedPool(endpoint, size);
74
75         registerFilter();
76     }
77
78     /**
79      * Registers a filter with the filter manager for this endpoint.
80      */

81     private void registerFilter() {
82
83         // msg filter
84
_filter = new MessageFilter(_applicationId, _endpointId, this);
85         FilterRegistry fr = FilterRegistry.getInstance();
86         String JavaDoc endpoint = getFQEndpointName();
87
88         // registers the filter
89
fr.registerFilter(Filter.PROCESS_REQUEST, endpoint, _filter);
90         fr.registerFilter(Filter.PROCESS_RESPONSE, endpoint, _filter);
91         fr.registerFilter(Filter.POST_PROCESS_RESPONSE, endpoint, _filter);
92     }
93
94     /**
95      * Sets the number of messages stored in memory for this endpoint.
96      * This method is called to dynamically reconfigure the size.
97      *
98      * @param size number of message stored in memory
99      */

100     void setMessageHistorySize(int size) {
101         if (_pool != null) {
102             _pool.resize(size);
103             _logger.fine("Set message history size to " + size
104                 + " for " + getEndpointName());
105         }
106     }
107
108     /**
109      * Disables monitoring for the endpoint and deregisters the filters.
110      */

111     void destroy() {
112         if (_pool != null) {
113             _pool.clear();
114             _pool = null;
115         }
116
117         if (_filter != null) {
118             FilterRegistry fr = FilterRegistry.getInstance();
119             String JavaDoc endpoint = getFQEndpointName();
120
121             // unregister filters
122
fr.unregisterFilter(Filter.PROCESS_REQUEST, endpoint, _filter);
123             fr.unregisterFilter(Filter.PROCESS_RESPONSE, endpoint, _filter);
124             fr.unregisterFilter(Filter.POST_PROCESS_RESPONSE, endpoint, _filter);
125             _filter = null;
126         }
127         _logger.finer("Message trace handler destroyed for "
128             + getEndpointName());
129     }
130
131     /**
132      * Returns all messages for this endpoint.
133      *
134      * @return messages associated for this endpoint
135      */

136     Collection JavaDoc getMessages() {
137         return _pool.values();
138     }
139
140     /**
141      * Adds a message trace to the pool.
142      *
143      * @param msgTrace a message trace object after the invocation
144      */

145     void addMessage(MessageTrace msgTrace) {
146         _pool.put(msgTrace.getMessageID(), msgTrace);
147     }
148
149     /**
150      * Returns the name of the endpoint.
151      *
152      * @return name of the endpoint
153      */

154     String JavaDoc getEndpointName() {
155         return _endpointId;
156     }
157
158     /**
159      * Returns the fully qualified name of this endpoint.
160      *
161      * @return fully qualified name of this endpoint
162      */

163     String JavaDoc getFQEndpointName() {
164         return _applicationId + DELIM + _endpointId;
165     }
166
167     // ---- VARIABLES - PRIVATE ---------------------------------------
168
private MessageFilter _filter = null;
169     private Pool _pool = null;
170     private String JavaDoc _endpointId = null;
171     private String JavaDoc _applicationId = null;
172     private static final String JavaDoc DELIM = "#";
173     private static final Logger JavaDoc _logger =
174         Logger.getLogger(LogDomains.ADMIN_LOGGER);
175     private static final StringManager _stringMgr =
176         StringManager.getManager(EndpointHandler.class);
177 }
178
Popular Tags