001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.transport.tcp.server.glassfish;
038:
039: import com.sun.appserv.server.LifecycleEvent;
040: import com.sun.appserv.server.LifecycleListener;
041: import com.sun.appserv.server.ServerLifecycleException;
042: import com.sun.istack.NotNull;
043: import com.sun.xml.ws.transport.tcp.grizzly.GrizzlyTCPConnector;
044: import com.sun.xml.ws.transport.tcp.server.*;
045: import com.sun.xml.ws.transport.tcp.resources.MessagesMessages;
046: import java.util.List;
047: import java.util.Properties;
048: import java.util.logging.Level;
049: import java.util.logging.Logger;
050:
051: /**
052: * GlassFish lifecycle module, which works as SOAP/TCP endpoints registry.
053: *
054: * @author Alexey Stashok
055: */
056:
057: public final class WSTCPLifeCycleModule implements LifecycleListener {
058: private static WSTCPLifeCycleModule instance;
059:
060: private static final Logger logger = Logger
061: .getLogger(com.sun.xml.ws.transport.tcp.util.TCPConstants.LoggingDomain
062: + ".server");
063:
064: private WSTCPConnector connector;
065: private WSTCPDelegate delegate;
066: private Properties properties;
067:
068: /**
069: * Method returns initialized WSTCPLifeCycleModule instance
070: * @throws IllegalStateException if instance was not initialized
071: */
072: public static @NotNull
073: WSTCPLifeCycleModule getInstance() {
074: if (instance == null) {
075: throw new IllegalStateException(MessagesMessages
076: .WSTCP_0007_TRANSPORT_MODULE_NOT_INITIALIZED());
077: }
078:
079: return instance;
080: }
081:
082: public void handleEvent(@NotNull
083: final LifecycleEvent lifecycleEvent)
084: throws ServerLifecycleException {
085: final int eventType = lifecycleEvent.getEventType();
086: if (eventType == LifecycleEvent.INIT_EVENT) {
087: instance = this ;
088: logger.log(Level.FINE, "WSTCPLifeCycleModule.INIT_EVENT");
089: properties = (Properties) lifecycleEvent.getData();
090: } else if (eventType == LifecycleEvent.STARTUP_EVENT) {
091: logger
092: .log(Level.FINE,
093: "WSTCPLifeCycleModule.STARTUP_EVENT");
094: delegate = new WSTCPDelegate();
095: } else if (eventType == LifecycleEvent.READY_EVENT) {
096: logger.log(Level.FINE, "WSTCPLifeCycleModule.READY_EVENT");
097: try {
098: delegate.setCustomWSRegistry(WSTCPAdapterRegistryImpl
099: .getInstance());
100: connector = new GrizzlyTCPConnector(delegate,
101: properties);
102: connector.listen();
103:
104: } catch (Exception e) {
105: logger.log(Level.SEVERE, e.getMessage(), e);
106: }
107: } else if (eventType == LifecycleEvent.SHUTDOWN_EVENT) {
108: logger.log(Level.FINE,
109: "WSTCPLifeCycleModule.SHUTDOWN_EVENT");
110: instance = null;
111:
112: if (delegate != null) {
113: delegate.destroy();
114: }
115:
116: if (connector != null) {
117: connector.close();
118: }
119:
120: }
121: }
122:
123: public void register(@NotNull
124: final String contextPath, @NotNull
125: final List<TCPAdapter> adapters) {
126: delegate.registerAdapters(contextPath, adapters);
127: }
128:
129: public void free(@NotNull
130: final String contextPath, @NotNull
131: final List<TCPAdapter> adapters) {
132: delegate.freeAdapters(contextPath, adapters);
133: }
134: }
|