From 40aa7960a748c80a2465d5ca78e8f91d43296c8e Mon Sep 17 00:00:00 2001 From: rfeng Date: Fri, 29 Jan 2010 03:34:21 +0000 Subject: Refactor the DomainRegistryFactory to be extensions of DomainRegistryFactoryExtensionPoint git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@904367 13f79535-47bb-0310-9956-ffa450edef68 --- .../hazelcast/HazelcastDomainRegistryFactory.java | 49 +++++++++ .../hazelcast/HazelcastEndpointRegistry.java | 116 ++------------------- ...pache.tuscany.sca.runtime.DomainRegistryFactory | 17 +++ ...org.apache.tuscany.sca.runtime.EndpointRegistry | 18 ---- 4 files changed, 73 insertions(+), 127 deletions(-) create mode 100644 sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastDomainRegistryFactory.java create mode 100644 sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory delete mode 100644 sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry (limited to 'sca-java-2.x/trunk/modules/endpoint-hazelcast') diff --git a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastDomainRegistryFactory.java b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastDomainRegistryFactory.java new file mode 100644 index 0000000000..a4e2da8be3 --- /dev/null +++ b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastDomainRegistryFactory.java @@ -0,0 +1,49 @@ +/* + * 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.endpoint.hazelcast; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.runtime.BaseDomainRegistryFactory; +import org.apache.tuscany.sca.runtime.EndpointRegistry; + +/** + * The utility responsible for finding the endpoint regstry by the scheme and creating instances for the + * given domain + */ +public class HazelcastDomainRegistryFactory extends BaseDomainRegistryFactory { + private final static String[] schemes = new String[] {"multicast", "wka", "tuscany", "hazelcast"}; + + /** + * @param extensionRegistry + */ + public HazelcastDomainRegistryFactory(ExtensionPointRegistry registry) { + super(registry); + } + + protected EndpointRegistry createEndpointRegistry(String endpointRegistryURI, String domainURI) { + EndpointRegistry endpointRegistry = + new HazelcastEndpointRegistry(registry, null, endpointRegistryURI, domainURI); + return endpointRegistry; + } + + public String[] getSupportedSchemes() { + return schemes; + } +} diff --git a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java index 7722a157f0..e50f0511cf 100644 --- a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java +++ b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/java/org/apache/tuscany/sca/endpoint/hazelcast/HazelcastEndpointRegistry.java @@ -24,14 +24,12 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.CopyOnWriteArrayList; import java.util.logging.Logger; import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.LifeCycleListener; -import org.apache.tuscany.sca.runtime.EndpointListener; +import org.apache.tuscany.sca.runtime.BaseEndpointRegistry; import org.apache.tuscany.sca.runtime.EndpointRegistry; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; @@ -50,24 +48,20 @@ import com.hazelcast.nio.Address; /** * An EndpointRegistry using a Hazelcast */ -public class HazelcastEndpointRegistry implements EndpointRegistry, LifeCycleListener, EntryListener, MembershipListener { +public class HazelcastEndpointRegistry extends BaseEndpointRegistry implements EndpointRegistry, LifeCycleListener, EntryListener, MembershipListener { private final static Logger logger = Logger.getLogger(HazelcastEndpointRegistry.class.getName()); - private List endpointreferences = new CopyOnWriteArrayList(); - private List listeners = new CopyOnWriteArrayList(); - - private ExtensionPointRegistry registry; protected ConfigURI configURI; private HazelcastInstance hazelcastInstance; protected Map map; - private List localEndpoints = new ArrayList();; + private List localEndpoints = new ArrayList(); public HazelcastEndpointRegistry(ExtensionPointRegistry registry, Map attributes, String domainRegistryURI, String domainURI) { - this.registry = registry; + super(registry, attributes, domainRegistryURI, domainURI); this.configURI = new ConfigURI(domainRegistryURI); } @@ -143,68 +137,6 @@ public class HazelcastEndpointRegistry implements EndpointRegistry, LifeCycleLis logger.info("Add endpoint - " + endpoint); } - public void addEndpointReference(EndpointReference endpointReference) { - endpointreferences.add(endpointReference); - logger.fine("Add endpoint reference - " + endpointReference); - } - - public void addListener(EndpointListener listener) { - listeners.add(listener); - } - - /** - * Parse the component/service/binding URI into an array of parts (componentURI, serviceName, bindingName) - * @param uri - * @return - */ - private String[] parse(String uri) { - String[] names = new String[3]; - int index = uri.lastIndexOf('#'); - if (index == -1) { - names[0] = uri; - } else { - names[0] = uri.substring(0, index); - String str = uri.substring(index + 1); - if (str.startsWith("service-binding(") && str.endsWith(")")) { - str = str.substring("service-binding(".length(), str.length() - 1); - String[] parts = str.split("/"); - if (parts.length != 2) { - throw new IllegalArgumentException("Invalid service-binding URI: " + uri); - } - names[1] = parts[0]; - names[2] = parts[1]; - } else if (str.startsWith("service(") && str.endsWith(")")) { - str = str.substring("service(".length(), str.length() - 1); - names[1] = str; - } else { - throw new IllegalArgumentException("Invalid component/service/binding URI: " + uri); - } - } - return names; - } - - private boolean matches(String target, String uri) { - String[] parts1 = parse(target); - String[] parts2 = parse(uri); - for (int i = 0; i < parts1.length; i++) { - if (parts1[i] == null || parts1[i].equals(parts2[i])) { - continue; - } else { - return false; - } - } - return true; - } - - public List findEndpoint(EndpointReference endpointReference) { - logger.fine("Find endpoint for reference - " + endpointReference); - if (endpointReference.getReference() != null) { - Endpoint targetEndpoint = endpointReference.getTargetEndpoint(); - return findEndpoint(targetEndpoint.getURI()); - } - return new ArrayList(); - } - public List findEndpoint(String uri) { List foundEndpoints = new ArrayList(); for (Object v : map.values()) { @@ -227,45 +159,20 @@ public class HazelcastEndpointRegistry implements EndpointRegistry, LifeCycleLis return localEndpoints.contains(endpoint.getURI()); } - public List findEndpointReference(Endpoint endpoint) { - return endpointreferences; - } - public Endpoint getEndpoint(String uri) { return (Endpoint)map.get(uri); } - public List getEndpointReferences() { - return endpointreferences; - } - public List getEndpoints() { return new ArrayList(map.values()); } - public List getListeners() { - return listeners; - } - public void removeEndpoint(Endpoint endpoint) { map.remove(endpoint.getURI()); localEndpoints.remove(endpoint.getURI()); logger.info("Removed endpoint - " + endpoint); } - public void removeEndpointReference(EndpointReference endpointReference) { - endpointreferences.remove(endpointReference); - logger.fine("Remove endpoint reference - " + endpointReference); - } - - public void removeListener(EndpointListener listener) { - listeners.remove(listener); - } - - public void updateEndpoint(String uri, Endpoint endpoint) { - // // TODO: is updateEndpoint needed? - // throw new UnsupportedOperationException(); - } public void entryAdded(EntryEvent event) { entryAdded(event.getKey(), event.getValue()); @@ -289,10 +196,7 @@ public class HazelcastEndpointRegistry implements EndpointRegistry, LifeCycleLis logger.info(" Remote endpoint added: " + newEp); newEp.setRemote(true); } - ((RuntimeEndpoint)newEp).bind(registry, this); - for (EndpointListener listener : listeners) { - listener.endpointAdded(newEp); - } + endpointAdded(newEp); } public void entryRemoved(Object key, Object value) { @@ -300,10 +204,7 @@ public class HazelcastEndpointRegistry implements EndpointRegistry, LifeCycleLis if (!isLocal(oldEp)) { logger.info(" Remote endpoint removed: " + value); } - ((RuntimeEndpoint) oldEp).bind(registry, this); - for (EndpointListener listener : listeners) { - listener.endpointRemoved(oldEp); - } + endpointRemoved(oldEp); } public void entryUpdated(Object key, Object oldValue, Object newValue) { @@ -312,10 +213,7 @@ public class HazelcastEndpointRegistry implements EndpointRegistry, LifeCycleLis if (!isLocal(newEp)) { logger.info(" Remote endpoint updated: " + newEp); } - ((RuntimeEndpoint)newEp).bind(registry, this); - for (EndpointListener listener : listeners) { - listener.endpointUpdated(oldEp, newEp); - } + endpointUpdated(oldEp, newEp); } public void memberAdded(MembershipEvent event) { diff --git a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory new file mode 100644 index 0000000000..23551701a5 --- /dev/null +++ b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.DomainRegistryFactory @@ -0,0 +1,17 @@ +# 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. +org.apache.tuscany.sca.endpoint.hazelcast.HazelcastDomainRegistryFactory;ranking=100 diff --git a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry b/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry deleted file mode 100644 index 1983881ce1..0000000000 --- a/sca-java-2.x/trunk/modules/endpoint-hazelcast/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.EndpointRegistry +++ /dev/null @@ -1,18 +0,0 @@ -# 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. -org.apache.tuscany.sca.endpoint.hazelcast.HazelcastEndpointRegistry;ranking=150,scheme=tuscany - -- cgit v1.2.3