Index: modules/http/src/main/java/com/sun/grizzly/http/embed/GrizzlyWebServer.java =================================================================== --- modules/http/src/main/java/com/sun/grizzly/http/embed/GrizzlyWebServer.java (revision 3318) +++ modules/http/src/main/java/com/sun/grizzly/http/embed/GrizzlyWebServer.java Fri Sep 18 17:06:50 CEST 2009 @@ -24,11 +24,14 @@ package com.sun.grizzly.http.embed; import com.sun.grizzly.SSLConfig; -import com.sun.grizzly.arp.DefaultAsyncHandler; import com.sun.grizzly.arp.AsyncFilter; import com.sun.grizzly.arp.AsyncHandler; +import com.sun.grizzly.arp.DefaultAsyncHandler; import com.sun.grizzly.http.Management; import com.sun.grizzly.http.SelectorThread; +import com.sun.grizzly.http.deployer.DeployException; +import com.sun.grizzly.http.deployer.Deployer; +import com.sun.grizzly.http.deployer.FromURIDeployer; import com.sun.grizzly.ssl.SSLSelectorThread; import com.sun.grizzly.tcp.Adapter; import com.sun.grizzly.tcp.http11.GrizzlyAdapter; @@ -38,14 +41,16 @@ import com.sun.grizzly.tcp.http11.GrizzlyResponse; import com.sun.grizzly.util.ClassLoaderUtil; import com.sun.grizzly.util.net.jsse.JSSEImplementation; + +import javax.management.ObjectInstance; +import javax.management.ObjectName; import java.io.IOException; +import java.net.URI; import java.util.ArrayList; import java.util.HashMap; import java.util.Map.Entry; import java.util.logging.Level; import java.util.logging.Logger; -import javax.management.ObjectInstance; -import javax.management.ObjectName; /** @@ -741,4 +746,45 @@ return adapterChains; } } + + /** + * Deploy given deployable using provided deployer. + * + * @param toDeploy Deplyable to deploy. + * @param deployer to be used for deployment. + * @param Type of object to be deployed. + * + * @return Deployment identification. + * + * @throws DeployException Deployment failed. + */ + public Integer deploy(V toDeploy, Deployer deployer) throws DeployException { + return deployer.deploy(this, toDeploy); -} + } + + /** + * Deploy from given uri using provided deployer. + * + * @param fromURI uri to deploy from. + * @param deployer to be used for deployment. + * @param Type of object to be deployed. + * + * @return Deployment identification. + * + * @throws DeployException Deployment failed. + */ + public Integer deploy(URI fromURI, FromURIDeployer deployer) throws DeployException { + return deployer.deploy(this, fromURI); + } + + /** + * Undeploy deploymentId using provided deployer. + * + * @param deploymentId Deployment identification to be undeployed. + * @param deployer to be used for undeploing. + * @param Type of object that was deployed by provided deployer. + */ + public void undeploy(Integer deploymentId, Deployer deployer) { + deployer.undeploy(this, deploymentId); + } +} Index: modules/http/src/main/java/com/sun/grizzly/http/deployer/FromURIDeployer.java =================================================================== --- modules/http/src/main/java/com/sun/grizzly/http/deployer/FromURIDeployer.java Fri Sep 18 16:53:58 CEST 2009 +++ modules/http/src/main/java/com/sun/grizzly/http/deployer/FromURIDeployer.java Fri Sep 18 16:53:58 CEST 2009 @@ -0,0 +1,60 @@ +/* + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the license at + * https://glassfish.dev.java.net/public/CDDLv1.0.html or + * glassfish/bootstrap/legal/CDDLv1.0.txt. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * Header Notice in each file and include the License file + * at glassfish/bootstrap/legal/CDDLv1.0.txt. + * If applicable, add the following below the CDDL Header, + * with the fields enclosed by brackets [] replaced by + * you own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + */ +package com.sun.grizzly.http.deployer; + +import com.sun.grizzly.http.embed.GrizzlyWebServer; + +import java.net.URI; + +/** + * Deployer abstraction supporting deployment from {@link URI} . + * + * @author Hubert Iwaniuk + * @param Type of object deployed by this deployer. + * @since Sep 18, 2009 + */ +public abstract class FromURIDeployer extends Deployer { + + /** + * Deploy deployable to gws. + * + * @param gws Grizzly to deploy to. + * @param deployFrom URI ofr deployable to be deployed. + * + * @return Deployment identification. + * + * @throws DeployException Error in deployment. + */ + public final Integer deploy(GrizzlyWebServer gws, URI deployFrom) throws DeployException { + return super.deploy(gws, fromURI(deployFrom)); + } + + /** + * Create object to deploy from uri. + * + * @param uri of deployable object. + * + * @return Deployable object. + */ + public abstract V fromURI(URI uri); +} Index: modules/http/src/main/java/com/sun/grizzly/http/deployer/Deployer.java =================================================================== --- modules/http/src/main/java/com/sun/grizzly/http/deployer/Deployer.java Fri Sep 18 16:52:22 CEST 2009 +++ modules/http/src/main/java/com/sun/grizzly/http/deployer/Deployer.java Fri Sep 18 16:52:22 CEST 2009 @@ -0,0 +1,93 @@ +/* + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the license at + * https://glassfish.dev.java.net/public/CDDLv1.0.html or + * glassfish/bootstrap/legal/CDDLv1.0.txt. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * Header Notice in each file and include the License file + * at glassfish/bootstrap/legal/CDDLv1.0.txt. + * If applicable, add the following below the CDDL Header, + * with the fields enclosed by brackets [] replaced by + * you own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + */ +package com.sun.grizzly.http.deployer; + +import com.sun.grizzly.http.embed.GrizzlyWebServer; +import com.sun.grizzly.tcp.http11.GrizzlyAdapter; + +import java.util.Map; +import java.util.Set; +import java.util.HashMap; + +/** + * Deployer abstraction. + * + * @author Hubert Iwaniuk + * @param Type of object deployed by this deployer. + * @since Sep 17, 2009 + */ +public abstract class Deployer { + + private Map> deployed + = new HashMap>(); + + /** + * Deploy deployable to gws. + * + * @param gws Grizzly to deploy to. + * @param toDeploy Deployable to be deployed. + * + * @return Deployment identification. + * + * @throws DeployException Error in deployment. + */ + public final Integer deploy(GrizzlyWebServer gws, V toDeploy) throws DeployException { + Map> map = convert(toDeploy); + if (map == null || map.isEmpty()) { + throw new DeployException("No GrizzlyAdapters created for: " + toDeploy); + } + for (Map.Entry> adapterEntry : map.entrySet()) { + Set mappings = adapterEntry.getValue(); + gws.addGrizzlyAdapter( + adapterEntry.getKey(), mappings.toArray(new String[mappings.size()])); + } + final Integer deploymentId = toDeploy.hashCode(); + deployed.put(deploymentId, map.keySet()); + return deploymentId; + } + + /** + * Undeploy previously deployed deployable. + *r + * @param gws Grizzly to undeploy from. + * @param deploymentId Deployment identification + */ + public final void undeploy(GrizzlyWebServer gws, Integer deploymentId) { + final Set adapters = deployed.get(deploymentId); + for (GrizzlyAdapter adapter : adapters) { + gws.removeGrizzlyAdapter(adapter); // TODO removal can go wrong + } + } + + /** + * Converts deployable object to {@link Map} of {@link GrizzlyAdapter}s to paths to deploy to. + * + * @param toDeploy Deployable object to be converted. + * + * @return {@link Map}ping {@link GrizzlyAdapter}s to paths to be deployed under ({@link Set} of + * {@link String}s). + * + * @throws DeployException Error while creating adapters. + */ + protected abstract Map> convert(V toDeploy) throws DeployException; +} Index: modules/http/src/main/java/com/sun/grizzly/http/deployer/DeployException.java =================================================================== --- modules/http/src/main/java/com/sun/grizzly/http/deployer/DeployException.java Fri Sep 18 16:24:03 CEST 2009 +++ modules/http/src/main/java/com/sun/grizzly/http/deployer/DeployException.java Fri Sep 18 16:24:03 CEST 2009 @@ -0,0 +1,51 @@ +/* + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the license at + * https://glassfish.dev.java.net/public/CDDLv1.0.html or + * glassfish/bootstrap/legal/CDDLv1.0.txt. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * Header Notice in each file and include the License file + * at glassfish/bootstrap/legal/CDDLv1.0.txt. + * If applicable, add the following below the CDDL Header, + * with the fields enclosed by brackets [] replaced by + * you own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + */ +package com.sun.grizzly.http.deployer; + +/** + * Deploying error. + * + * @author Hubert Iwaniuk + * @since Sep 17, 2009 + */ +public class DeployException extends Exception { + /** {@inheritDoc} */ + public DeployException() { + super(); + } + + /** {@inheritDoc} */ + public DeployException(String message) { + super(message); + } + + /** {@inheritDoc} */ + public DeployException(String message, Throwable cause) { + super(message, cause); + } + + /** {@inheritDoc} */ + public DeployException(Throwable cause) { + super(cause); + } +}