Tue, 09 Apr 2013 14:51:13 +0100
8010393: Update JAX-WS RI to 2.2.9-b12941
Reviewed-by: alanb, erikj
Contributed-by: miroslav.kos@oracle.com, martin.grebac@oracle.com
ohair@286 | 1 | /* |
alanb@368 | 2 | * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
ohair@286 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohair@286 | 4 | * |
ohair@286 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohair@286 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@286 | 7 | * published by the Free Software Foundation. Oracle designates this |
ohair@286 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@286 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
ohair@286 | 10 | * |
ohair@286 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohair@286 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohair@286 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohair@286 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
ohair@286 | 15 | * accompanied this code). |
ohair@286 | 16 | * |
ohair@286 | 17 | * You should have received a copy of the GNU General Public License version |
ohair@286 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohair@286 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohair@286 | 20 | * |
ohair@286 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@286 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@286 | 23 | * questions. |
ohair@286 | 24 | */ |
ohair@286 | 25 | |
ohair@286 | 26 | package com.sun.xml.internal.ws.api.server; |
ohair@286 | 27 | |
alanb@368 | 28 | import com.sun.xml.internal.ws.server.WSEndpointImpl; |
ohair@286 | 29 | import java.util.HashSet; |
ohair@286 | 30 | import java.util.Set; |
alanb@368 | 31 | import com.sun.org.glassfish.external.amx.AMXGlassfish; |
alanb@368 | 32 | import com.sun.org.glassfish.external.amx.MBeanListener; |
alanb@368 | 33 | import com.sun.org.glassfish.gmbal.ManagedObjectManager; |
ohair@286 | 34 | |
ohair@286 | 35 | /** |
ohair@286 | 36 | * The lazy provider is intended to defer Gmbal API calls until there is a JMX connection. The provider is scope |
ohair@286 | 37 | * (environment) aware and behaves accordingly to actual scope. The default behaviour does not defers Gmbal API calls. |
ohair@286 | 38 | * |
ohair@286 | 39 | * There are two kind of method allowing registration of an object as a listener. One is for {@code WSEndpointImpl} |
ohair@286 | 40 | * instances (implementing {@code WSEndpointScopeChangeListener}) and the other is for arbitrary objects |
ohair@286 | 41 | * (implementing {@code DefaultScopeChangeListener}) that want to be notified about scope changes. The distinction is made |
ohair@286 | 42 | * because of the fact that endpoints should be registered first and other objects (e.g. dependants on endpoints) must |
ohair@286 | 43 | * be registered after all the endpoints are processed so no inconsistency is present. |
ohair@286 | 44 | * |
ohair@286 | 45 | * Glassfish: |
ohair@286 | 46 | * {@link WebServicesContainer} is one of two classes for which a {@link ManagedObjectManager} instance (see Gmbal API) |
ohair@286 | 47 | * is created when a webservice application is deployed into the Glassfish. For the purpose of postponing Gmbal API calls |
alanb@368 | 48 | * the {@code WebServicesContainer} extends {@link MBeanListener.CallbackImpl} so it can register itself as a listener of |
ohair@286 | 49 | * {@link AMXGlassfish} and receive a notification about a connection of a JMX client to the Glassfish server (see |
ohair@286 | 50 | * {@code WebServicesContainer#postConstruct} for registration details). The moment the JMX client is connected a notification |
ohair@286 | 51 | * is sent to the listeners of {@code AMXGlassfish}. When this event is received by {@code WebServiceContainer} (see the |
ohair@286 | 52 | * callback method {@code mbeanRegistered}) a {@code ManagedObjectManager} instance is created and no further deferring |
ohair@286 | 53 | * of Gmbal API calls is needed. |
ohair@286 | 54 | * |
ohair@286 | 55 | * Metro/JAX-WS: |
ohair@286 | 56 | * The situation in Metro/JAX-WS is slightly different from the one described above. Metro/JAX-WS can be used as standalone |
ohair@286 | 57 | * libraries (outside of Glassfish) so no notification from the Glassfish server can be expected in this case. This leads |
ohair@286 | 58 | * to a situation when Metro/JAX-WS has to be aware of context in which it is used and acts appropriately. There are 3 |
ohair@286 | 59 | * scopes an application using Metro/JAX-WS can be in: {@code STANDALONE}, {@code GLASSFISH_NO_JMX}, {@code GLASSFISH_JMX} |
alanb@368 | 60 | * ({@link LazyMOMProvider#scope}). The default scope is {@code STANDALONE} and all Gmbal API calls are invoked as they |
ohair@286 | 61 | * are requested. The other two scopes are applied only when an application is deployed into a Glassfish server. The |
ohair@286 | 62 | * {@code GLASSFISH_NO_JMX} is set at the moment the application is deployed (see below) and its purpose is to defer Gmbal |
ohair@286 | 63 | * API calls for as long as possible. For some classes e.g. {@code ManagedObjectManager} proxy classes were introduced to |
ohair@286 | 64 | * avoid the necessity of creating the real Gmbal objects but if a method is invoked on these proxies the creation of real |
ohair@286 | 65 | * Gmbal objects is forced even in this scope. The {@code GLASSFISH_JMX} scope is set when a JMX client is connected to |
ohair@286 | 66 | * the Glassfish server and it processes Gmbal API calls without deferring (as if the application was in the |
ohair@286 | 67 | * {@code STANDALONE} scope). The entry point for postponing the Gmbal API calls / creating Gmbal objects in Metro/JAX-WS |
ohair@286 | 68 | * is {@link LazyMOMProvider}. This class is capable of receiving notifications from the Glassfish server |
ohair@286 | 69 | * ({@code LazyMOMProvider.initMOMForScope}) about the scope change and it also spread this information to its listeners. |
ohair@286 | 70 | * The listeners of {@code LazyMOMProvider} are of two kinds: {@link LazyMOMProvider.WSEndpointScopeChangeListener} and |
ohair@286 | 71 | * {@link LazyMOMProvider.DefaultScopeChangeListener}. Extensions of {@link WSEndpoint} (e.g. {@link WSEndpointImpl}) |
ohair@286 | 72 | * should implement the {@code LazyMOMProvider.WSEndpointScopeChangeListener} and register themselves as endpoint listeners |
ohair@286 | 73 | * of {@code LazyMOMProvider}. Other classes should implement the latter mentioned interface and register themselves as |
ohair@286 | 74 | * a non-endpoint listener. The differences between these two kind of listeners are described in {@code LazyMOMProvider} |
ohair@286 | 75 | * class comment. An implementation of {@code LazyMOMProvider.DefaultScopeChangeListener} is provided in Metro |
ohair@286 | 76 | * ({@link WSEndpointCollectionBasedMOMListener}). As mentioned above this listener register itself as a non-endpoint |
ohair@286 | 77 | * listener of {@code LazyMOMProvider} ({@code WSEndpointCollectionBasedMOMListener.init}). An instance of this class is |
ohair@286 | 78 | * used in these factories: {@link SessionManager}, {@link NonceManager} and {@link SequenceManagerFactory}. |
ohair@286 | 79 | * {@code SessionManager}, {@code NonceManager}, {@code PersistentSequenceManager} and {@code InVmSequenceManager} also |
ohair@286 | 80 | * (indirectly) implement {@link MOMRegistrationAware} for providing information whether a manager is registered at |
ohair@286 | 81 | * {@code ManagedObjectManager} or not. Registration of a manager at {@code ManagedObjectManager} can be processed directly |
ohair@286 | 82 | * (if {@code WSEndpointCollectionBasedMOMListener.canRegisterAtMOM} returns {@code true}) via |
ohair@286 | 83 | * {@code WSEndpointCollectionBasedMOMListener.registerAtMOM} or is deferred by putting the manager into |
ohair@286 | 84 | * {@code WSEndpointCollectionBasedMOMListener.registrationAwareMap}. Managers stored in for deferred registration are |
ohair@286 | 85 | * processed at the moment the {@code LazyMOMProvider} notifies the {@code WSEndpointCollectionBasedMOMListener} about |
ohair@286 | 86 | * the scope change. |
ohair@286 | 87 | * The mentioned postponing of Gmbal API calls applies only to the server side of the webservice application. |
ohair@286 | 88 | */ |
ohair@286 | 89 | public enum LazyMOMProvider { |
ohair@286 | 90 | |
ohair@286 | 91 | INSTANCE; |
ohair@286 | 92 | |
ohair@286 | 93 | /** |
ohair@286 | 94 | * Possible scopes (environments) in which the provider (and object associated with it) could be in. |
ohair@286 | 95 | * Default scope is STANDALONE - applied during initialization of classes. For now, only possible scope change for a |
ohair@286 | 96 | * object can be in this direction: STANDALONE -> GLASSFISH_NO_JMX -> GLASSFISH_JMX. |
ohair@286 | 97 | */ |
ohair@286 | 98 | public static enum Scope { |
ohair@286 | 99 | |
ohair@286 | 100 | //** Default scope where lazy flag is not applied and all Gmbal API calls are processed immediately. */ |
ohair@286 | 101 | STANDALONE, |
ohair@286 | 102 | |
ohair@286 | 103 | /** In this scope almost all Gmbal API call are deferred until a JMX connection to a Glassfish server is created */ |
ohair@286 | 104 | GLASSFISH_NO_JMX, |
ohair@286 | 105 | |
ohair@286 | 106 | /** Same as STANDALONE. Gmbal API calls are processed immediately. */ |
ohair@286 | 107 | GLASSFISH_JMX |
ohair@286 | 108 | |
ohair@286 | 109 | } |
ohair@286 | 110 | |
ohair@286 | 111 | /** |
ohair@286 | 112 | * Interface for all object that want to be notified about scope change, introducing required methods. |
ohair@286 | 113 | */ |
ohair@286 | 114 | public static interface ScopeChangeListener { |
ohair@286 | 115 | |
ohair@286 | 116 | void scopeChanged(Scope scope); |
ohair@286 | 117 | |
ohair@286 | 118 | } |
ohair@286 | 119 | |
ohair@286 | 120 | /** |
ohair@286 | 121 | * Default interface for all object that want to be notified about scope change. This interface should not be |
ohair@286 | 122 | * implemented directly. |
ohair@286 | 123 | */ |
ohair@286 | 124 | public static interface DefaultScopeChangeListener extends ScopeChangeListener { |
ohair@286 | 125 | } |
ohair@286 | 126 | |
ohair@286 | 127 | /** |
ohair@286 | 128 | * Interface used for distinguishing between a registration of a WSEndpointImpl rather than of other classes. |
ohair@286 | 129 | * Webservice Endpoints should get a notification about scope change sooner than the rest of the registered listeners |
ohair@286 | 130 | * (there is a possibility that other listeners are dependant on Webservice Endpoints). |
ohair@286 | 131 | */ |
ohair@286 | 132 | public static interface WSEndpointScopeChangeListener extends ScopeChangeListener { |
ohair@286 | 133 | } |
ohair@286 | 134 | |
ohair@286 | 135 | private final Set<WSEndpointScopeChangeListener> endpointsWaitingForMOM = new HashSet<WSEndpointScopeChangeListener>(); |
ohair@286 | 136 | private final Set<DefaultScopeChangeListener> listeners = new HashSet<DefaultScopeChangeListener>(); |
ohair@286 | 137 | |
ohair@286 | 138 | private volatile Scope scope = Scope.STANDALONE; |
ohair@286 | 139 | |
ohair@286 | 140 | /** |
ohair@286 | 141 | * Initializes this provider with a given scope. If the given scope is different than the one this provider is |
ohair@286 | 142 | * currently in and the transition between scopes is valid then a event is fired to all registered listeners. |
ohair@286 | 143 | * |
ohair@286 | 144 | * @param scope a scope to initialize this provider with |
ohair@286 | 145 | */ |
ohair@286 | 146 | public void initMOMForScope(LazyMOMProvider.Scope scope) { |
ohair@286 | 147 | // cannot go backwards between scopes, for possible scope changes see #Scope |
ohair@286 | 148 | if ((this.scope == Scope.GLASSFISH_JMX) |
ohair@286 | 149 | || (scope == Scope.STANDALONE && (this.scope == Scope.GLASSFISH_JMX || this.scope == Scope.GLASSFISH_NO_JMX)) |
ohair@286 | 150 | || this.scope == scope) { |
ohair@286 | 151 | return; |
ohair@286 | 152 | } |
ohair@286 | 153 | |
ohair@286 | 154 | this.scope = scope; |
ohair@286 | 155 | |
ohair@286 | 156 | fireScopeChanged(); |
ohair@286 | 157 | } |
ohair@286 | 158 | |
ohair@286 | 159 | /** |
ohair@286 | 160 | * Notifies the registered listeners about the scope change. |
ohair@286 | 161 | */ |
ohair@286 | 162 | private void fireScopeChanged() { |
ohair@286 | 163 | for (ScopeChangeListener wsEndpoint : endpointsWaitingForMOM) { |
ohair@286 | 164 | wsEndpoint.scopeChanged(this.scope); |
ohair@286 | 165 | } |
ohair@286 | 166 | |
ohair@286 | 167 | for (ScopeChangeListener listener : listeners) { |
ohair@286 | 168 | listener.scopeChanged(this.scope); |
ohair@286 | 169 | } |
ohair@286 | 170 | } |
ohair@286 | 171 | |
ohair@286 | 172 | /** |
ohair@286 | 173 | * Registers the given object as a listener. |
ohair@286 | 174 | * |
ohair@286 | 175 | * @param listener a listener to be registered |
ohair@286 | 176 | */ |
ohair@286 | 177 | public void registerListener(DefaultScopeChangeListener listener) { |
ohair@286 | 178 | listeners.add(listener); |
ohair@286 | 179 | |
ohair@286 | 180 | if (!isProviderInDefaultScope()) { |
ohair@286 | 181 | listener.scopeChanged(this.scope); |
ohair@286 | 182 | } |
ohair@286 | 183 | } |
ohair@286 | 184 | |
ohair@286 | 185 | /** |
ohair@286 | 186 | * Returns {@code true} if this provider is in the default scope. |
ohair@286 | 187 | * |
alanb@368 | 188 | * @return {@code true} if this provider is in the default scope, |
alanb@368 | 189 | * {@code false} otherwise |
ohair@286 | 190 | */ |
ohair@286 | 191 | private boolean isProviderInDefaultScope() { |
ohair@286 | 192 | return this.scope == Scope.STANDALONE; |
ohair@286 | 193 | } |
ohair@286 | 194 | |
ohair@286 | 195 | public Scope getScope() { |
ohair@286 | 196 | return scope; |
ohair@286 | 197 | } |
ohair@286 | 198 | |
ohair@286 | 199 | /** |
ohair@286 | 200 | * Registers a Webservice Endpoint as a listener. |
ohair@286 | 201 | * Webservice Endpoints should rather register through this method than through LazyMOMProvider#registerListener |
ohair@286 | 202 | * because generally they need to be notified sooner than arbitrary listener (i.e. object that is dependant on |
ohair@286 | 203 | * Webservice Endpoint) |
ohair@286 | 204 | * |
ohair@286 | 205 | * @param wsEndpoint a Webservice Endpoint to be registered |
ohair@286 | 206 | */ |
ohair@286 | 207 | public void registerEndpoint(WSEndpointScopeChangeListener wsEndpoint) { |
ohair@286 | 208 | endpointsWaitingForMOM.add(wsEndpoint); |
ohair@286 | 209 | |
ohair@286 | 210 | if (!isProviderInDefaultScope()) { |
ohair@286 | 211 | wsEndpoint.scopeChanged(this.scope); |
ohair@286 | 212 | } |
ohair@286 | 213 | } |
ohair@286 | 214 | |
ohair@286 | 215 | /** |
ohair@286 | 216 | * Unregisters a Webservice Endpoint from the list of listeners. |
ohair@286 | 217 | * |
ohair@286 | 218 | * @param wsEndpoint a Webservice Endpoint to be unregistered |
ohair@286 | 219 | */ |
ohair@286 | 220 | public void unregisterEndpoint(WSEndpointScopeChangeListener wsEndpoint) { |
ohair@286 | 221 | endpointsWaitingForMOM.remove(wsEndpoint); |
ohair@286 | 222 | } |
ohair@286 | 223 | |
ohair@286 | 224 | } |