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 2009/03/09 18:03:34 UTC
svn commit: r751759 - in /servicemix/smx4/nmr/trunk: jbi/osgi/
jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/
jbi/osgi/src/main/resources/META-INF/spring/ nmr/osgi/
nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/
nmr/osgi/src/main/resour...
Author: gnodet
Date: Mon Mar 9 17:03:33 2009
New Revision: 751759
URL: http://svn.apache.org/viewvc?rev=751759&view=rev
Log:
SMX4NMR-115: Do not use spring proxies for tracking endpoints and other NMR lists
Added:
servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/OsgiServiceRegistryTracker.java
Modified:
servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml
servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/RegistryWrapper.java
servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/META-INF/spring/servicemix-jbi.xml
servicemix/smx4/nmr/trunk/nmr/osgi/pom.xml
servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/META-INF/spring/servicemix-nmr.xml
Modified: servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml?rev=751759&r1=751758&r2=751759&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml Mon Mar 9 17:03:33 2009
@@ -45,6 +45,10 @@
<artifactId>org.apache.servicemix.jbi.deployer</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.servicemix.nmr</groupId>
+ <artifactId>org.apache.servicemix.nmr.osgi</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
@@ -66,6 +70,7 @@
org.apache.geronimo.transaction.manager;resolution:=optional,
org.apache.servicemix.document,
org.apache.servicemix.nmr.api,
+ org.apache.servicemix.nmr.osgi,
org.apache.servicemix.jbi.runtime,
org.apache.servicemix.jbi.runtime.impl,
org.apache.servicemix.jbi.osgi,
Modified: servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/RegistryWrapper.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/RegistryWrapper.java?rev=751759&r1=751758&r2=751759&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/RegistryWrapper.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/RegistryWrapper.java Mon Mar 9 17:03:33 2009
@@ -16,20 +16,20 @@
*/
package org.apache.servicemix.jbi.osgi;
-import java.util.Map;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.w3c.dom.Document;
-import org.apache.servicemix.nmr.api.EndpointRegistry;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.nmr.api.Endpoint;
+import org.apache.servicemix.nmr.api.EndpointRegistry;
import org.apache.servicemix.nmr.api.Reference;
-import org.apache.servicemix.nmr.api.Wire;
+import org.apache.servicemix.nmr.api.internal.InternalEndpoint;
import org.apache.servicemix.nmr.core.util.MapToDictionary;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
@@ -48,7 +48,7 @@
private EndpointRegistry registry;
private BundleContext bundleContext;
- private Map<Endpoint, ServiceRegistration> registrations = new ConcurrentHashMap();
+ private Map<Endpoint, ServiceRegistration> registrations = new ConcurrentHashMap<Endpoint, ServiceRegistration>();
public RegistryWrapper(EndpointRegistry registry, BundleContext bundleContext) {
this.registry = registry;
@@ -65,10 +65,14 @@
public void unregister(Endpoint endpoint, Map<String, ?> properties) {
ServiceRegistration reg = registrations.remove(endpoint);
+ if (reg == null && endpoint instanceof InternalEndpoint) {
+ reg = registrations.remove(((InternalEndpoint) endpoint).getEndpoint());
+ }
if (reg != null) {
reg.unregister();
} else {
LOG.warn("Unregistration failed: the endpoint was not found in registry: " + endpoint + " (" + properties + ")");
+ registry.unregister(endpoint, properties);
}
}
Modified: servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/META-INF/spring/servicemix-jbi.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/META-INF/spring/servicemix-jbi.xml?rev=751759&r1=751758&r2=751759&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/META-INF/spring/servicemix-jbi.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/META-INF/spring/servicemix-jbi.xml Mon Mar 9 17:03:33 2009
@@ -55,11 +55,10 @@
</bean>
<!-- Service tracker for JBI components -->
- <osgi:list id="components"
- interface="org.apache.servicemix.jbi.runtime.ComponentWrapper"
- cardinality="0..N">
- <osgi:listener ref="componentRegistry" bind-method="register" unbind-method="unregister" />
- </osgi:list>
+ <bean class="org.apache.servicemix.nmr.osgi.OsgiServiceRegistryTracker">
+ <property name="interface" value="org.apache.servicemix.jbi.runtime.ComponentWrapper" />
+ <property name="registry" ref="componentRegistry" />
+ </bean>
<!-- Reference to the ServiceMix NMR -->
<osgi:reference id="nmr"
Modified: servicemix/smx4/nmr/trunk/nmr/osgi/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/osgi/pom.xml?rev=751759&r1=751758&r2=751759&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/osgi/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/nmr/osgi/pom.xml Mon Mar 9 17:03:33 2009
@@ -54,6 +54,11 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.apache.servicemix.bundles</groupId>
<artifactId>org.apache.servicemix.bundles.junit</artifactId>
<scope>test</scope>
Added: servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/OsgiServiceRegistryTracker.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/OsgiServiceRegistryTracker.java?rev=751759&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/OsgiServiceRegistryTracker.java (added)
+++ servicemix/smx4/nmr/trunk/nmr/osgi/src/main/java/org/apache/servicemix/nmr/osgi/OsgiServiceRegistryTracker.java Mon Mar 9 17:03:33 2009
@@ -0,0 +1,76 @@
+package org.apache.servicemix.nmr.osgi;
+
+import java.util.Map;
+
+import org.apache.servicemix.nmr.api.service.ServiceRegistry;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+import org.springframework.beans.factory.DisposableBean;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.osgi.context.BundleContextAware;
+import org.springframework.osgi.util.OsgiServiceReferenceUtils;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: gnodet
+ * Date: Mar 9, 2009
+ * Time: 3:05:46 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public class OsgiServiceRegistryTracker<T> implements BundleContextAware, InitializingBean, DisposableBean, ServiceTrackerCustomizer {
+
+ private BundleContext bundleContext;
+ private ServiceRegistry<T> registry;
+ private Class clazz;
+ private ServiceTracker tracker;
+
+ public BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ public Class getInterface() {
+ return clazz;
+ }
+
+ public void setInterface(Class clazz) {
+ this.clazz = clazz;
+ }
+
+ public ServiceRegistry<T> getRegistry() {
+ return registry;
+ }
+
+ public void setRegistry(ServiceRegistry<T> registry) {
+ this.registry = registry;
+ }
+
+ public void afterPropertiesSet() throws Exception {
+ tracker = new ServiceTracker(bundleContext, clazz.getName(), this);
+ tracker.open();
+ }
+
+ public void destroy() throws Exception {
+ tracker.close();
+ }
+
+ public Object addingService(ServiceReference reference) {
+ T service = (T) bundleContext.getService(reference);
+ Map properties = OsgiServiceReferenceUtils.getServicePropertiesSnapshotAsMap(reference);
+ registry.register(service, properties);
+ return service;
+ }
+
+ public void modifiedService(ServiceReference reference, Object service) {
+ }
+
+ public void removedService(ServiceReference reference, Object service) {
+ Map properties = OsgiServiceReferenceUtils.getServicePropertiesSnapshotAsMap(reference);
+ registry.unregister((T) service, properties);
+ }
+}
Modified: servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/META-INF/spring/servicemix-nmr.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/META-INF/spring/servicemix-nmr.xml?rev=751759&r1=751758&r2=751759&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/META-INF/spring/servicemix-nmr.xml (original)
+++ servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/META-INF/spring/servicemix-nmr.xml Mon Mar 9 17:03:33 2009
@@ -51,20 +51,17 @@
</list>
</property>
</bean>
- <osgi:list id="flows"
- interface="org.apache.servicemix.nmr.api.internal.Flow"
- cardinality="0..N">
- <osgi:listener ref="flowRegistry" bind-method="register" unbind-method="unregister" />
- </osgi:list>
+ <bean class="org.apache.servicemix.nmr.osgi.OsgiServiceRegistryTracker">
+ <property name="interface" value="org.apache.servicemix.nmr.api.internal.Flow" />
+ <property name="registry" ref="listenerRegistry" />
+ </bean>
<!-- Listener registry and service tracker -->
<bean id="listenerRegistry" class="org.apache.servicemix.nmr.core.ListenerRegistryImpl" />
- <osgi:list id="listeners"
- interface="org.apache.servicemix.nmr.api.event.Listener"
- cardinality="0..N"
- greedy-proxying="true">
- <osgi:listener ref="listenerRegistry" bind-method="register" unbind-method="unregister" />
- </osgi:list>
+ <bean class="org.apache.servicemix.nmr.osgi.OsgiServiceRegistryTracker">
+ <property name="interface" value="org.apache.servicemix.nmr.api.event.Listener" />
+ <property name="registry" ref="listenerRegistry" />
+ </bean>
<!-- Endpoint registry and service tracker -->
<bean id="endpointRegistry" class="org.apache.servicemix.nmr.core.EndpointRegistryImpl">
@@ -72,19 +69,17 @@
<property name="registry" ref="internalEndpointRegistry" />
</bean>
<bean id="internalEndpointRegistry" class="org.apache.servicemix.nmr.osgi.InternalRegistryWrapper" />
- <osgi:list id="endpoints"
- interface="org.apache.servicemix.nmr.api.Endpoint"
- cardinality="0..N">
- <osgi:listener ref="endpointRegistry" bind-method="register" unbind-method="unregister" />
- </osgi:list>
-
+ <bean class="org.apache.servicemix.nmr.osgi.OsgiServiceRegistryTracker">
+ <property name="interface" value="org.apache.servicemix.nmr.api.Endpoint" />
+ <property name="registry" ref="endpointRegistry" />
+ </bean>
+
<!-- Wire registry and service tracker -->
<bean id="wireRegistry" class="org.apache.servicemix.nmr.core.WireRegistryImpl"/>
- <osgi:list id="wires"
- interface="org.apache.servicemix.nmr.api.Wire"
- cardinality="0..N">
- <osgi:listener ref="wireRegistry" bind-method="register" unbind-method="unregister" />
- </osgi:list>
+ <bean class="org.apache.servicemix.nmr.osgi.OsgiServiceRegistryTracker">
+ <property name="interface" value="org.apache.servicemix.nmr.api.Wire" />
+ <property name="registry" ref="wireRegistry" />
+ </bean>
<!-- AuthorizationService -->
<bean id="authorizationService" class="org.apache.servicemix.nmr.core.security.DefaultAuthorizationService" />