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 2008/02/29 00:49:08 UTC
svn commit: r632172 - in /servicemix/smx4/nmr/trunk/jbi/osgi: ./
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/servicemix/ src/main/java/org/apache/servicemix/jbi/
src/main/java/org/apache/servicemix/jbi/osgi/ src...
Author: gnodet
Date: Thu Feb 28 15:48:59 2008
New Revision: 632172
URL: http://svn.apache.org/viewvc?rev=632172&view=rev
Log:
SMX4NMR-12: endpoints should be registered in the OSGi registry and not directly in the NMR
Added:
servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/
servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/
servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/
servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/
servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/
servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/
servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/NMRWrapper.java
servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/RegistryWrapper.java
Modified:
servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml
servicemix/smx4/nmr/trunk/jbi/osgi/src/main/resources/META-INF/spring/servicemix-jbi.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=632172&r1=632171&r2=632172&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/osgi/pom.xml Thu Feb 28 15:48:59 2008
@@ -44,6 +44,11 @@
<artifactId>org.apache.servicemix.jbi.deployer</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>${felix.osgi.version}</version>
+ </dependency>
</dependencies>
<build>
@@ -54,7 +59,7 @@
<configuration>
<instructions>
<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
- <Import-Package>org.apache.servicemix.jbi.runtime,org.apache.servicemix.jbi.runtime.impl</Import-Package>
+ <Import-Package>*</Import-Package>
<Spring-Context>*;publish-context:=false;create-asynchronously:=true</Spring-Context>
</instructions>
</configuration>
Added: servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/NMRWrapper.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/NMRWrapper.java?rev=632172&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/NMRWrapper.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/NMRWrapper.java Thu Feb 28 15:48:59 2008
@@ -0,0 +1,75 @@
+/*
+ * 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.osgi;
+
+import org.apache.servicemix.nmr.api.Channel;
+import org.apache.servicemix.nmr.api.EndpointRegistry;
+import org.apache.servicemix.nmr.api.NMR;
+import org.apache.servicemix.nmr.api.event.ListenerRegistry;
+import org.apache.servicemix.nmr.api.internal.FlowRegistry;
+import org.osgi.framework.BundleContext;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.osgi.context.BundleContextAware;
+
+/**
+ * A NMR wrapper which purpose is to delegate to the OSGi registry
+ * instead of registering the endpoints directly.
+ * This way, the JBI layer is decoupled from OSGi, while still
+ * having the endpoints registered in the OSGi registry.
+ */
+public class NMRWrapper implements NMR, BundleContextAware, InitializingBean {
+
+ private NMR nmr;
+ private BundleContext bundleContext;
+ private EndpointRegistry registry;
+
+ public void setNmr(NMR nmr) {
+ this.nmr = nmr;
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ public void afterPropertiesSet() throws Exception {
+ if (this.nmr == null) {
+ throw new IllegalArgumentException("nmr must be set");
+ }
+ if (this.bundleContext == null) {
+ throw new IllegalArgumentException("bundleContext must be set");
+ }
+ this.registry = new RegistryWrapper(nmr.getEndpointRegistry(), bundleContext);
+ }
+
+ public EndpointRegistry getEndpointRegistry() {
+ return registry;
+ }
+
+ public ListenerRegistry getListenerRegistry() {
+ return nmr.getListenerRegistry();
+ }
+
+ public FlowRegistry getFlowRegistry() {
+ return nmr.getFlowRegistry();
+ }
+
+ public Channel createChannel() {
+ return nmr.createChannel();
+ }
+
+
+}
Added: 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=632172&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/RegistryWrapper.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/osgi/src/main/java/org/apache/servicemix/jbi/osgi/RegistryWrapper.java Thu Feb 28 15:48:59 2008
@@ -0,0 +1,88 @@
+/*
+ * 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.osgi;
+
+import java.util.Map;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.w3c.dom.Document;
+
+import org.apache.servicemix.nmr.api.EndpointRegistry;
+import org.apache.servicemix.nmr.api.Endpoint;
+import org.apache.servicemix.nmr.api.Reference;
+import org.apache.servicemix.nmr.core.util.MapToDictionary;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * A wrapper around an EndpointRegistry.
+ * Instead of directly registering endpoints in the
+ * delegate registry, this one will register the
+ * endpoints in the OSGi registry.
+ *
+ * @see NMRWrapper
+ *
+ */
+public class RegistryWrapper implements EndpointRegistry {
+ private EndpointRegistry registry;
+ private BundleContext bundleContext;
+ private Map<Endpoint, ServiceRegistration> registrations = new ConcurrentHashMap();
+
+ public RegistryWrapper(EndpointRegistry registry, BundleContext bundleContext) {
+ this.registry = registry;
+ this.bundleContext = bundleContext;
+ }
+
+ public void register(Endpoint endpoint, Map<String, ?> properties) {
+ ServiceRegistration reg = bundleContext.registerService(
+ Endpoint.class.getName(),
+ endpoint,
+ new MapToDictionary(properties));
+ registrations.put(endpoint, reg);
+ }
+
+ public void unregister(Endpoint endpoint, Map<String, ?> properties) {
+ ServiceRegistration reg = registrations.remove(endpoint);
+ reg.unregister();
+ }
+
+ public List<Endpoint> query(Map<String, ?> properties) {
+ return registry.query(properties);
+ }
+
+ public Reference lookup(Map<String, ?> properties) {
+ return registry.lookup(properties);
+ }
+
+ public Reference lookup(Document xml) {
+ return registry.lookup(xml);
+ }
+
+ public Reference lookup(String filter) {
+ return registry.lookup(filter);
+ }
+
+ public Map<String, ?> getProperties(Endpoint service) {
+ return registry.getProperties(service);
+ }
+
+ public Set<Endpoint> getServices() {
+ return registry.getServices();
+ }
+}
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=632172&r1=632171&r2=632172&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 Thu Feb 28 15:48:59 2008
@@ -31,7 +31,7 @@
<!-- JBI Component Registry -->
<bean id="componentRegistry" class="org.apache.servicemix.jbi.runtime.impl.ComponentRegistryImpl">
- <property name="nmr" ref="nmr" />
+ <property name="nmr" ref="nmrWrapper" />
<property name="documentRepository" ref="documentRepository" />
<property name="managementContext" ref="managementContext" />
<property name="environment" ref="environment" />
@@ -52,6 +52,10 @@
<property name="transactionManagers" ref="transactionManagers" />
<property name="mbeanServers" ref="mbeanServers" />
<property name="namingContexts" ref="namingContexts" />
+ </bean>
+
+ <bean id="nmrWrapper" class="org.apache.servicemix.jbi.osgi.NMRWrapper">
+ <property name="nmr" ref="nmr" />
</bean>
<!-- Service tracker for JBI components -->