You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2007/11/19 16:48:04 UTC
svn commit: r596337 - in /servicemix/branches/servicemix-4.0/jbi:
deployer/src/main/java/org/apache/servicemix/jbi/deployer/
deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ itests/
itests/src/test/java/org/apache/servicemix/jbi/ itests/...
Author: gnodet
Date: Mon Nov 19 07:48:03 2007
New Revision: 596337
URL: http://svn.apache.org/viewvc?rev=596337&view=rev
Log:
Improvements on the JBI 1.0 layer
Added:
servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceAssembly.java
servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java
Modified:
servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/SharedLibrary.java
servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/SharedLibraryImpl.java
servicemix/branches/servicemix-4.0/jbi/itests/ (props changed)
servicemix/branches/servicemix-4.0/jbi/itests/pom.xml
servicemix/branches/servicemix-4.0/jbi/itests/src/test/java/org/apache/servicemix/jbi/IntegrationTest.java
servicemix/branches/servicemix-4.0/jbi/itests/src/test/resources/log4j.properties
servicemix/branches/servicemix-4.0/jbi/itests/src/test/resources/org/apache/servicemix/MANIFEST.MF
servicemix/branches/servicemix-4.0/jbi/offline/pom.xml
Added: servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceAssembly.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceAssembly.java?rev=596337&view=auto
==============================================================================
--- servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceAssembly.java (added)
+++ servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/ServiceAssembly.java Mon Nov 19 07:48:03 2007
@@ -0,0 +1,24 @@
+/*
+ * 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.servicemix.jbi.deployer;
+
+/**
+ * This interface represents a JBI Service Assembly and will be registered
+ * in the OSGi registry
+ */
+public interface ServiceAssembly {
+}
Modified: servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/SharedLibrary.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/SharedLibrary.java?rev=596337&r1=596336&r2=596337&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/SharedLibrary.java (original)
+++ servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/SharedLibrary.java Mon Nov 19 07:48:03 2007
@@ -1,20 +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.servicemix.jbi.deployer;
/**
- * Created by IntelliJ IDEA.
- * User: gnodet
- * Date: Nov 8, 2007
- * Time: 1:01:27 PM
- * To change this template use File | Settings | File Templates.
+ * This interface represents a JBI Shared Library and will be registered in
+ * the OSGi registry
*/
public interface SharedLibrary {
+ /**
+ * Retrieves the name of this shared library
+ * @return the name
+ */
String getName();
+ /**
+ * Retrieves the description of this shared library
+ * @return the description
+ */
String getDescription();
+ /**
+ * Retrieves the version of this shared library
+ * @return the version
+ */
String getVersion();
+ /**
+ * Create a classloader for this shared library
+ * @return a new classloader
+ */
ClassLoader createClassLoader();
}
Modified: servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java?rev=596337&r1=596336&r2=596337&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java (original)
+++ servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java Mon Nov 19 07:48:03 2007
@@ -101,7 +101,11 @@
LOGGER.debug("Bundle '" + event.getBundle().getSymbolicName() + "' is a JBI shared library");
SharedLibraryImpl sl = new SharedLibraryImpl(descriptor.getSharedLibrary(), event.getBundle());
sharedLibraries.put(sl.getName(), sl);
- //context.registerService(SharedLibrary.class.getName(), sl, new Properties());
+ Dictionary<String, String> props = new Hashtable<String, String>();
+ // populate props from the library meta-data
+ props.put(NAME, descriptor.getSharedLibrary().getIdentification().getName());
+ LOGGER.debug("Registering JBI Shared Library");
+ context.registerService(SharedLibrary.class.getName(), sl, props);
} else {
// WARN: unhandled JBI artifact
}
Added: servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java?rev=596337&view=auto
==============================================================================
--- servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java (added)
+++ servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyImpl.java Mon Nov 19 07:48:03 2007
@@ -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.servicemix.jbi.deployer.impl;
+
+import org.apache.servicemix.jbi.deployer.ServiceAssembly;
+
+/**
+ * ServiceAssembly object
+ */
+public class ServiceAssemblyImpl implements ServiceAssembly {
+}
Modified: servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/SharedLibraryImpl.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/SharedLibraryImpl.java?rev=596337&r1=596336&r2=596337&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/SharedLibraryImpl.java (original)
+++ servicemix/branches/servicemix-4.0/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/SharedLibraryImpl.java Mon Nov 19 07:48:03 2007
@@ -1,3 +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.
+ */
package org.apache.servicemix.jbi.deployer.impl;
import java.io.File;
@@ -12,11 +28,7 @@
import org.springframework.osgi.internal.context.support.BundleDelegatingClassLoader;
/**
- * Created by IntelliJ IDEA.
- * User: gnodet
- * Date: Nov 8, 2007
- * Time: 1:06:00 PM
- * To change this template use File | Settings | File Templates.
+ * SharedLibrary object
*/
public class SharedLibraryImpl implements SharedLibrary {
Propchange: servicemix/branches/servicemix-4.0/jbi/itests/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Nov 19 07:48:03 2007
@@ -2,3 +2,4 @@
*.iml
*.ipr
*.iws
+eclipse_config
Modified: servicemix/branches/servicemix-4.0/jbi/itests/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/jbi/itests/pom.xml?rev=596337&r1=596336&r2=596337&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/jbi/itests/pom.xml (original)
+++ servicemix/branches/servicemix-4.0/jbi/itests/pom.xml Mon Nov 19 07:48:03 2007
@@ -262,21 +262,6 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.compendium</artifactId>
- <version>0.9.0-SNAPSHOT</version>
- <exclusions>
- <exclusion>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.osgi.core</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.osgi.foundation</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.apache.felix</groupId>
- <artifactId>javax.servlet</artifactId>
- </exclusion>
- </exclusions>
</dependency>
<dependency>
<groupId>org.ops4j.pax.logging</groupId>
@@ -288,12 +273,14 @@
<artifactId>pax-logging-service</artifactId>
<version>0.9.7-SNAPSHOT</version>
</dependency>
+ <!--
<dependency>
<groupId>org.apache.servicemix</groupId>
<artifactId>servicemix-eip</artifactId>
<classifier>installer</classifier>
<type>zip</type>
<version>3.2.1-SNAPSHOT</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.servicemix</groupId>
@@ -301,7 +288,9 @@
<classifier>installer</classifier>
<type>zip</type>
<version>3.2.1-SNAPSHOT</version>
+ <scope>provided</scope>
</dependency>
+ -->
</dependencies>
<build>
@@ -317,6 +306,39 @@
<goals>
<goal>generate-depends-file</goal>
</goals>
+ </execution>
+ </executions>
+ </plugin>
+ <!-- Copy shared library and component -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>dependency-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-components</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>target/components</outputDirectory>
+ <artifactItems>
+ <artifactItem>
+ <groupId>org.apache.servicemix</groupId>
+ <artifactId>servicemix-shared-compat</artifactId>
+ <version>3.2.1-SNAPSHOT</version>
+ <classifier>installer</classifier>
+ <type>zip</type>
+ </artifactItem>
+ <artifactItem>
+ <groupId>org.apache.servicemix</groupId>
+ <artifactId>servicemix-eip</artifactId>
+ <version>3.2.1-SNAPSHOT</version>
+ <classifier>installer</classifier>
+ <type>zip</type>
+ </artifactItem>
+ </artifactItems>
+ </configuration>
</execution>
</executions>
</plugin>
Modified: servicemix/branches/servicemix-4.0/jbi/itests/src/test/java/org/apache/servicemix/jbi/IntegrationTest.java
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/jbi/itests/src/test/java/org/apache/servicemix/jbi/IntegrationTest.java?rev=596337&r1=596336&r2=596337&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/jbi/itests/src/test/java/org/apache/servicemix/jbi/IntegrationTest.java (original)
+++ servicemix/branches/servicemix-4.0/jbi/itests/src/test/java/org/apache/servicemix/jbi/IntegrationTest.java Mon Nov 19 07:48:03 2007
@@ -18,12 +18,23 @@
import java.io.File;
import java.io.FileInputStream;
+import java.io.FilenameFilter;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Properties;
+import javax.jbi.component.Component;
+
import org.apache.servicemix.jbi.offline.Main;
+import org.apache.servicemix.nmr.api.NMR;
import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
import org.springframework.osgi.test.AbstractConfigurableBundleCreatorTests;
+import org.springframework.osgi.util.OsgiFilterUtils;
+import org.springframework.osgi.util.OsgiListenerUtils;
+import org.springframework.osgi.internal.util.concurrent.Counter;
public class IntegrationTest extends AbstractConfigurableBundleCreatorTests {
@@ -122,20 +133,23 @@
return null;
}
- /**
- * The superclass provides us access to the root bundle
- * context via the 'getBundleContext' operation
- */
- public void testOSGiStartedOk() {
- assertNotNull(bundleContext);
- }
-
public void testJbiComponent() throws Exception {
- // Test currently fails
- installArtifact("org.apache.servicemix", "servicemix-shared-compat", "installer", "zip");
- installArtifact("org.apache.servicemix", "servicemix-eip", "installer", "zip");
+ System.out.println("Waiting for NMR");
+ NMR nmr = getOsgiService(NMR.class);
+ assertNotNull(nmr);
+ installBundle(getArtifact("servicemix-shared-compat"));
+ installBundle(getArtifact("servicemix-eip"));
+ System.out.println("Waiting for JBI Component");
+ Component cmp = (Component) getOsgiService(Component.class);
+ assertNotNull(cmp);
+ }
- Thread.sleep(1000);
+ protected File getArtifact(final String id) {
+ return new File("target/components/").listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.startsWith(id);
+ }
+ })[0];
}
protected void installArtifact(String groupId, String artifactId, String classifier, String type) throws Exception {
@@ -143,7 +157,16 @@
File in = localMavenBundle(groupId, artifactId, version, classifier, type);
File out = File.createTempFile("smx", ".jar");
new Main().run(in.toString(), out.toString());
- Bundle bundle = bundleContext.installBundle(out.toURI().toString());
+ installBundle(out);
+ }
+
+ protected void installBundle(File file) throws Exception {
+ installBundle(file.getAbsoluteFile().toURI().toString());
+ }
+
+ protected void installBundle(String uri) throws Exception {
+ System.out.println("Installing bundle " + uri);
+ Bundle bundle = bundleContext.installBundle(uri);
bundle.start();
}
@@ -168,6 +191,98 @@
location.append(type);
return new File(repositoryHome, location.toString());
+ }
+
+ public <T> T getOsgiService(Class<T> type) {
+ return getOsgiService(type, DEFAULT_WAIT_TIME);
+ }
+
+ public <T> T getOsgiService(Class<T> type, long timeout) {
+ // translate from seconds to miliseconds
+ long time = timeout * 1000;
+
+ // use the counter to make sure the threads block
+ final Counter counter = new Counter("waitForOsgiService on bnd=" + type.getName());
+
+ counter.increment();
+
+ final List<T> services = new ArrayList<T>();
+
+ ServiceListener listener = new ServiceListener() {
+ public void serviceChanged(ServiceEvent event) {
+ if (event.getType() == ServiceEvent.REGISTERED) {
+ services.add((T) bundleContext.getService(event.getServiceReference()));
+ counter.decrement();
+ }
+ }
+ };
+
+ String filter = OsgiFilterUtils.unifyFilter(type.getName(), null);
+ OsgiListenerUtils.addServiceListener(bundleContext, listener, filter);
+
+ if (logger.isDebugEnabled())
+ logger.debug("start waiting for OSGi service=" + type.getName());
+
+ try {
+ if (counter.waitForZero(time)) {
+ logger.warn("waiting for OSGi service=" + type.getName() + " timed out");
+ throw new RuntimeException("Gave up waiting for OSGi service '" + type.getName() + "' to be created");
+ }
+ else if (logger.isDebugEnabled()) {
+ logger.debug("found OSGi service=" + type.getName());
+ }
+ return services.get(0);
+ }
+ finally {
+ // inform waiting thread
+ bundleContext.removeServiceListener(listener);
+ }
+ }
+
+ /**
+ * Place the current (test) thread to wait for the a Spring application
+ * context to be published under the given symbolic name. This method allows
+ * waiting for full initialization of Spring OSGi bundles before starting
+ * the actual test execution.
+ *
+ * @param interfaceName
+ * @param timeout
+ */
+ public void waitForOsgiService(String interfaceName, long timeout) {
+ // translate from seconds to miliseconds
+ long time = timeout * 1000;
+
+ // use the counter to make sure the threads block
+ final Counter counter = new Counter("waitForOsgiService on bnd=" + interfaceName);
+
+ counter.increment();
+
+ ServiceListener listener = new ServiceListener() {
+ public void serviceChanged(ServiceEvent event) {
+ if (event.getType() == ServiceEvent.REGISTERED)
+ counter.decrement();
+ }
+ };
+
+ String filter = OsgiFilterUtils.unifyFilter(interfaceName, null);
+ OsgiListenerUtils.addServiceListener(bundleContext, listener, filter);
+
+ if (logger.isDebugEnabled())
+ logger.debug("start waiting for OSGi service=" + interfaceName);
+
+ try {
+ if (counter.waitForZero(time)) {
+ logger.warn("waiting for OSGi service=" + interfaceName + " timed out");
+ throw new RuntimeException("Gave up waiting for OSGi service '" + interfaceName + "' to be created");
+ }
+ else if (logger.isDebugEnabled()) {
+ logger.debug("found OSGi service=" + interfaceName);
+ }
+ }
+ finally {
+ // inform waiting thread
+ bundleContext.removeServiceListener(listener);
+ }
}
}
Modified: servicemix/branches/servicemix-4.0/jbi/itests/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/jbi/itests/src/test/resources/log4j.properties?rev=596337&r1=596336&r2=596337&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/jbi/itests/src/test/resources/log4j.properties (original)
+++ servicemix/branches/servicemix-4.0/jbi/itests/src/test/resources/log4j.properties Mon Nov 19 07:48:03 2007
@@ -16,7 +16,7 @@
#
################################################################################
-log4j.rootLogger=WARN, stdout
+log4j.rootLogger=DEBUG, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
Modified: servicemix/branches/servicemix-4.0/jbi/itests/src/test/resources/org/apache/servicemix/MANIFEST.MF
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/jbi/itests/src/test/resources/org/apache/servicemix/MANIFEST.MF?rev=596337&r1=596336&r2=596337&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/jbi/itests/src/test/resources/org/apache/servicemix/MANIFEST.MF (original)
+++ servicemix/branches/servicemix-4.0/jbi/itests/src/test/resources/org/apache/servicemix/MANIFEST.MF Mon Nov 19 07:48:03 2007
@@ -21,8 +21,12 @@
Bundle-Activator: org.springframework.osgi.test.JUnitTestActivator
Import-Package: junit.framework,
org.osgi.framework;specification-version="1.3.0",
+ org.apache.commons.logging,
org.springframework.core.io,
org.springframework.osgi.test,
+ org.springframework.osgi.internal.util.concurrent,
org.apache.servicemix.nmr.api,
org.apache.servicemix.nmr.core,
- org.apache.servicemix.jbi.offline
+ org.apache.servicemix.jbi.offline,
+ org.springframework.osgi.util,
+ javax.jbi.component
Modified: servicemix/branches/servicemix-4.0/jbi/offline/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/branches/servicemix-4.0/jbi/offline/pom.xml?rev=596337&r1=596336&r2=596337&view=diff
==============================================================================
--- servicemix/branches/servicemix-4.0/jbi/offline/pom.xml (original)
+++ servicemix/branches/servicemix-4.0/jbi/offline/pom.xml Mon Nov 19 07:48:03 2007
@@ -58,6 +58,7 @@
<classifier>installer</classifier>
<type>zip</type>
<version>3.1.2</version>
+ <scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>