You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2010/02/19 04:27:50 UTC

svn commit: r911689 - in /tuscany/sca-java-2.x/trunk: itest/nodes/two-nodes-two-vms-test/ modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/ modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility...

Author: rfeng
Date: Fri Feb 19 03:27:50 2010
New Revision: 911689

URL: http://svn.apache.org/viewvc?rev=911689&view=rev
Log:
Start to add the support to load node factory configuration from external files

Added:
    tuscany/sca-java-2.x/trunk/modules/node-impl/src/test/resources/org/apache/tuscany/sca/node/configuration/test-node-factory.config
Modified:
    tuscany/sca-java-2.x/trunk/itest/nodes/two-nodes-two-vms-test/server.xml
    tuscany/sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java
    tuscany/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ClassLoaderContext.java
    tuscany/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java
    tuscany/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDeclarationParser.java
    tuscany/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java

Modified: tuscany/sca-java-2.x/trunk/itest/nodes/two-nodes-two-vms-test/server.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/itest/nodes/two-nodes-two-vms-test/server.xml?rev=911689&r1=911688&r2=911689&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/itest/nodes/two-nodes-two-vms-test/server.xml (original)
+++ tuscany/sca-java-2.x/trunk/itest/nodes/two-nodes-two-vms-test/server.xml Fri Feb 19 03:27:50 2010
@@ -24,6 +24,8 @@
 		<java classpath="${runtime_classpath}" classname="org.apache.tuscany.sca.node.launcher.NodeMain" fork="true">
 			<arg value="-node"/>
 			<arg value="./server-config.xml"/>
+            <arg value="-ttl"/>
+            <arg value="15000"/>			
 		</java>
 	</target>
 

Modified: tuscany/sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java?rev=911689&r1=911688&r2=911689&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/extensibility-equinox/src/main/java/org/apache/tuscany/sca/extensibility/equinox/EquinoxServiceDiscoverer.java Fri Feb 19 03:27:50 2010
@@ -19,28 +19,20 @@
 
 package org.apache.tuscany.sca.extensibility.equinox;
 
-import static org.apache.tuscany.sca.extensibility.ServiceDeclarationParser.parseDeclaration;
-
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.net.URL;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
 import java.util.Collection;
 import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
-import java.util.Properties;
 import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDeclarationParser;
 import org.apache.tuscany.sca.extensibility.ServiceDiscoverer;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
@@ -302,77 +294,10 @@
                     logger.fine("Reading service provider file: " + url.toExternalForm());
                 }
                 try {
-                    // Allow privileged access to open URL stream. Add FilePermission to added to security
-                    // policy file.
-                    InputStream is;
-                    try {
-                        is = AccessController.doPrivileged(new PrivilegedExceptionAction<InputStream>() {
-                            public InputStream run() throws IOException {
-                                return url.openStream();
-                            }
-                        });
-                    } catch (PrivilegedActionException e) {
-                        throw (IOException)e.getException();
-                    }
-                    if (isPropertyFile) {
-                        // Load as a property file
-                        Properties props = new Properties();
-                        props.load(is);
-                        is.close();
-                        for (Map.Entry<Object, Object> e : props.entrySet()) {
-                            Map<String, String> attributes = new HashMap<String, String>();
-                            String key = (String)e.getKey();
-                            String value = (String)e.getValue();
-                            // Unfortunately, the xalan file only has the classname
-                            if ("".equals(value)) {
-                                value = key;
-                                key = "";
-                            }
-                            if (!"".equals(key)) {
-                                attributes.put(key, value);
-                                attributes.put("uri", key);
-                            }
-                            attributes.putAll(parseDeclaration(value));
-                            ServiceDeclarationImpl descriptor = new ServiceDeclarationImpl(bundle, url, value, attributes);
-                            descriptors.add(descriptor);
-                        }
-                        continue;
-                    }
-                    BufferedReader reader = null;
-                    try {
-                        reader = new BufferedReader(new InputStreamReader(is));
-                        int count = 0;
-                        while (true) {
-                            String line = reader.readLine();
-                            if (line == null)
-                                break;
-                            line = line.trim();
-                            if (!line.startsWith("#") && !"".equals(line)) {
-                                String reg = line.trim();
-                                if (debug) {
-                                    logger.fine("Registering service provider: " + reg);
-                                }
-
-                                Map<String, String> attributes = parseDeclaration(reg);
-                                String className = attributes.get("class");
-                                if (className == null) {
-                                    // Add a unique class name to prevent equals() from returning true
-                                    className = "_class_" + count;
-                                    count++;
-                                }
-                                ServiceDeclarationImpl descriptor =
-                                    new ServiceDeclarationImpl(bundle, url, className, attributes);
-                                descriptors.add(descriptor);
-                            }
-                        }
-                    } finally {
-                        if (reader != null) {
-                            try {
-                                reader.close();
-                            } catch (IOException e) {
-                                // Ignore
-                            }
-                        }
+                    for (Map<String, String> attributes : ServiceDeclarationParser.load(url, isPropertyFile)) {
+                        String className = attributes.get("class");
+                        ServiceDeclarationImpl descriptor = new ServiceDeclarationImpl(bundle, url, className, attributes);
+                        descriptors.add(descriptor);
                     }
                 } catch (IOException e) {
                     logger.log(Level.SEVERE, e.getMessage(), e);

Modified: tuscany/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ClassLoaderContext.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ClassLoaderContext.java?rev=911689&r1=911688&r2=911689&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ClassLoaderContext.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ClassLoaderContext.java Fri Feb 19 03:27:50 2010
@@ -205,4 +205,8 @@
         return loaders;
     }
 
+    public ClassLoader getClassLoader() {
+        return classLoader;
+    }
+
 }

Modified: tuscany/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java?rev=911689&r1=911688&r2=911689&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java Fri Feb 19 03:27:50 2010
@@ -19,26 +19,18 @@
 
 package org.apache.tuscany.sca.extensibility;
 
-import static org.apache.tuscany.sca.extensibility.ServiceDeclarationParser.parseDeclaration;
-
-import java.io.BufferedReader;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
 import java.lang.ref.WeakReference;
 import java.net.URL;
-import java.net.URLConnection;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Properties;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -163,83 +155,10 @@
                     logger.fine("Reading service provider file: " + url.toExternalForm());
                 }
 
-                // Allow privileged access to open URL stream. Add FilePermission to added to security
-                // policy file.
-                InputStream is;
-                try {
-                    is = AccessController.doPrivileged(new PrivilegedExceptionAction<InputStream>() {
-                        public InputStream run() throws IOException {
-                            URLConnection connection = url.openConnection();
-                            // TUSCANY-2539
-                            // Don't cache connections by default to stop Tuscany locking contribution jar files
-                            // done here as this is one of the first places we open a stream and the only way to
-                            // set the default is to set it on an instance of URLConnection
-                            connection.setDefaultUseCaches(false);
-                            connection.setUseCaches(false);
-                            return url.openStream();
-                        }
-                    });
-                } catch (PrivilegedActionException e) {
-                    throw (IOException)e.getException();
-                }
-                if (isPropertyFile) {
-                    // Load as a property file
-                    Properties props = new Properties();
-                    props.load(is);
-                    is.close();
-                    for (Map.Entry<Object, Object> e : props.entrySet()) {
-                        Map<String, String> attributes = new HashMap<String, String>();
-                        String key = (String)e.getKey();
-                        String value = (String)e.getValue();
-                        // Unfortunately, the xalan file only has the classname
-                        if (value == null || "".equals(value)) {
-                            value = key;
-                            key = "";
-                        }
-                        if (!"".equals(key)) {
-                            attributes.put(key, value);
-                            attributes.put("uri", key);
-                        }
-                        attributes.putAll(parseDeclaration(value));
-                        ServiceDeclarationImpl descriptor = new ServiceDeclarationImpl(url, value, attributes);
-                        descriptors.add(descriptor);
-                    }
-                    continue;
-                }
-                BufferedReader reader = null;
-                try {
-                    reader = new BufferedReader(new InputStreamReader(is));
-                    int count = 0;
-                    while (true) {
-                        String line = reader.readLine();
-                        if (line == null)
-                            break;
-                        line = line.trim();
-                        if (!line.startsWith("#") && !"".equals(line)) {
-                            String reg = line.trim();
-                            if (debug) {
-                                logger.fine("Registering service provider: " + reg);
-                            }
-
-                            Map<String, String> attributes = parseDeclaration(reg);
-                            String className = attributes.get("class");
-                            if (className == null) {
-                                // Add a unique class name to prevent equals() from returning true
-                                className = "_class_" + count;
-                                count++;
-                            }
-                            ServiceDeclarationImpl descriptor = new ServiceDeclarationImpl(url, className, attributes);
-                            descriptors.add(descriptor);
-                        }
-                    }
-                } finally {
-                    if (reader != null) {
-                        try {
-                            reader.close();
-                        } catch (IOException e) {
-                            // Ignore
-                        }
-                    }
+                for (Map<String, String> attributes : ServiceDeclarationParser.load(url, isPropertyFile)) {
+                    String className = attributes.get("class");
+                    ServiceDeclarationImpl descriptor = new ServiceDeclarationImpl(url, className, attributes);
+                    descriptors.add(descriptor);
                 }
             }
         } catch (IOException e) {

Modified: tuscany/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDeclarationParser.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDeclarationParser.java?rev=911689&r1=911688&r2=911689&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDeclarationParser.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDeclarationParser.java Fri Feb 19 03:27:50 2010
@@ -19,10 +19,21 @@
 
 package org.apache.tuscany.sca.extensibility;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 
 import javax.xml.namespace.QName;
 
@@ -288,5 +299,77 @@
         }
         return new QName(qname);
     }
+    
+    public static Collection<Map<String, String>> load(final URL url, boolean isPropertyFile) throws IOException {
+        Collection<Map<String, String>> descriptors = new ArrayList<Map<String, String>>();
+
+        // Allow privileged access to open URL stream. Add FilePermission to added to security
+        // policy file.
+        InputStream is;
+        try {
+            is = AccessController.doPrivileged(new PrivilegedExceptionAction<InputStream>() {
+                public InputStream run() throws IOException {
+                    URLConnection connection = url.openConnection();
+                    // TUSCANY-2539
+                    // Don't cache connections by default to stop Tuscany locking contribution jar files
+                    // done here as this is one of the first places we open a stream and the only way to
+                    // set the default is to set it on an instance of URLConnection
+                    connection.setDefaultUseCaches(false);
+                    connection.setUseCaches(false);
+                    return url.openStream();
+                }
+            });
+        } catch (PrivilegedActionException e) {
+            throw (IOException)e.getException();
+        }
+        if (isPropertyFile) {
+            // Load as a property file
+            Properties props = new Properties();
+            props.load(is);
+            is.close();
+            for (Map.Entry<Object, Object> e : props.entrySet()) {
+                Map<String, String> attributes = new HashMap<String, String>();
+                String key = (String)e.getKey();
+                String value = (String)e.getValue();
+                // Unfortunately, the xalan file only has the classname
+                if (value == null || "".equals(value)) {
+                    value = key;
+                    key = "";
+                }
+                if (!"".equals(key)) {
+                    attributes.put(key, value);
+                    attributes.put("uri", key);
+                }
+                attributes.putAll(parseDeclaration(value));
+                descriptors.add(attributes);
+            }
+            return descriptors;
+        }
+        BufferedReader reader = null;
+        try {
+            reader = new BufferedReader(new InputStreamReader(is));
+            while (true) {
+                String line = reader.readLine();
+                if (line == null)
+                    break;
+                line = line.trim();
+                if (!line.startsWith("#") && !"".equals(line)) {
+                    String reg = line.trim();
+
+                    Map<String, String> attributes = parseDeclaration(reg);
+                    descriptors.add(attributes);
+                }
+            }
+        } finally {
+            if (reader != null) {
+                try {
+                    reader.close();
+                } catch (IOException e) {
+                    // Ignore
+                }
+            }
+        }
+        return descriptors;
+    }
 
 }

Modified: tuscany/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java?rev=911689&r1=911688&r2=911689&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java Fri Feb 19 03:27:50 2010
@@ -25,12 +25,15 @@
 import java.io.StringReader;
 import java.net.MalformedURLException;
 import java.net.URI;
+import java.net.URL;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.tuscany.sca.assembly.Endpoint;
 import org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint;
+import org.apache.tuscany.sca.extensibility.ServiceDeclarationParser;
 import org.apache.tuscany.sca.node.Contribution;
 import org.apache.tuscany.sca.node.Node;
 import org.apache.tuscany.sca.node.NodeFactory;
@@ -141,4 +144,13 @@
         Assert.assertEquals(1, mapping.size());
         Assert.assertEquals("multicast://200.0.0.100:50000/MyDomain", mapping.get("urn:MyDomain"));
     }
+    
+    @Test
+    public void testLoadNodeFactoryProperties() throws Exception {
+        URL url = getClass().getResource("/org/apache/tuscany/sca/node/configuration/test-node-factory.config");
+        Collection<Map<String, String>> items = ServiceDeclarationParser.load(url, false);
+        for (Map<String, String> attrs : items) {
+            System.out.println(attrs);
+        }
+    }
 }

Added: tuscany/sca-java-2.x/trunk/modules/node-impl/src/test/resources/org/apache/tuscany/sca/node/configuration/test-node-factory.config
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/node-impl/src/test/resources/org/apache/tuscany/sca/node/configuration/test-node-factory.config?rev=911689&view=auto
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/node-impl/src/test/resources/org/apache/tuscany/sca/node/configuration/test-node-factory.config (added)
+++ tuscany/sca-java-2.x/trunk/modules/node-impl/src/test/resources/org/apache/tuscany/sca/node/configuration/test-node-factory.config Fri Feb 19 03:27:50 2010
@@ -0,0 +1,19 @@
+# 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.
+# Configuration properties for NodeFactory
+org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint;enabled=true,attr="value"
+org.apache.tuscany.sca.runtime.DomainRegistryFactoryExtensionPoint;urn:MyDomain="multicast://200.0.0.100:50000/MyDomain"
\ No newline at end of file