From 6c51c6d6f32b9972ed825f1444309212f9d99a21 Mon Sep 17 00:00:00 2001 From: rfeng Date: Tue, 9 Feb 2010 21:20:45 +0000 Subject: Start to clean up the node-api (remove Node.destroy()) git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@908233 13f79535-47bb-0310-9956-ffa450edef68 --- .../tuscany/sca/runtime/BaseEndpointRegistry.java | 2 +- .../tuscany/sca/runtime/CompositeActivator.java | 70 +++++++-- .../tuscany/sca/runtime/DomainRegistryFactory.java | 20 ++- .../DomainRegistryFactoryExtensionPoint.java | 13 +- .../tuscany/sca/runtime/DomainRegistryURI.java | 166 +++++++++++++++++++++ .../tuscany/sca/runtime/EndpointRegistry.java | 2 +- .../sca/runtime/ExtensibleDomainRegistry.java | 2 +- .../org/apache/tuscany/sca/runtime/TuscanyURI.java | 166 --------------------- 8 files changed, 260 insertions(+), 181 deletions(-) create mode 100644 sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryURI.java delete mode 100644 sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/TuscanyURI.java (limited to 'sca-java-2.x/trunk/modules/core-spi/src/main/java') diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseEndpointRegistry.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseEndpointRegistry.java index 8cea5e1423..d45631d576 100644 --- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseEndpointRegistry.java +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/BaseEndpointRegistry.java @@ -199,7 +199,7 @@ public abstract class BaseEndpointRegistry implements EndpointRegistry, LifeCycl listeners.remove(listener); } - public String getDomainName() { + public String getDomainURI() { return domainURI; } diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/CompositeActivator.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/CompositeActivator.java index f4e18f60cc..d9bdc2b6f6 100644 --- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/CompositeActivator.java +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/CompositeActivator.java @@ -36,14 +36,6 @@ public interface CompositeActivator { */ void activate(CompositeContext compositeContext, Composite composite) throws ActivationException; - /** - * Activate a component reference - * @param compositeContext The context of the Node - * @param component - * @param ref - */ - void start(CompositeContext compositeContext, RuntimeComponent component, RuntimeComponentReference ref); - /** * Activate a component reference * @param compositeContext The context of the Node @@ -59,7 +51,7 @@ public interface CompositeActivator { * @param ref */ void activate(CompositeContext compositeContext, RuntimeComponent component, RuntimeComponentService service); - + /** * De-activate a component reference * @param component @@ -80,6 +72,15 @@ public interface CompositeActivator { */ void deactivate(Composite composite) throws ActivationException; + /** + * Start a component reference + * @param compositeContext The context of the Node + * @param component + * @param ref + */ + void start(CompositeContext compositeContext, RuntimeComponent component, RuntimeComponentReference ref); + + /** * Start a component * @param component @@ -104,4 +105,55 @@ public interface CompositeActivator { */ void stop(CompositeContext compositeContext, Composite composite) throws ActivationException; + /** + * Activate an endpoint + * @param compositeContext + * @param endpoint + */ + void activate(CompositeContext compositeContext, RuntimeEndpoint endpoint); + + /** + * Activate an endpoint reference + * @param compositeContext + * @param endpointReference + */ + void activate(CompositeContext compositeContext, RuntimeEndpointReference endpointReference); + + /** + * Deactivate an endpoint + * @param endpoint + */ + void deactivate(RuntimeEndpoint endpoint); + + /** + * Deactivate an endpoint reference + * @param endpointReference + */ + void deactivate(RuntimeEndpointReference endpointReference); + + /** + * Start an endpoint + * @param compositeContext + * @param endpoint + */ + void start(CompositeContext compositeContext, RuntimeEndpoint endpoint); + + /** + * Start an endpoint reference + * @param compositeContext + * @param endpointReference + */ + void start(CompositeContext compositeContext, RuntimeEndpointReference endpointReference); + + /** + * Stop an endpoint + * @param endpoint + */ + void stop(RuntimeEndpoint endpoint); + + /** + * Stop an endpoint reference + * @param endpointReference + */ + void stop(RuntimeEndpointReference endpointReference); } diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactory.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactory.java index bd97a525c0..c79fab1f47 100644 --- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactory.java +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactory.java @@ -22,7 +22,8 @@ package org.apache.tuscany.sca.runtime; import java.util.Collection; /** - * + * A DomainRegistryFactory is responsible for creating an instance of the DomainRegistry for a given + * registry URI and domain URI */ public interface DomainRegistryFactory { /** @@ -33,13 +34,28 @@ public interface DomainRegistryFactory { * @return */ EndpointRegistry getEndpointRegistry(String endpointRegistryURI, String domainURI); - + /** * Return all active endpoint registries * @return */ Collection getEndpointRegistries(); + + /** + * Add an EndpointListener + * @param listener + */ void addListener(EndpointListener listener); + + /** + * Remove an EndpointListener + * @param listener + */ void removeListener(EndpointListener listener); + + /** + * Return an array of schemes that this factory supports + * @return + */ String[] getSupportedSchemes(); } diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactoryExtensionPoint.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactoryExtensionPoint.java index 4b823c0e7d..a373402db4 100644 --- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactoryExtensionPoint.java +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryFactoryExtensionPoint.java @@ -22,12 +22,23 @@ package org.apache.tuscany.sca.runtime; import java.util.List; /** - * + * Extension point for DomainRegistryFactory */ public interface DomainRegistryFactoryExtensionPoint { + /** + * Add a DomainRegistryFactory + * @param factory + */ void addDomainRegistryFactory(DomainRegistryFactory factory); + /** + * Remove a DomainRegistryFactory + * @param factory + */ void removeDomainRegistryFactory(DomainRegistryFactory factory); + /** + * @return A list of DomainRegistryFactory + */ List getDomainRegistryFactories(); } diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryURI.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryURI.java new file mode 100644 index 0000000000..74e5d431ca --- /dev/null +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DomainRegistryURI.java @@ -0,0 +1,166 @@ +/* + * 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.runtime; + +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +/** + * Utility to parse the config uri string. + * + * tuscany:[domainName]?listen=[port|ip:port]]&password=abc&multicast=[off|port|ip:port]&remotes=ip:port,ip:port,... + + * listen - defines the local bind address and port, it defaults to all network interfaces on port 14820 and if that port in use it will try incrementing by one till a free port is found. + * password - is the password other nodes must use to connect to this domain. The default is 'tuscany'. + * multicast - defines if multicast discovery is used and if so what multicast ip group and port is used. + * The default is multicast is off if remotes= is specified (only for now due to a Hazelcast limitation that is planned to be fixed), + * otherwise if remotes= is not specified then multicast defaults to 224.5.12.10:51482 + * remotes - a list of ipAddress:port for remote nodes + * + */ +public class DomainRegistryURI { + + private String domainName = "default"; + private String bindAddress = null; // null means all network adapters + private int listenPort = 14820; + private String password = "tuscany"; + private boolean multicastDisabled = false; + private String multicastAddress = "224.5.12.10"; + private int multicastPort = 51482; + private List remotes = new ArrayList(); + private String uri; + + public DomainRegistryURI(String uri) { + this.uri = uri; + parseURI(uri); + } + + private void parseURI(String uri) { + if (uri.startsWith("tuscanyclient:")) { + uri = uri.replace("tuscanyclient:", "tuscany:"); + } + + if (!uri.startsWith("tuscany:")) { + throw new IllegalArgumentException("Config URI must start with 'tuscany:'"); + } + + // make it a URI so java.net.URI can be used to parse it + int i = uri.indexOf(":"); + if (uri.charAt("tuscany:".length()) != '/') { + uri = uri.replaceFirst(":", ":/"); + } + if (uri.charAt("tuscany:".length()+1) != '/') { + uri = uri.replaceFirst(":/", "://"); + } + URI configURI = URI.create(uri); + + this.domainName = configURI.getHost(); + + String query = configURI.getQuery(); + if (query != null && query.length() > 0) { + String[] params = query.split("&"); + Map paramMap = new HashMap(); + for (String param : params) { + paramMap.put(param.split("=")[0], param.split("=")[1]); + } + for (String name : paramMap.keySet()) { + String value = paramMap.get(name); + if ("listen".equals(name)) { + if (value.indexOf(":") == -1) { + this.listenPort = Integer.parseInt(value); + } else { + String[] addr = value.split(":"); + this.bindAddress = addr[0]; + this.listenPort = Integer.parseInt(addr[1]); + } + } else if ("multicast".equals(name)) { + if ("off".equalsIgnoreCase(value)) { + this.multicastDisabled = true; + } else { + if (value.indexOf(":") == -1) { + this.multicastAddress = value; + } else { + String[] addr = value.split(":"); + this.multicastAddress = addr[0]; + this.multicastPort = Integer.parseInt(addr[1]); + } + } + } else if ("password".equals(name)) { + this.password = value; + } else if ("remotes".equals(name)) { + String[] ips = value.split(","); + for (String ip : ips) { + if (ip.indexOf(":") == -1) { + remotes.add(ip + ":14820"); + } else { + remotes.add(ip); + } + } + if (paramMap.containsKey("multicast")) { + throw new IllegalArgumentException("Cannot have multicast and remotes (for now)"); + } else { + this.multicastDisabled = true; + } + } + } + } + } + + public String getDomainName() { + return domainName; + } + + public String getBindAddress() { + return bindAddress; + } + + public int getListenPort() { + return listenPort; + } + + public String getPassword() { + return password; + } + + public boolean isMulticastDisabled() { + return multicastDisabled; + } + + public String getMulticastAddress() { + return multicastAddress; + } + + public int getMulticastPort() { + return multicastPort; + } + + public List getRemotes() { + return remotes; + } + + public String toString() { + return uri; + } + +} diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java index 0c0c0f2b0e..43388c612a 100644 --- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointRegistry.java @@ -66,5 +66,5 @@ public interface EndpointRegistry { void addListener(EndpointListener listener); void removeListener(EndpointListener listener); - String getDomainName(); + String getDomainURI(); } diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ExtensibleDomainRegistry.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ExtensibleDomainRegistry.java index 62ba7cce8d..7b96903dae 100644 --- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ExtensibleDomainRegistry.java +++ b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ExtensibleDomainRegistry.java @@ -68,7 +68,7 @@ public class ExtensibleDomainRegistry implements DomainRegistryFactory { // See if there is a previously created registry for that domain for (DomainRegistryFactory factory : factories.getDomainRegistryFactories()) { for (EndpointRegistry endpointRegistry : factory.getEndpointRegistries()) { - if (endpointRegistry.getDomainName().equals(domainURI)) { + if (endpointRegistry.getDomainURI().equals(domainURI)) { return endpointRegistry; } } diff --git a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/TuscanyURI.java b/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/TuscanyURI.java deleted file mode 100644 index 2bb22ad634..0000000000 --- a/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/TuscanyURI.java +++ /dev/null @@ -1,166 +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. - */ - -package org.apache.tuscany.sca.runtime; - -import java.net.URI; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - - -/** - * Utility to parse the config uri string. - * - * tuscany:[domainName]?listen=[port|ip:port]]&password=abc&multicast=[off|port|ip:port]&remotes=ip:port,ip:port,... - - * listen - defines the local bind address and port, it defaults to all network interfaces on port 14820 and if that port in use it will try incrementing by one till a free port is found. - * password - is the password other nodes must use to connect to this domain. The default is 'tuscany'. - * multicast - defines if multicast discovery is used and if so what multicast ip group and port is used. - * The default is multicast is off if remotes= is specified (only for now due to a Hazelcast limitation that is planned to be fixed), - * otherwise if remotes= is not specified then multicast defaults to 224.5.12.10:51482 - * remotes - a list of ipAddress:port for remote nodes - * - */ -public class TuscanyURI { - - private String domainName = "default"; - private String bindAddress = null; // null means all network adapters - private int listenPort = 14820; - private String password = "tuscany"; - private boolean multicastDisabled = false; - private String multicastAddress = "224.5.12.10"; - private int multicastPort = 51482; - private List remotes = new ArrayList(); - private String uri; - - public TuscanyURI(String uri) { - this.uri = uri; - parseURI(uri); - } - - private void parseURI(String uri) { - if (uri.startsWith("tuscanyclient:")) { - uri = uri.replace("tuscanyclient:", "tuscany:"); - } - - if (!uri.startsWith("tuscany:")) { - throw new IllegalArgumentException("Config URI must start with 'tuscany:'"); - } - - // make it a URI so java.net.URI can be used to parse it - int i = uri.indexOf(":"); - if (uri.charAt("tuscany:".length()) != '/') { - uri = uri.replaceFirst(":", ":/"); - } - if (uri.charAt("tuscany:".length()+1) != '/') { - uri = uri.replaceFirst(":/", "://"); - } - URI configURI = URI.create(uri); - - this.domainName = configURI.getHost(); - - String query = configURI.getQuery(); - if (query != null && query.length() > 0) { - String[] params = query.split("&"); - Map paramMap = new HashMap(); - for (String param : params) { - paramMap.put(param.split("=")[0], param.split("=")[1]); - } - for (String name : paramMap.keySet()) { - String value = paramMap.get(name); - if ("listen".equals(name)) { - if (value.indexOf(":") == -1) { - this.listenPort = Integer.parseInt(value); - } else { - String[] addr = value.split(":"); - this.bindAddress = addr[0]; - this.listenPort = Integer.parseInt(addr[1]); - } - } else if ("multicast".equals(name)) { - if ("off".equalsIgnoreCase(value)) { - this.multicastDisabled = true; - } else { - if (value.indexOf(":") == -1) { - this.multicastAddress = value; - } else { - String[] addr = value.split(":"); - this.multicastAddress = addr[0]; - this.multicastPort = Integer.parseInt(addr[1]); - } - } - } else if ("password".equals(name)) { - this.password = value; - } else if ("remotes".equals(name)) { - String[] ips = value.split(","); - for (String ip : ips) { - if (ip.indexOf(":") == -1) { - remotes.add(ip + ":14820"); - } else { - remotes.add(ip); - } - } - if (paramMap.containsKey("multicast")) { - throw new IllegalArgumentException("Cannot have multicast and remotes (for now)"); - } else { - this.multicastDisabled = true; - } - } - } - } - } - - public String getDomainName() { - return domainName; - } - - public String getBindAddress() { - return bindAddress; - } - - public int getListenPort() { - return listenPort; - } - - public String getPassword() { - return password; - } - - public boolean isMulticastDisabled() { - return multicastDisabled; - } - - public String getMulticastAddress() { - return multicastAddress; - } - - public int getMulticastPort() { - return multicastPort; - } - - public List getRemotes() { - return remotes; - } - - public String toString() { - return uri; - } - -} -- cgit v1.2.3