dev@grizzly.java.net

Re: Embedding WebAppAdapter was RFC Deployer refactoring

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Mon, 21 Sep 2009 11:31:39 -0400

Salut,

Hubert Iwaniuk wrote:
> Hi *
>
> I've updated Deployer API:
>
> 1. Can updeploy
> 2. Doesn't need to support URI deployments.

See inline...

> 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 <V> Type of object to be deployed.
> + *
> + * @return Deployment identification.
> + *
> + * @throws DeployException Deployment failed.
> + */
> + public <V> Integer deploy(V toDeploy, Deployer<V> deployer) throws DeployException {
> + return deployer.deploy(this, toDeploy);
> -}
> + }
> +

+1

> + /**
> + * Deploy from given uri using provided deployer.
> + *
> + * @param fromURI uri to deploy from.
> + * @param deployer to be used for deployment.
> + * @param <V> Type of object to be deployed.
> + *
> + * @return Deployment identification.
> + *
> + * @throws DeployException Deployment failed.
> + */
> + public <V> Integer deploy(URI fromURI, FromURIDeployer<V> deployer) throws DeployException {
> + return deployer.deploy(this, fromURI);
> + }

+1

> +
> + /**
> + * Undeploy deploymentId using provided deployer.
> + *
> + * @param deploymentId Deployment identification to be undeployed.
> + * @param deployer to be used for undeploing.
> + * @param <V> Type of object that was deployed by provided deployer.
> + */
> + public <V> void undeploy(Integer deploymentId, Deployer<V> deployer) {
> + deployer.undeploy(this, deploymentId);
> + }
> +}

+1


> 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 {_at_link URI} .
> + *
> + * @author Hubert Iwaniuk
> + * @param <V> Type of object deployed by this deployer.
> + * @since Sep 18, 2009
> + */
> +public abstract class FromURIDeployer<V> extends Deployer<V> {
> +
> + /**
> + * 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);

Do we needs that method to be abstract? I would think all URI should be
deployed the same way. Can you elaborate?



> +}
> 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 <V> Type of object deployed by this deployer.
> + * @since Sep 17, 2009
> + */
> +public abstract class Deployer<V> {
> +
> + private Map<Integer, Set<GrizzlyAdapter>> deployed
> + = new HashMap<Integer, Set<GrizzlyAdapter>>();
> +
> + /**
> + * 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<GrizzlyAdapter, Set<String>> map = convert(toDeploy);

Here the convert role will consist of doing something similar to what
the current GWSD does right now, e.g. populate
GrizzlyAdapter/ServletAdapter instances, right?


> + if (map == null || map.isEmpty()) {
> + throw new DeployException("No GrizzlyAdapters created for: " + toDeploy);
> + }
> + for (Map.Entry<GrizzlyAdapter, Set<String>> adapterEntry : map.entrySet()) {
> + Set<String> 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;
> + }

A+

--Jeanfrancois



> +
> + /**
> + * 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<GrizzlyAdapter> adapters = deployed.get(deploymentId);
> + for (GrizzlyAdapter adapter : adapters) {
> + gws.removeGrizzlyAdapter(adapter); // TODO removal can go wrong
> + }
> + }
> +
> + /**
> + * Converts deployable object to {_at_link Map} of {_at_link GrizzlyAdapter}s to paths to deploy to.
> + *
> + * @param toDeploy Deployable object to be converted.
> + *
> + * @return {_at_link Map}ping {_at_link GrizzlyAdapter}s to paths to be deployed under ({_at_link Set} of
> + * {_at_link String}s).
> + *
> + * @throws DeployException Error while creating adapters.
> + */
> + protected abstract Map<GrizzlyAdapter, Set<String>> 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 {
> + /** {_at_inheritDoc} */
> + public DeployException() {
> + super();
> + }
> +
> + /** {_at_inheritDoc} */
> + public DeployException(String message) {
> + super(message);
> + }
> +
> + /** {_at_inheritDoc} */
> + public DeployException(String message, Throwable cause) {
> + super(message, cause);
> + }
> +
> + /** {_at_inheritDoc} */
> + public DeployException(Throwable cause) {
> + super(cause);
> + }
> +}
>
>