[grizzly~git:deab666d] [2.3.x] + implement task #1486

  • From: oleksiys@...
  • To: commits@...
  • Subject: [grizzly~git:deab666d] [2.3.x] + implement task #1486
  • Date: Thu, 23 May 2013 21:23:53 +0000

Project:    grizzly
Repository: git
Revision:   deab666dee78adbd6a3c089e54e5e83ffc6d663c
Author:     oleksiys
Date:       2013-05-23 21:22:35 UTC
Link:       

Log Message:
------------
[2.3.x] + implement task #1486
java.net/jira/browse/GRIZZLY-1486

"Move Grizzly config under Glassfish"



Revisions:
----------
deab666dee78adbd6a3c089e54e5e83ffc6d663c


Modified Paths:
---------------
bom/pom.xml
modules/pom.xml


Diffs:
------
--- a/bom/pom.xml
+++ b/bom/pom.xml
@@ -47,7 +47,7 @@
     <parent>
         <groupId>net.java</groupId>
         <artifactId>jvnet-parent</artifactId>
-        <version>3</version>
+        <version>4</version>
         <relativePath/>
     </parent>
 
@@ -134,11 +134,6 @@
             </dependency>
             <dependency>
                 <groupId>org.glassfish.grizzly</groupId>
-                <artifactId>grizzly-config</artifactId>
-                <version>${project.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.glassfish.grizzly</groupId>
                 <artifactId>grizzly-http-server-multipart</artifactId>
                 <version>${project.version}</version>
             </dependency>--- a/modules/config/osgi.bundle
+++ /dev/null
@@ -1,49 +0,0 @@
-#
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
-#
-# Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
-#
-# The contents of this file are subject to the terms of either the GNU
-# General Public License Version 2 only ("GPL") or the Common Development
-# and Distribution License("CDDL") (collectively, 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/CDDL+GPL_1_1.html
-# or packager/legal/LICENSE.txt.  See the License for the specific
-# language governing permissions and limitations under the License.
-#
-# When distributing the software, include this License Header Notice in each
-# file and include the License file at packager/legal/LICENSE.txt.
-#
-# GPL Classpath Exception:
-# Oracle designates this particular file as subject to the "Classpath"
-# exception as provided by Oracle in the GPL Version 2 section of the License
-# file that accompanied this code.
-#
-# Modifications:
-# If applicable, add the following below the License Header, with the fields
-# enclosed by brackets [] replaced by your own identifying information:
-# "Portions Copyright [year] [name of copyright owner]"
-#
-# Contributor(s):
-# If you wish your version of this file to be governed by only the CDDL or
-# only the GPL Version 2, indicate your decision by adding "[Contributor]
-# elects to include this software in this distribution under the [CDDL or GPL
-# Version 2] license."  If you don't indicate a single choice of license, a
-# recipient has the option to distribute your version of this file under
-# either the CDDL, the GPL Version 2 or to extend the choice of license to
-# its licensees as provided above.  However, if you add GPL Version 2 code
-# and therefore, elected the GPL Version 2 license, then the option applies
-# only if the new code is made subject to such option by the copyright
-# holder.
-#
-
--exportcontents: \
-                        org.glassfish.grizzly.config; \
-                        org.glassfish.grizzly.config.dom; \
-                        org.glassfish.grizzly.config.portunif; \
-                        org.glassfish.grizzly.config.ssl; 
version=${project.version}
-
-Import-Package: \
-                        org.glassfish.grizzly*; version=${project.version}, \
-                        *--- a/modules/config/pom.xml
+++ /dev/null
@@ -1,243 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
-    DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
-
-    Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights 
reserved.
-
-    The contents of this file are subject to the terms of either the GNU
-    General Public License Version 2 only ("GPL") or the Common Development
-    and Distribution License("CDDL") (collectively, 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/CDDL+GPL_1_1.html
-    or packager/legal/LICENSE.txt.  See the License for the specific
-    language governing permissions and limitations under the License.
-
-    When distributing the software, include this License Header Notice in 
each
-    file and include the License file at packager/legal/LICENSE.txt.
-
-    GPL Classpath Exception:
-    Oracle designates this particular file as subject to the "Classpath"
-    exception as provided by Oracle in the GPL Version 2 section of the 
License
-    file that accompanied this code.
-
-    Modifications:
-    If applicable, add the following below the License Header, with the 
fields
-    enclosed by brackets [] replaced by your own identifying information:
-    "Portions Copyright [year] [name of copyright owner]"
-
-    Contributor(s):
-    If you wish your version of this file to be governed by only the CDDL or
-    only the GPL Version 2, indicate your decision by adding "[Contributor]
-    elects to include this software in this distribution under the [CDDL or 
GPL
-    Version 2] license."  If you don't indicate a single choice of license, a
-    recipient has the option to distribute your version of this file under
-    either the CDDL, the GPL Version 2 or to extend the choice of license to
-    its licensees as provided above.  However, if you add GPL Version 2 code
-    and therefore, elected the GPL Version 2 license, then the option applies
-    only if the new code is made subject to such option by the copyright
-    holder.
-
--->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" ;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ;
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 ;
http://maven.apache.org/maven-v4_0_0.xsd";>
-    <parent>
-        <groupId>org.glassfish.grizzly</groupId>
-        <artifactId>grizzly-project</artifactId>
-        <version>2.3.3-SNAPSHOT</version>
-        <relativePath>../../pom.xml</relativePath>
-    </parent>
-    <modelVersion>4.0.0</modelVersion>
-    <artifactId>grizzly-config</artifactId>
-    <version>2.3.3-SNAPSHOT</version>
-    <name>grizzly-config</name>
-    <profiles>
-        <profile>
-            <id>jdk7</id>
-            <activation>
-                <jdk>1.7</jdk>
-            </activation>
-            <build>
-            </build>
-        </profile>
-    </profiles>
-    <build>
-        <resources>
-            <resource>
-                <filtering>true</filtering>
-                <directory>src/main/java/</directory>
-                <excludes>
-                    <exclude>**/*.java</exclude>
-                </excludes>
-            </resource>
-            <resource>
-                <directory>src/main/resources</directory>
-            </resource>
-        </resources>
-        <defaultGoal>install</defaultGoal>
-        <finalName>${project.artifactId}</finalName>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-dependency-plugin</artifactId>
-                <version>2.4</version>
-                <executions>
-                    <execution>
-                        <configuration>
-                            <silent>true</silent>
-                            
<outputFile>${project.build.directory}/classpath.txt</outputFile>
-                        </configuration>
-                        <goals>
-                            <goal>build-classpath</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-            <plugin>
-                <groupId>org.glassfish.hk2</groupId>
-                <artifactId>config-generator</artifactId>
-                <version>${hk2.version}</version>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>generate-injectors</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>build-helper-maven-plugin</artifactId>
-                <version>1.7</version>
-                <executions>
-                    <execution>
-                        <id>add-source</id>
-                        <phase>generate-sources</phase>
-                        <goals>
-                            <goal>add-source</goal>
-                        </goals>
-                        <configuration>
-                            <sources>
-                                
<source>target/generated-sources/hk2-config-generator</source>
-                            </sources>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-            <plugin>
-                <groupId>org.glassfish.hk2</groupId>
-                <artifactId>hk2-inhabitant-generator</artifactId>
-                <version>${hk2.version}</version>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>generate-inhabitants</goal>
-                        </goals>
-                    </execution>
-                    <execution>
-                        <id>test</id>
-                        <phase>process-test-classes</phase>
-                        <goals>
-                            <goal>generate-inhabitants</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-eclipse-plugin</artifactId>
-                <version>2.9</version>
-                <configuration>
-                    <downloadSources>true</downloadSources>
-                    <downloadJavadocs>true</downloadJavadocs>
-                    <addGroupIdToProjectName>true</addGroupIdToProjectName>
-                </configuration>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-bundle-plugin</artifactId>
-                <version>${felix-version}</version>
-                <configuration>
-                    <supportedProjectTypes>
-                        <supportedProjectType>bundle</supportedProjectType>
-                    </supportedProjectTypes>
-                    <instructions>
-                        <_include>-${basedir}/osgi.bundle</_include>
-                    </instructions>
-                </configuration>
-                <executions>
-                    <execution>
-                        <id>bundle-manifest</id>
-                        <phase>process-classes</phase>
-                        <goals>
-                            <goal>manifest</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-            <plugin>
-                <artifactId>maven-surefire-plugin</artifactId>
-                <configuration>
-                    <argLine>-Xms256m -Xmx512m</argLine>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
-    <dependencies>
-        <dependency>
-            <groupId>org.glassfish.grizzly</groupId>
-            <artifactId>grizzly-http-server</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.glassfish.grizzly</groupId>
-            <artifactId>grizzly-portunif</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.glassfish.grizzly</groupId>
-            <artifactId>grizzly-websockets</artifactId>
-            <version>${project.version}</version>
-            <scope>test</scope>
-        </dependency>
-        <dependency>
-            <groupId>org.glassfish.hk2</groupId>
-            <artifactId>core</artifactId>
-            <version>${hk2.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.glassfish.hk2</groupId>
-            <artifactId>hk2-locator</artifactId>
-            <version>${hk2.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.glassfish.hk2</groupId>
-            <artifactId>hk2-config</artifactId>
-            <version>${hk2.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.glassfish.hk2</groupId>
-            <artifactId>config-types</artifactId>
-            <version>${hk2.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.glassfish.hk2</groupId>
-            <artifactId>osgi-adapter</artifactId>
-            <version>${hk2.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>stax</groupId>
-            <artifactId>stax</artifactId>
-            <version>1.2.0</version>
-            <scope>provided</scope>
-        </dependency>
-
-        <!-- test deps -->
-        <dependency>
-            <groupId>javax.servlet</groupId>
-            <artifactId>javax.servlet-api</artifactId>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
-</project>--- 
a/modules/config/src/main/java/org/glassfish/grizzly/config/ConfigAwareElement.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright (c) 2009-2012 Oracle and/or its affiliates. All rights reserved.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, 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/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt.  See the License for the specific
- * language governing permissions and limitations under the License.
- *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
- *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the 
License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or 
GPL
- * Version 2] license."  If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above.  However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
- */
-
-package org.glassfish.grizzly.config;
-
-import org.glassfish.grizzly.config.dom.NetworkListener;
-import org.glassfish.hk2.api.ServiceLocator;
-import org.jvnet.hk2.config.ConfigBeanProxy;
-
-/**
- * Grizzly config elements like protocols, filters, which implement this
- * interface, will get correspondent dom configuration element.
- * 
- * @author Alexey Stashok
- */
-public interface ConfigAwareElement<E extends ConfigBeanProxy> {
-    public void configure(ServiceLocator habitat, NetworkListener 
networkListener, E configuration);
-}--- 
a/modules/config/src/main/java/org/glassfish/grizzly/config/ContextRootInfo.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright (c) 2009-2011 Oracle and/or its affiliates. All rights reserved.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, 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/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt.  See the License for the specific
- * language governing permissions and limitations under the License.
- *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
- *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the 
License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or 
GPL
- * Version 2] license."  If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above.  However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
- */
-package org.glassfish.grizzly.config;
-
-import org.glassfish.grizzly.http.server.HttpHandler;
-
-/**
- * Class represents context-root associated information
- */
-public final class ContextRootInfo {
-
-    /**
-     * The interface, which is responsible for holding 
<tt>ContextRootInfo</tt>,
-     * which makes possible to initialize <tt>ContextRootInfo<tt> lazily.
-     */
-    public static interface Holder {
-
-        /**
-         * Gets the Grizzly {@link HttpHandler}, associated with the context.
-         *
-         * @return the Grizzly {@link HttpHandler}, associated with the 
context.
-         */
-        public HttpHandler getHttpHandler();
-
-        /**
-         * Gets the application container, associated with the context.
-         *
-         * @return the application container, associated with the context.
-         */
-        public Object getContainer();
-    }
-    private final Holder holder;
-
-    /**
-     * Create <tt>ContextRootInfo</tt> using prepared {@link HttpHandler} and
-     * application container parameters.
-     * 
-     * @param handler Grizzly {@link HttpHandler}, associated with the 
context.
-     * @param container application container, associated with the context.
-     */
-    public ContextRootInfo(final HttpHandler handler,
-            final Object container) {
-        holder = new SimpleHolder(handler, container);
-    }
-
-    /**
-     * Create <tt>ContextRootInfo</tt> using passed {@link Holder} object, 
which
-     * might be initialized lazily.
-     * 
-     * @param holder context info {@link Holder}.
-     */
-    public ContextRootInfo(final Holder holder) {
-        this.holder = holder;
-    }
-
-    /**
-     * Gets the Grizzly {@link HttpHandler}, associated with the context.
-     *
-     * @return the Grizzly {@link HttpHandler}, associated with the context.
-     */
-    public HttpHandler getHttpHandler() {
-        return holder.getHttpHandler();
-    }
-
-    /**
-     * Gets the application container, associated with the context.
-     *
-     * @return the application container, associated with the context.
-     */
-    public Object getContainer() {
-        return holder.getContainer();
-    }
-
-    private static class SimpleHolder implements Holder {
-
-        private final HttpHandler handler;
-        private final Object container;
-
-        public SimpleHolder(HttpHandler handler, Object container) {
-            this.handler = handler;
-            this.container = container;
-        }
-
-        @Override
-        public HttpHandler getHttpHandler() {
-            return handler;
-        }
-
-        @Override
-        public Object getContainer() {
-            return container;
-        }
-    }
-}--- 
a/modules/config/src/main/java/org/glassfish/grizzly/config/DefaultProxy.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, 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/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt.  See the License for the specific
- * language governing permissions and limitations under the License.
- *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
- *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the 
License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or 
GPL
- * Version 2] license."  If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above.  However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
- */
-
-package org.glassfish.grizzly.config;
-
-import org.jvnet.hk2.config.Attribute;
-import org.jvnet.hk2.config.ConfigBeanProxy;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.HashMap;
-import java.util.Map;
-
-public class DefaultProxy implements InvocationHandler {
-    private final Map<String, Method> methods;
-    private final ConfigBeanProxy parent;
-
-    DefaultProxy(ConfigBeanProxy parent, final Class<? extends 
ConfigBeanProxy> sslClass) {
-        this.parent = parent;
-        methods = new HashMap<String, Method>();
-        final Method[] list = sslClass.getDeclaredMethods();
-        for (Method method : list) {
-            if (method.getName().startsWith("get") || 
method.getName().startsWith("is")) {
-                methods.put(method.getName(), method);
-            }
-        }
-    }
-
-    public ConfigBeanProxy getParent() {
-        return parent;
-    }
-
-    public Object invoke(Object proxy, Method method, Object[] args) throws 
Throwable {
-        Object value = null;
-        if (methods.get(method.getName()) != null) {
-            final Attribute annotation = 
method.getAnnotation(Attribute.class);
-            if (annotation != null) {
-                String defValue = annotation.defaultValue().trim();
-                if (defValue.length() > 0) {
-                    value = defValue;
-                }
-            }
-        } else if ("getParent".equals(method.getName())) {
-            value = getParent();
-        } else {
-            throw new GrizzlyConfigException(String.format("Method not 
implemented for a %s: %s", getClass().getName(),
-                    method.getName()));
-        }
-        return value;
-    }
-
-    public static ConfigBeanProxy createDummyProxy(ConfigBeanProxy parent,
-            final Class<? extends ConfigBeanProxy> type) {
-        return (ConfigBeanProxy) 
Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type},
-                new DefaultProxy(parent, type));
-    }
-}--- 
a/modules/config/src/main/java/org/glassfish/grizzly/config/GenericGrizzlyListener.java
+++ /dev/null
@@ -1,966 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright (c) 2007-2013 Oracle and/or its affiliates. All rights reserved.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, 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/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt.  See the License for the specific
- * language governing permissions and limitations under the License.
- *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
- *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the 
License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or 
GPL
- * Version 2] license."  If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above.  However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
- */
-package org.glassfish.grizzly.config;
-
-import java.beans.PropertyChangeEvent;
-import java.io.IOException;
-import java.lang.reflect.Method;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.glassfish.grizzly.IOStrategy;
-
-import org.glassfish.grizzly.SocketBinder;
-import org.glassfish.grizzly.config.dom.Http;
-import org.glassfish.grizzly.config.dom.NetworkListener;
-import org.glassfish.grizzly.config.dom.PortUnification;
-import org.glassfish.grizzly.config.dom.Protocol;
-import org.glassfish.grizzly.config.dom.ProtocolChain;
-import org.glassfish.grizzly.config.dom.ProtocolChainInstanceHandler;
-import org.glassfish.grizzly.config.dom.ProtocolFilter;
-import org.glassfish.grizzly.config.dom.SelectionKeyHandler;
-import org.glassfish.grizzly.config.dom.Spdy;
-import org.glassfish.grizzly.config.dom.Ssl;
-import org.glassfish.grizzly.config.dom.ThreadPool;
-import org.glassfish.grizzly.config.dom.Transport;
-import org.glassfish.grizzly.config.dom.Transports;
-import org.glassfish.grizzly.config.portunif.HttpRedirectFilter;
-import org.glassfish.grizzly.filterchain.Filter;
-import org.glassfish.grizzly.filterchain.FilterChain;
-import org.glassfish.grizzly.filterchain.FilterChainBuilder;
-import org.glassfish.grizzly.filterchain.TransportFilter;
-import org.glassfish.grizzly.http.ContentEncoding;
-import org.glassfish.grizzly.http.GZipContentEncoding;
-import org.glassfish.grizzly.http.KeepAlive;
-import org.glassfish.grizzly.http.LZMAContentEncoding;
-import org.glassfish.grizzly.http.server.AddOn;
-import org.glassfish.grizzly.http.server.CompressionEncodingFilter;
-import org.glassfish.grizzly.http.server.CompressionLevel;
-import org.glassfish.grizzly.http.server.FileCacheFilter;
-import org.glassfish.grizzly.http.server.HttpHandler;
-import org.glassfish.grizzly.http.server.HttpServerFilter;
-import org.glassfish.grizzly.http.server.ServerFilterConfiguration;
-import org.glassfish.grizzly.http.server.StaticHttpHandler;
-import org.glassfish.grizzly.http.server.filecache.FileCache;
-import org.glassfish.grizzly.http.util.MimeHeaders;
-import org.glassfish.grizzly.memory.AbstractMemoryManager;
-import org.glassfish.grizzly.memory.ByteBufferManager;
-import org.glassfish.grizzly.nio.NIOTransport;
-import org.glassfish.grizzly.nio.RoundRobinConnectionDistributor;
-import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
-import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder;
-import org.glassfish.grizzly.nio.transport.UDPNIOTransport;
-import org.glassfish.grizzly.nio.transport.UDPNIOTransportBuilder;
-import org.glassfish.grizzly.portunif.PUFilter;
-import org.glassfish.grizzly.portunif.PUProtocol;
-import org.glassfish.grizzly.portunif.ProtocolFinder;
-import org.glassfish.grizzly.portunif.finders.SSLProtocolFinder;
-import org.glassfish.grizzly.rcm.ResourceAllocationFilter;
-import org.glassfish.grizzly.ssl.SSLEngineConfigurator;
-import org.glassfish.grizzly.ssl.SSLBaseFilter;
-import org.glassfish.grizzly.strategies.WorkerThreadIOStrategy;
-import org.glassfish.grizzly.threadpool.DefaultWorkerThread;
-import org.glassfish.grizzly.threadpool.GrizzlyExecutorService;
-import org.glassfish.grizzly.threadpool.ThreadPoolConfig;
-import org.glassfish.grizzly.utils.DelayedExecutor;
-import org.glassfish.grizzly.utils.IdleTimeoutFilter;
-import org.glassfish.hk2.api.ServiceLocator;
-import org.jvnet.hk2.config.ConfigBeanProxy;
-
-/**
- * Generic {@link GrizzlyListener} implementation, which is not HTTP 
dependent, and can support any Transport
- * configuration, based on {@link FilterChain}.
- *
- * @author Alexey Stashok
- */
-public class GenericGrizzlyListener implements GrizzlyListener {
-    /**
-     * The logger to use for logging messages.
-     */
-    static final Logger logger = 
Logger.getLogger(GrizzlyListener.class.getName());
-    protected volatile String name;
-    protected volatile InetAddress address;
-    protected volatile int port;
-    protected NIOTransport transport;
-    protected FilterChain rootFilterChain;
-    private volatile ExecutorService auxExecutorService;
-    private volatile DelayedExecutor delayedExecutor;
-    private volatile long transactionTimeoutMillis = -1;
-
-    @Override
-    public String getName() {
-        return name;
-    }
-
-    protected final void setName(String name) {
-        this.name = name;
-    }
-
-    @Override
-    public InetAddress getAddress() {
-        return address;
-    }
-
-    protected final void setAddress(InetAddress inetAddress) {
-        address = inetAddress;
-    }
-
-    @Override
-    public int getPort() {
-        return port;
-    }
-
-    protected void setPort(int port) {
-        this.port = port;
-    }
-
-    @Override
-    public void start() throws IOException {
-        delayedExecutor.start();
-        ((SocketBinder) transport).bind(new InetSocketAddress(address, 
port));
-        transport.start();
-    }
-
-    @Override
-    public void stop() throws IOException {
-        stopDelayedExecutor();
-        final NIOTransport localTransport = transport;
-        transport = null;
-        if (localTransport != null) {
-            localTransport.stop();
-        }
-        rootFilterChain = null;
-    }
-
-    @Override
-    public void destroy() {
-    }
-
-    @Override
-    public void processDynamicConfigurationChange(ServiceLocator habitat,
-        PropertyChangeEvent[] events) {
-    }
-
-    @Override
-    public <T> T getAdapter(Class<T> adapterClass) {
-        return null;
-    }
-
-    public <E> List<E> getFilters(Class<E> clazz) {
-        return getFilters(clazz, rootFilterChain, new ArrayList<E>(2));
-    }
-
-    public org.glassfish.grizzly.Transport getTransport() {
-        return transport;
-    }
-    
-    @SuppressWarnings({"unchecked"})
-    public static <E> List<E> getFilters(Class<E> clazz,
-        FilterChain filterChain, List<E> filters) {
-        for (final Filter filter : filterChain) {
-            if (clazz.isAssignableFrom(filter.getClass())) {
-                filters.add((E) filter);
-            }
-            if (PUFilter.class.isAssignableFrom(filter.getClass())) {
-                final Set<PUProtocol> puProtocols = ((PUFilter) 
filter).getProtocols();
-                for (PUProtocol puProtocol : puProtocols) {
-                    getFilters(clazz, puProtocol.getFilterChain(), filters);
-                }
-            }
-        }
-        return filters;
-    }
-
-    /*
-     * Configures the given grizzlyListener.
-     *
-     * @param networkListener The NetworkListener to configure
-     */
-    // TODO: Must get the information from domain.xml Config objects.
-    // TODO: Pending Grizzly issue 54
-    @Override
-    public void configure(final ServiceLocator habitat,
-        final NetworkListener networkListener) throws IOException {
-        setName(networkListener.getName());
-        setAddress(InetAddress.getByName(networkListener.getAddress()));
-        setPort(Integer.parseInt(networkListener.getPort()));
-        configureDelayedExecutor();
-
-        final FilterChainBuilder filterChainBuilder = 
FilterChainBuilder.stateless();
-        
-        configureTransport(networkListener,
-                           networkListener.findTransport(),
-                           filterChainBuilder);
-
-        configureProtocol(habitat, networkListener,
-                networkListener.findProtocol(), filterChainBuilder);
-
-        configureThreadPool(habitat, networkListener,
-                networkListener.findThreadPool());
-
-        rootFilterChain = filterChainBuilder.build();
-        transport.setProcessor(rootFilterChain);
-    }
-
-    protected void configureTransport(final NetworkListener networkListener,
-                                      final Transport transportConfig,
-                                      final FilterChainBuilder 
filterChainBuilder) {
-        
-        final String transportClassName = transportConfig.getClassname();
-        if (TCPNIOTransport.class.getName().equals(transportClassName)) {
-            transport = configureTCPTransport(transportConfig);
-        } else if 
(UDPNIOTransport.class.getName().equals(transportClassName)) {
-            transport = configureUDPTransport();
-        } else {
-            throw new GrizzlyConfigException("Unsupported transport type " + 
transportConfig.getName());
-        }
-
-        String selectorName = transportConfig.getSelectionKeyHandler();
-        if (selectorName != null) {
-            if (getSelectionKeyHandlerByName(selectorName, transportConfig) 
!= null) {
-                if (logger.isLoggable(Level.INFO)) {
-                    logger.warning("Element, selection-key-handler, has been 
deprecated and is effectively ignored by the runtime.");
-                }
-            }
-        }
-
-        if 
(!Transport.BYTE_BUFFER_TYPE.equalsIgnoreCase(transportConfig.getByteBufferType()))
 {
-            transport.setMemoryManager(
-                    new ByteBufferManager(true,
-                                          
AbstractMemoryManager.DEFAULT_MAX_BUFFER_SIZE,
-                                          
ByteBufferManager.DEFAULT_SMALL_BUFFER_SIZE));
-        }
-        
transport.setSelectorRunnersCount(Integer.parseInt(transportConfig.getAcceptorThreads()));
-
-        final int readSize = 
Integer.parseInt(transportConfig.getSocketReadBufferSize());
-        if (readSize > 0) {
-            transport.setReadBufferSize(readSize);
-        }
-
-        final int writeSize = 
Integer.parseInt(transportConfig.getSocketWriteBufferSize());
-        if (writeSize > 0) {
-            transport.setWriteBufferSize(writeSize);
-        }
-
-        
transport.getKernelThreadPoolConfig().setPoolName(networkListener.getName() + 
"-kernel");
-        
transport.setIOStrategy(loadIOStrategy(transportConfig.getIOStrategy()));
-        transport.setNIOChannelDistributor(
-                new RoundRobinConnectionDistributor(
-                transport,
-                
Boolean.parseBoolean(transportConfig.getDedicatedAcceptorEnabled())));
-        
-        filterChainBuilder.add(new TransportFilter());
-    }
-
-    protected NIOTransport configureTCPTransport(final Transport 
transportConfig) {
-        
-        final TCPNIOTransport tcpTransport = 
TCPNIOTransportBuilder.newInstance().build();
-        
tcpTransport.setTcpNoDelay(Boolean.parseBoolean(transportConfig.getTcpNoDelay()));
-        
tcpTransport.setLinger(Integer.parseInt(transportConfig.getLinger()));
-        
tcpTransport.setWriteTimeout(Long.parseLong(transportConfig.getWriteTimeoutMillis()),
 TimeUnit.MILLISECONDS);
-        
tcpTransport.setReadTimeout(Long.parseLong(transportConfig.getReadTimeoutMillis()),
 TimeUnit.MILLISECONDS);
-        
tcpTransport.setServerConnectionBackLog(Integer.parseInt(transportConfig.getMaxConnectionsCount()));
-        return tcpTransport;
-    }
-
-    protected NIOTransport configureUDPTransport() {
-        return UDPNIOTransportBuilder.newInstance().build();
-    }
-
-    protected void configureProtocol(final ServiceLocator habitat,
-            final NetworkListener networkListener,
-            final Protocol protocol,
-            final FilterChainBuilder filterChainBuilder) {
-        
-        if (Boolean.valueOf(protocol.getSecurityEnabled())) {
-            configureSsl(habitat, 
-                         getSsl(protocol),
-                         filterChainBuilder);
-        }
-        configureSubProtocol(habitat, networkListener, protocol,
-                filterChainBuilder);
-    }
-
-    protected void configureSubProtocol(final ServiceLocator habitat,
-            final NetworkListener networkListener,
-            final Protocol protocol,
-            final FilterChainBuilder filterChainBuilder) {
-        
-        if (protocol.getHttp() != null) {
-            final Http http = protocol.getHttp();
-            configureHttpProtocol(habitat,
-                                  networkListener,
-                                  http,
-                                  filterChainBuilder,
-                                  
Boolean.valueOf(protocol.getSecurityEnabled()));
-
-        } else if (protocol.getPortUnification() != null) {
-            // Port unification
-            final PortUnification pu = protocol.getPortUnification();
-            final String puFilterClassname = pu.getClassname();
-            PUFilter puFilter = null;
-            if (puFilterClassname != null) {
-                try {
-                    puFilter = Utils.newInstance(habitat,
-                        PUFilter.class, puFilterClassname, 
puFilterClassname);
-                    configureElement(habitat, networkListener, pu, puFilter);
-                } catch (Exception e) {
-                    logger.log(Level.WARNING,
-                        "Can not initialize port unification filter: "
-                            + puFilterClassname + " default filter will be 
used instead", e);
-                }
-            }
-            if (puFilter == null) {
-                puFilter = new PUFilter();
-            }
-            List<org.glassfish.grizzly.config.dom.ProtocolFinder> 
findersConfig = pu.getProtocolFinder();
-            for (org.glassfish.grizzly.config.dom.ProtocolFinder 
finderConfig : findersConfig) {
-                final String finderClassname = finderConfig.getClassname();
-                try {
-                    final ProtocolFinder protocolFinder = 
Utils.newInstance(habitat,
-                        ProtocolFinder.class, finderClassname, 
finderClassname);
-                    configureElement(habitat, networkListener, finderConfig, 
protocolFinder);
-                    final Protocol subProtocol = finderConfig.findProtocol();
-                    final FilterChainBuilder subProtocolFilterChainBuilder =
-                        puFilter.getPUFilterChainBuilder();
-                    // If subprotocol is secured - we need to wrap it under 
SSLProtocolFinder
-                    if (Boolean.valueOf(subProtocol.getSecurityEnabled())) {
-                        final PUFilter extraSslPUFilter = new PUFilter();
-                        
-                        final Filter addedSSLFilter = configureSsl(
-                                habitat, getSsl(subProtocol),
-                                subProtocolFilterChainBuilder);
-                        
-                        subProtocolFilterChainBuilder.add(extraSslPUFilter);
-                        final FilterChainBuilder 
extraSslPUFilterChainBuilder =
-                            extraSslPUFilter.getPUFilterChainBuilder();
-                        
-                        try {
-                            // temporary add SSL Filter, so subprotocol
-                            // will see it
-                            extraSslPUFilterChainBuilder.add(addedSSLFilter);
-                            configureSubProtocol(habitat, networkListener,
-                                    subProtocol, 
extraSslPUFilterChainBuilder);
-                        } finally {
-                            // remove SSL Filter
-                            
extraSslPUFilterChainBuilder.remove(addedSSLFilter);
-                        }
-                        
-                        extraSslPUFilter.register(protocolFinder,
-                                extraSslPUFilterChainBuilder.build());
-                        
-                        puFilter.register(new SSLProtocolFinder(
-                            new SSLConfigurator(habitat, 
subProtocol.getSsl())),
-                            subProtocolFilterChainBuilder.build());
-                    } else {
-                        configureSubProtocol(habitat, networkListener,
-                                subProtocol, subProtocolFilterChainBuilder);
-                        puFilter.register(protocolFinder, 
subProtocolFilterChainBuilder.build());
-                    }
-                } catch (Exception e) {
-                    logger.log(Level.WARNING, "Can not initialize sub 
protocol. Finder: "
-                        + finderClassname, e);
-                }
-            }
-            filterChainBuilder.add(puFilter);
-        } else if (protocol.getHttpRedirect() != null) {
-            filterChainBuilder.add(new 
org.glassfish.grizzly.http.HttpServerFilter());
-            final HttpRedirectFilter filter = new HttpRedirectFilter();
-            filter.configure(habitat, networkListener, 
protocol.getHttpRedirect());
-            filterChainBuilder.add(filter);
-        } else {
-            ProtocolChainInstanceHandler pcihConfig = 
protocol.getProtocolChainInstanceHandler();
-            if (pcihConfig == null) {
-                logger.log(Level.WARNING, "Empty protocol declaration");
-                return;
-            }
-            ProtocolChain filterChainConfig = pcihConfig.getProtocolChain();
-            for (ProtocolFilter filterConfig : 
filterChainConfig.getProtocolFilter()) {
-                final String filterClassname = filterConfig.getClassname();
-                try {
-                    final Filter filter = (Filter) 
Utils.newInstance(filterClassname);
-                    configureElement(habitat, networkListener, filterConfig, 
filter);
-                    filterChainBuilder.add(filter);
-                } catch (Exception e) {
-                    logger.log(Level.WARNING, "Can not initialize protocol 
filter: "
-                        + filterClassname, e);
-                    throw new IllegalStateException("Can not initialize 
protocol filter: "
-                        + filterClassname);
-                }
-            }
-        }
-    }
-
-    protected static Filter configureSsl(final ServiceLocator habitat,
-                                       final Ssl ssl,
-                                       final FilterChainBuilder 
filterChainBuilder) {
-        final SSLEngineConfigurator serverConfig = new 
SSLConfigurator(habitat, ssl);
-//        final SSLEngineConfigurator clientConfig = new 
SSLConfigurator(habitat, ssl);
-//        clientConfig.setClientMode(true);
-        final SSLBaseFilter sslFilter = new SSLBaseFilter(serverConfig,
-         //                                             clientConfig,
-                                                      
isRenegotiateOnClientAuthWant(ssl));
-        sslFilter.setHandshakeTimeout(
-                Long.parseLong(ssl.getHandshakeTimeoutMillis()), 
TimeUnit.MILLISECONDS);
-
-        filterChainBuilder.add(sslFilter);
-        return sslFilter;
-    }
-
-    private static boolean isRenegotiateOnClientAuthWant(final Ssl ssl) {
-        return ssl == null || 
Boolean.parseBoolean(ssl.getRenegotiateOnClientAuthWant());
-    }
-
-    @SuppressWarnings({"unchecked"})
-    private static boolean configureElement(ServiceLocator habitat,
-            NetworkListener networkListener, ConfigBeanProxy configuration,
-            Object instance) {
-        
-        if (instance instanceof ConfigAwareElement) {
-            ((ConfigAwareElement) instance).configure(habitat, 
networkListener,
-                    configuration);
-            
-            return true;
-        }
-        
-        return false;
-    }
-
-    protected void configureThreadPool(final ServiceLocator habitat,
-            final NetworkListener networkListener,
-            final ThreadPool threadPool) {
-        
-        final String classname = threadPool.getClassname();
-        if (classname != null &&
-                
!ThreadPool.DEFAULT_THREAD_POOL_CLASS_NAME.equals(classname)) {
-            
-            // Use custom thread pool
-            try {
-                final ExecutorService customThreadPool =
-                        Utils.newInstance(habitat,
-                        ExecutorService.class, classname, classname);
-                
-                if (customThreadPool != null) {
-                    if (!configureElement(habitat, networkListener,
-                            threadPool, customThreadPool)) {
-                        logger.log(Level.INFO,
-                                "The ThreadPool configuration bean can not 
be "
-                                + "passed to the custom thread-pool: {0}" +
-                                " instance, because it's not {1}.",
-                                new Object[] {
-                                classname, 
ConfigAwareElement.class.getName()});
-                    }
-                    
-                    transport.setWorkerThreadPool(customThreadPool);
-                    return;
-                }
-                
-                logger.log(Level.WARNING,
-                        "Can not initalize custom thread pool: {0}", 
classname);
-                
-            } catch (Throwable t) {
-                logger.log(Level.WARNING,
-                        "Can not initalize custom thread pool: " + 
classname, t);
-            }
-        }
-            
-        try {
-            // Use standard Grizzly thread pool
-            
transport.setWorkerThreadPool(GrizzlyExecutorService.createInstance(
-                configureThreadPoolConfig(networkListener, threadPool)));
-        } catch (NumberFormatException ex) {
-            logger.log(Level.WARNING, "Invalid thread-pool attribute", ex);
-        }
-    }
-
-    protected ThreadPoolConfig configureThreadPoolConfig(final 
NetworkListener networkListener,
-                                                         final ThreadPool 
threadPool) {
-
-        final int maxQueueSize = threadPool.getMaxQueueSize() == null ? 
Integer.MAX_VALUE
-            : Integer.parseInt(threadPool.getMaxQueueSize());
-        final int minThreads = 
Integer.parseInt(threadPool.getMinThreadPoolSize());
-        final int maxThreads = 
Integer.parseInt(threadPool.getMaxThreadPoolSize());
-        final int timeout = 
Integer.parseInt(threadPool.getIdleThreadTimeoutSeconds());
-        final ThreadPoolConfig poolConfig = ThreadPoolConfig.defaultConfig();
-        poolConfig.setPoolName(networkListener.getName());
-        poolConfig.setCorePoolSize(minThreads);
-        poolConfig.setMaxPoolSize(maxThreads);
-        poolConfig.setQueueLimit(maxQueueSize);
-
-        // we specify the classloader that loaded this class to ensure
-        // we present the same initial classloader no matter what mode
-        // GlassFish is being run in.
-        // See http://java.net/jira/browse/GLASSFISH-19639
-        poolConfig.setInitialClassLoader(this.getClass().getClassLoader());
-
-        poolConfig.setKeepAliveTime(timeout < 0 ? Long.MAX_VALUE : timeout, 
TimeUnit.SECONDS);
-        if (transactionTimeoutMillis > 0 && !Utils.isDebugVM()) {
-            poolConfig.setTransactionTimeout(delayedExecutor,
-                    transactionTimeoutMillis, TimeUnit.MILLISECONDS);
-        }
-        
-        return poolConfig;
-    }
-
-    protected void configureDelayedExecutor() {
-        final AtomicInteger threadCounter = new AtomicInteger();
-        auxExecutorService = Executors.newCachedThreadPool(
-            new ThreadFactory() {
-                @Override
-                public Thread newThread(Runnable r) {
-                    final Thread newThread = new DefaultWorkerThread(
-                        transport.getAttributeBuilder(),
-                        getName() + '-' + threadCounter.getAndIncrement(),
-                        null,
-                        r);
-                    newThread.setDaemon(true);
-                    return newThread;
-                }
-            });
-        delayedExecutor = new Dela
[truncated due to length]



[grizzly~git:deab666d] [2.3.x] + implement task #1486

oleksiys 05/23/2013
Terms of Use; Privacy Policy; Copyright ©2013-2015 (revision 20150226.965aeb8)
 
 
Close
loading
Please Confirm
Close