summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2011-03-29 18:25:48 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2011-03-29 18:25:48 +0000
commitfaad66a153eb6e04068f821d89f0f671758568c3 (patch)
tree186c1e39017118c07b8bd51f7fa929db346b3918 /sca-java-2.x
parent1eb4fb2f439306dd256d439eb301baed891f3a61 (diff)
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
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1086671 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x')
-rw-r--r--sca-java-2.x/trunk/modules/host-http/META-INF/MANIFEST.MF3
-rw-r--r--sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/HttpScheme.java25
-rw-r--r--sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/client/HttpClientFactory.java14
-rw-r--r--sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/DefaultHttpPortAllocatorExtensionPoint.java108
-rw-r--r--sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/ExtensibleHttpPortAllocator.java45
-rw-r--r--sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocator.java36
-rw-r--r--sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocatorExtensionPoint.java47
7 files changed, 270 insertions, 8 deletions
diff --git a/sca-java-2.x/trunk/modules/host-http/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/host-http/META-INF/MANIFEST.MF
index 2077368e95..c4ccda2499 100644
--- a/sca-java-2.x/trunk/modules/host-http/META-INF/MANIFEST.MF
+++ b/sca-java-2.x/trunk/modules/host-http/META-INF/MANIFEST.MF
@@ -4,7 +4,8 @@ Export-Package: org.apache.tuscany.sca.host.http;version="2.0.0";
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
diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/HttpScheme.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/HttpScheme.java
new file mode 100644
index 0000000000..859b685f3f
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/HttpScheme.java
@@ -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
+}
diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/client/HttpClientFactory.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/client/HttpClientFactory.java
index b3f21728c8..4819107ffd 100644
--- a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/client/HttpClientFactory.java
+++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/client/HttpClientFactory.java
@@ -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.HttpProtocolParams;
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);
}
diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/DefaultHttpPortAllocatorExtensionPoint.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/DefaultHttpPortAllocatorExtensionPoint.java
new file mode 100644
index 0000000000..5c5847f77b
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/DefaultHttpPortAllocatorExtensionPoint.java
@@ -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;
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/ExtensibleHttpPortAllocator.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/ExtensibleHttpPortAllocator.java
new file mode 100644
index 0000000000..c1f3083cf8
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/ExtensibleHttpPortAllocator.java
@@ -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);
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocator.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocator.java
new file mode 100644
index 0000000000..71a164df2e
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocator.java
@@ -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);
+}
diff --git a/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocatorExtensionPoint.java b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocatorExtensionPoint.java
new file mode 100644
index 0000000000..b7e748f217
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/extensibility/HttpPortAllocatorExtensionPoint.java
@@ -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();
+}