diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-19 16:49:34 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-05-19 16:49:34 +0000 |
commit | 9182bba609947d775130c84f00639d8f0f766e00 (patch) | |
tree | 37df0c96f7eab7b98683c16150f8c0bae52b4cb4 /java/sca/modules/extensibility | |
parent | 08ba6e53202a2b2f20dd8ea6e2a315fb80ff818a (diff) |
Change the NodeFactoryImpl to be capable of hosting multiple instances of SCA node in the same JVM and align the OSGiNodeFactoryImpl to that feature
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@776383 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/extensibility')
-rw-r--r-- | java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java index 7976ea2f7b..131c2b5041 100644 --- a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java +++ b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java @@ -6,20 +6,24 @@ * 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.extensibility; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; import java.util.Set; import java.util.logging.Logger; @@ -27,7 +31,7 @@ import java.util.logging.Logger; * Service discovery for Tuscany based on J2SE Jar service provider spec. * Services are described using configuration files in META-INF/services. * Service description specifies a class name followed by optional properties. - * + * * * @version $Rev$ $Date$ */ @@ -37,14 +41,14 @@ public final class ServiceDiscovery implements ServiceDiscoverer { private final static ServiceDiscovery INSTANCE = new ServiceDiscovery(); private ServiceDiscoverer discoverer; - + private ServiceDiscovery() { super(); } /** * Get an instance of Service discovery, one instance is created per * ClassLoader that this class is loaded from - * + * * @return */ public static ServiceDiscovery getInstance() { @@ -80,8 +84,34 @@ public final class ServiceDiscovery implements ServiceDiscoverer { } public ServiceDeclaration getFirstServiceDeclaration(final String name) throws IOException { - ServiceDeclaration service = getServiceDiscoverer().getFirstServiceDeclaration(name); - return service; + // ServiceDeclaration service = getServiceDiscoverer().getFirstServiceDeclaration(name); + // return service; + Set<ServiceDeclaration> declarations = getServiceDeclarations(name); + if (!declarations.isEmpty()) { + List<ServiceDeclaration> declarationList = new ArrayList<ServiceDeclaration>(declarations); + Collections.sort(declarationList, ServiceComparator.INSTANCE); + return declarationList.get(declarationList.size() - 1); + } else { + return null; + } + } + + private static class ServiceComparator implements Comparator<ServiceDeclaration> { + private final static ServiceComparator INSTANCE = new ServiceComparator(); + + public int compare(ServiceDeclaration o1, ServiceDeclaration o2) { + int rank1 = 0; + String r1 = o1.getAttributes().get("ranking"); + if (r1 != null) { + rank1 = Integer.parseInt(r1); + } + int rank2 = 0; + String r2 = o2.getAttributes().get("ranking"); + if (r2 != null) { + rank2 = Integer.parseInt(r2); + } + return rank1 - rank2; + } } - + } |