You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by lr...@apache.org on 2011/03/29 20:25:48 UTC
svn commit: r1086671 - in /tuscany/sca-java-2.x/trunk/modules/host-http:
META-INF/ src/main/java/org/apache/tuscany/sca/host/http/
src/main/java/org/apache/tuscany/sca/host/http/client/
src/main/java/org/apache/tuscany/sca/host/http/extensibility/
Author: lresende
Date: Tue Mar 29 18:25:48 2011
New Revision: 1086671
URL: http://svn.apache.org/viewvc?rev=1086671&view=rev
Log:
TUSCANY-3856 - Providing HttpPortAllocator, a default implementation plus extensibility to allow others to provide their own way to select available ports for http embedded runtime
Added:
tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/HttpScheme.java (with props)
tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/
tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/DefaultHttpPortAllocatorExtensionPoint.java (with props)
tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/ExtensibleHttpPortAllocator.java (with props)
tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocator.java (with props)
tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocatorExtensionPoint.java (with props)
Modified:
tuscany/sca-java-2.x/trunk/modules/host-http/META-INF/MANIFEST.MF
tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/client/HttpClientFactory.java
Modified: tuscany/sca-java-2.x/trunk/modules/host-http/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/host-http/META-INF/MANIFEST.MF?rev=1086671&r1=1086670&r2=1086671&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/host-http/META-INF/MANIFEST.MF (original)
+++ tuscany/sca-java-2.x/trunk/modules/host-http/META-INF/MANIFEST.MF Tue Mar 29 18:25:48 2011
@@ -4,7 +4,8 @@ Export-Package: org.apache.tuscany.sca.h
org.apache.tuscany.sca.core,
org.apache.tuscany.sca.extensibility,
javax.servlet.http",
- org.apache.tuscany.sca.host.http.client;version="2.0.0";uses:="org.apache.http.client"
+ org.apache.tuscany.sca.host.http.client;version="2.0.0";uses:="org.apache.http.client",
+ org.apache.tuscany.sca.host.http.extensibility;version="2.0.0"
SCA-Version: 1.1
Bundle-Name: Apache Tuscany SCA HTTP Servlet Host Extension Point
Bundle-Vendor: The Apache Software Foundation
Added: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/HttpScheme.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/HttpScheme.java?rev=1086671&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/HttpScheme.java (added)
+++ tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/HttpScheme.java Tue Mar 29 18:25:48 2011
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.http;
+
+public enum HttpScheme {
+ HTTP,
+ HTTPS
+}
Propchange: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/HttpScheme.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/HttpScheme.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/client/HttpClientFactory.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/client/HttpClientFactory.java?rev=1086671&r1=1086670&r2=1086671&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/client/HttpClientFactory.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/client/HttpClientFactory.java Tue Mar 29 18:25:48 2011
@@ -6,15 +6,15 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
- * under the License.
+ * under the License.
*/
package org.apache.tuscany.sca.host.http.client;
@@ -36,14 +36,14 @@ import org.apache.http.params.HttpProtoc
import org.apache.http.protocol.HTTP;
/**
- *
+ * @version $Rev$ $Date$
*/
public class HttpClientFactory {
public HttpClient createHttpClient() {
HttpParams defaultParameters = new BasicHttpParams();
//defaultParameters.setIntParameter(HttpConnectionManagerParams.MAX_TOTAL_CONNECTIONS, 10);
-
+
ConnManagerParams.setMaxTotalConnections(defaultParameters, 160);
// ConnManagerParams.setMaxConnectionsPerRoute(defaultParameters, ConnPerRoute);
@@ -57,8 +57,8 @@ public class HttpClientFactory {
ClientConnectionManager connectionManager =
new ThreadSafeClientConnManager(defaultParameters, supportedSchemes);
-
-
+
+
return new DefaultHttpClient(connectionManager, defaultParameters);
}
Added: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/DefaultHttpPortAllocatorExtensionPoint.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/DefaultHttpPortAllocatorExtensionPoint.java?rev=1086671&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/DefaultHttpPortAllocatorExtensionPoint.java (added)
+++ tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/DefaultHttpPortAllocatorExtensionPoint.java Tue Mar 29 18:25:48 2011
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.http.extensibility;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceHelper;
+
+public class DefaultHttpPortAllocatorExtensionPoint implements HttpPortAllocatorExtensionPoint {
+ private final static Logger logger = Logger.getLogger(DefaultHttpPortAllocatorExtensionPoint.class.getName());
+
+ private ExtensionPointRegistry registry;
+ private List<HttpPortAllocator> portAllocators = new ArrayList<HttpPortAllocator>();
+ private boolean loaded;
+
+ public DefaultHttpPortAllocatorExtensionPoint(ExtensionPointRegistry registry) {
+ this.registry = registry;
+ }
+ public void addPortAllocators(HttpPortAllocator httpPortAllocator) {
+ this.portAllocators.add(httpPortAllocator);
+ }
+
+ public void removePortAllocators(HttpPortAllocator httpPortAllocator) {
+ this.portAllocators.remove(httpPortAllocator);
+ }
+
+ public List<HttpPortAllocator> getPortAllocators() {
+ loadServletHosts();
+ return this.portAllocators;
+ }
+
+ private synchronized void loadServletHosts() {
+ if (loaded)
+ return;
+
+ // Get the activator service declarations
+ Collection<ServiceDeclaration> activatorDeclarations;
+ try {
+ // Load the port allocators by ranking
+ activatorDeclarations = registry.getServiceDiscovery().getServiceDeclarations(HttpPortAllocator.class.getName(), true);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+
+ // Load and instantiate http port allocators
+ for (ServiceDeclaration allocatorDeclaration : activatorDeclarations) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Loading " + allocatorDeclaration.getClassName());
+ }
+ HttpPortAllocator allocator = null;
+ try {
+ Class<HttpPortAllocator> allocatorClass = (Class<HttpPortAllocator>)allocatorDeclaration.loadClass();
+ try {
+ allocator = ServiceHelper.newInstance(allocatorClass, ExtensionPointRegistry.class, registry);
+ } catch (NoSuchMethodException e) {
+ try {
+ allocator =
+ ServiceHelper.newInstance(allocatorClass,
+ new Class<?>[] {ExtensionPointRegistry.class, Map.class},
+ registry,
+ allocatorDeclaration.getAttributes());
+
+ } catch (NoSuchMethodException e1) {
+ allocator = ServiceHelper.newInstance(allocatorClass);
+
+ }
+ }
+ } catch (Throwable e) {
+ String optional = allocatorDeclaration.getAttributes().get("optional");
+ if ("true".equalsIgnoreCase(optional)) {
+ // If the optional flag is true, just log the error
+ logger.log(Level.SEVERE, e.getMessage(), e);
+ continue;
+ } else {
+ throw new IllegalArgumentException(e);
+ }
+ }
+ addPortAllocators(allocator);
+ }
+
+ loaded = true;
+ }
+}
Propchange: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/DefaultHttpPortAllocatorExtensionPoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/DefaultHttpPortAllocatorExtensionPoint.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/ExtensibleHttpPortAllocator.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/ExtensibleHttpPortAllocator.java?rev=1086671&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/ExtensibleHttpPortAllocator.java (added)
+++ tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/ExtensibleHttpPortAllocator.java Tue Mar 29 18:25:48 2011
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.http.extensibility;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.host.http.HttpScheme;
+
+public class ExtensibleHttpPortAllocator implements HttpPortAllocator {
+ HttpPortAllocatorExtensionPoint httpPortAllocators;
+
+ public ExtensibleHttpPortAllocator(ExtensionPointRegistry registry) {
+ this.httpPortAllocators = registry.getExtensionPoint(HttpPortAllocatorExtensionPoint.class);
+ }
+
+ public static ExtensibleHttpPortAllocator getInstance(ExtensionPointRegistry registry) {
+ UtilityExtensionPoint utilityExtensionPoint = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ return utilityExtensionPoint.getUtility(ExtensibleHttpPortAllocator.class);
+ }
+
+ public int getDefaultPort(HttpScheme scheme) {
+ if(this.httpPortAllocators.getPortAllocators().isEmpty()) {
+ throw new RuntimeException("No port allocators registered");
+ }
+
+ return this.httpPortAllocators.getPortAllocators().get(0).getDefaultPort(scheme);
+ }
+}
Propchange: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/ExtensibleHttpPortAllocator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/ExtensibleHttpPortAllocator.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocator.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocator.java?rev=1086671&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocator.java (added)
+++ tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocator.java Tue Mar 29 18:25:48 2011
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.http.extensibility;
+
+import org.apache.tuscany.sca.host.http.HttpScheme;
+
+/**
+ * Allows runtime to query the Http Port to use for a particular Http Scheme (http, https)
+ *
+ * @version $Rev$ $Date$
+ */
+public interface HttpPortAllocator {
+ /**
+ * Get default port for a given http scheme
+ * @param scheme the http scheme in use (http/https)
+ * @return the default port to use
+ */
+ int getDefaultPort(HttpScheme scheme);
+}
Propchange: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocator.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocatorExtensionPoint.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocatorExtensionPoint.java?rev=1086671&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocatorExtensionPoint.java (added)
+++ tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocatorExtensionPoint.java Tue Mar 29 18:25:48 2011
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.http.extensibility;
+
+import java.util.List;
+
+/**
+ * Extension Point to allow registration of different port allocators
+ * @version $Rev$ $Date$
+ */
+public interface HttpPortAllocatorExtensionPoint {
+
+ /**
+ * Register a new http port allocator
+ * @param httpPortAllocator the http port allocator
+ */
+ void addPortAllocators(HttpPortAllocator httpPortAllocator);
+
+ /**
+ * Unregister a http port allocator
+ * @param httpPortAllocator the http port allocator
+ */
+ void removePortAllocators(HttpPortAllocator httpPortAllocator);
+
+ /**
+ * Get a list of all registered http port allocators
+ * @return the list of http port allocators
+ */
+ List<HttpPortAllocator> getPortAllocators();
+}
Propchange: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocatorExtensionPoint.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocatorExtensionPoint.java
------------------------------------------------------------------------------
svn:keywords = Rev Date