http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImplTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImplTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImplTest.java deleted file mode 100644 index 9057e46..0000000 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentManagerImplTest.java +++ /dev/null @@ -1,278 +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.cxf.dosgi.dsw.qos; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.cxf.binding.BindingConfiguration; -import org.apache.cxf.dosgi.dsw.api.IntentUnsatisfiedException; -import org.apache.cxf.endpoint.AbstractEndpointFactory; -import org.apache.cxf.feature.AbstractFeature; -import org.apache.cxf.feature.Feature; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.junit.Assert; -import org.junit.Test; - -public class IntentManagerImplTest extends Assert { - - @Test - public void testIntents() throws Exception { - Map<String, Object> intents = new HashMap<String, Object>(); - intents.put("A", new TestFeature("A")); - intents.put("SOAP", new TestFeature("SOAP")); - final IntentMap intentMap = new IntentMap(intents); - - IMocksControl control = EasyMock.createNiceControl(); - List<Feature> features = new ArrayList<Feature>(); - AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class); - control.replay(); - - IntentManager intentManager = new IntentManagerImpl(intentMap, 10000); - - Map<String, Object> props = new HashMap<String, Object>(); - props.put("osgi.remote.requires.intents", "A"); - - List<String> effectiveIntents = Arrays.asList(intentManager.applyIntents(features, factory, props)); - assertEquals(Arrays.asList("A", "SOAP"), effectiveIntents); - } - - @Test - public void testMultiIntents() { - final IntentMap intentMap = new IntentMap(new DefaultIntentMapFactory().create()); - intentMap.put("confidentiality.message", new TestFeature("confidentiality.message")); - intentMap.put("transactionality", new TestFeature("transactionality")); - - IMocksControl control = EasyMock.createNiceControl(); - List<Feature> features = new ArrayList<Feature>(); - AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class); - control.replay(); - - IntentManager intentManager = new IntentManagerImpl(intentMap); - - Map<String, Object> props = new HashMap<String, Object>(); - props.put("osgi.remote.requires.intents", "transactionality confidentiality.message"); - - List<String> effectiveIntents = Arrays.asList(intentManager.applyIntents(features, factory, props)); - assertTrue(effectiveIntents.contains("transactionality")); - assertTrue(effectiveIntents.contains("confidentiality.message")); - } - - @Test - public void testFailedIntent() { - Map<String, Object> intents = new HashMap<String, Object>(); - intents.put("A", new TestFeature("A")); - final IntentMap intentMap = new IntentMap(intents); - - IMocksControl control = EasyMock.createNiceControl(); - List<Feature> features = new ArrayList<Feature>(); - AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class); - control.replay(); - - IntentManager intentManager = new IntentManagerImpl(intentMap); - - Map<String, Object> props = new HashMap<String, Object>(); - props.put("osgi.remote.requires.intents", "A B"); - // ServiceEndpointDescription sd = - // new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()), props); - - try { - intentManager.applyIntents(features, factory, props); - Assert.fail("applyIntents() should have thrown an exception as there was an unsatisfiable intent"); - } catch (IntentUnsatisfiedException iue) { - assertEquals("B", iue.getIntent()); - } - } - - @Test - public void testInferIntents() { - Map<String, Object> intents = new HashMap<String, Object>(); - intents.put("SOAP", new TestFeature("SOAP")); - intents.put("Prov", "PROVIDED"); - AbstractFeature feat1 = new TestFeature("feat1"); - intents.put("A", feat1); - intents.put("A_alt", feat1); - intents.put("B", new TestFeature("B")); - final IntentMap intentMap = new IntentMap(intents); - - IMocksControl control = EasyMock.createNiceControl(); - List<Feature> features = new ArrayList<Feature>(); - AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class); - control.replay(); - - IntentManager intentManager = new IntentManagerImpl(intentMap); - - Map<String, Object> props = new HashMap<String, Object>(); - props.put("osgi.remote.requires.intents", "A"); - // ServiceEndpointDescription sd = - // new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()), props); - - List<String> effectiveIntents = Arrays.asList(intentManager.applyIntents(features, factory, props)); - assertEquals(4, effectiveIntents.size()); - assertTrue(effectiveIntents.contains("Prov")); - assertTrue(effectiveIntents.contains("A")); - assertTrue(effectiveIntents.contains("A_alt")); - } - - @Test - public void testDefaultBindingIntent() { - IMocksControl control = EasyMock.createNiceControl(); - - Map<String, Object> intents = new HashMap<String, Object>(); - BindingConfiguration feat1 = control.createMock(BindingConfiguration.class); - intents.put("A", new AbstractFeature() { - }); - intents.put("SOAP", feat1); - intents.put("SOAP.1_1", feat1); - intents.put("SOAP.1_2", control.createMock(BindingConfiguration.class)); - final IntentMap intentMap = new IntentMap(intents); - - List<Feature> features = new ArrayList<Feature>(); - AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class); - control.replay(); - IntentManager intentManager = new IntentManagerImpl(intentMap); - - Map<String, Object> props = new HashMap<String, Object>(); - props.put("osgi.remote.requires.intents", "A"); - // ServiceEndpointDescription sd = - // new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()), props); - - List<String> effectiveIntents = Arrays.asList(intentManager.applyIntents(features, factory, props)); - assertEquals(3, effectiveIntents.size()); - assertTrue(effectiveIntents.contains("A")); - assertTrue(effectiveIntents.contains("SOAP")); - assertTrue(effectiveIntents.contains("SOAP.1_1")); - } - - @Test - public void testExplicitBindingIntent() { - IMocksControl control = EasyMock.createNiceControl(); - - Map<String, Object> intents = new HashMap<String, Object>(); - BindingConfiguration feat1 = control.createMock(BindingConfiguration.class); - intents.put("A", new AbstractFeature() { - }); - intents.put("SOAP", feat1); - intents.put("SOAP.1_1", feat1); - intents.put("SOAP.1_2", control.createMock(BindingConfiguration.class)); - final IntentMap intentMap = new IntentMap(intents); - - List<Feature> features = new ArrayList<Feature>(); - AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class); - control.replay(); - - IntentManager intentManager = new IntentManagerImpl(intentMap); - - Map<String, Object> props = new HashMap<String, Object>(); - props.put("osgi.remote.requires.intents", "A SOAP.1_2"); - // ServiceEndpointDescription sd = - // new ServiceEndpointDescriptionImpl(Arrays.asList(String.class.getName()), props); - - List<String> effectiveIntents = Arrays.asList(intentManager.applyIntents(features, factory, props)); - assertEquals(2, effectiveIntents.size()); - assertTrue(effectiveIntents.contains("A")); - assertTrue(effectiveIntents.contains("SOAP.1_2")); - } - - public void testInheritMasterIntentMapDefault() { - List<String> features = runTestInheritMasterIntentMap("A B"); - - assertEquals(2, features.size()); - assertTrue(features.contains("appFeatureA")); - assertTrue(features.contains("masterFeatureB")); - } - - public void testInheritMasterIntentMap() { - List<String> features = runTestInheritMasterIntentMap("A B"); - - assertEquals(2, features.size()); - assertTrue(features.contains("appFeatureA")); - assertTrue(features.contains("masterFeatureB")); - } - - private List<String> runTestInheritMasterIntentMap(String requestedIntents) { - Map<String, Object> masterIntents = new HashMap<String, Object>(); - masterIntents.put("A", new TestFeature("masterFeatureA")); - masterIntents.put("B", new TestFeature("masterFeatureB")); - final IntentMap intentMap = new IntentMap(masterIntents); - intentMap.put("A", new TestFeature("appFeatureA")); - - IMocksControl control = EasyMock.createNiceControl(); - List<Feature> features = new ArrayList<Feature>(); - AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class); - control.replay(); - - Map<String, Object> props = new HashMap<String, Object>(); - props.put("osgi.remote.requires.intents", requestedIntents); - - IntentManagerImpl intentManager = new IntentManagerImpl(intentMap); - intentManager.applyIntents(features, factory, props); - - List<String> featureNames = new ArrayList<String>(); - for (Feature f : features) { - featureNames.add(f.toString()); - } - return featureNames; - } - - @Test - public void testProvidedIntents() { - Map<String, Object> masterIntents = new HashMap<String, Object>(); - masterIntents.put("SOAP", "SOAP"); - masterIntents.put("A", "Provided"); - masterIntents.put("B", "PROVIDED"); - final IntentMap intentMap = new IntentMap(masterIntents); - - IMocksControl control = EasyMock.createNiceControl(); - List<Feature> features = new ArrayList<Feature>(); - AbstractEndpointFactory factory = control.createMock(AbstractEndpointFactory.class); - control.replay(); - - Map<String, Object> props = new HashMap<String, Object>(); - props.put("osgi.remote.requires.intents", "B A"); - - IntentManager intentManager = new IntentManagerImpl(intentMap); - - Set<String> effectiveIntents = new HashSet<String>(Arrays.asList(intentManager.applyIntents(features, - factory, - props))); - Set<String> expectedIntents = new HashSet<String>(Arrays.asList(new String[] {"A", "B", "SOAP"})); - assertEquals(expectedIntents, effectiveIntents); - } - - private static final class TestFeature extends AbstractFeature { - - private final String name; - - private TestFeature(String n) { - name = n; - } - - @Override - public String toString() { - return name; - } - } -}
http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentMapTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentMapTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentMapTest.java deleted file mode 100644 index 748da85..0000000 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentMapTest.java +++ /dev/null @@ -1,41 +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.cxf.dosgi.dsw.qos; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Assert; -import org.junit.Test; - -public class IntentMapTest { - - @Test - public void inheritanceTest() { - Map<String, Object> defaultMap = new HashMap<String, Object>(); - defaultMap.put("key1", "defaultValue"); - IntentMap intentMap = new IntentMap(defaultMap); - Assert.assertEquals("defaultValue", intentMap.get("key1")); - intentMap.put("key1", "overridden"); - Assert.assertEquals("overridden", intentMap.get("key1")); - Object curValue = intentMap.remove("key1"); - Assert.assertEquals("overridden", curValue); - Assert.assertEquals("defaultValue", intentMap.get("key1")); - } -} http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentTrackerTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentTrackerTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentTrackerTest.java deleted file mode 100644 index b68cf61..0000000 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentTrackerTest.java +++ /dev/null @@ -1,80 +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.cxf.dosgi.dsw.qos; - -import org.apache.cxf.dosgi.dsw.Constants; -import org.apache.cxf.feature.AbstractFeature; -import org.easymock.Capture; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.junit.Assert; -import org.junit.Test; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Filter; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceEvent; -import org.osgi.framework.ServiceListener; -import org.osgi.framework.ServiceReference; - -import static org.easymock.EasyMock.expect; - -public class IntentTrackerTest { - - private static final String MY_INTENT_NAME = "myIntent"; - - @Test - public void testIntentAsService() throws InvalidSyntaxException { - IMocksControl c = EasyMock.createControl(); - BundleContext bc = c.createMock(BundleContext.class); - Filter filter = c.createMock(Filter.class); - expect(bc.createFilter(EasyMock.<String>anyObject())).andReturn(filter); - final Capture<ServiceListener> capturedListener = EasyMock.newCapture(); - bc.addServiceListener(EasyMock.capture(capturedListener), EasyMock.<String>anyObject()); - EasyMock.expectLastCall().atLeastOnce(); - expect(bc.getServiceReferences(EasyMock.<String>anyObject(), - EasyMock.<String>anyObject())).andReturn(new ServiceReference[]{}); - IntentMap intentMap = new IntentMap(); - - // Create a custom intent - @SuppressWarnings("unchecked") - ServiceReference<AbstractFeature> reference = c.createMock(ServiceReference.class); - expect(reference.getProperty(Constants.INTENT_NAME_PROP)).andReturn(MY_INTENT_NAME); - AbstractFeature testIntent = new AbstractFeature() { - }; - expect(bc.getService(reference)).andReturn(testIntent).atLeastOnce(); - - c.replay(); - - IntentTracker tracker = new IntentTracker(bc, intentMap); - tracker.open(); - - Assert.assertFalse("IntentMap should not contain " + MY_INTENT_NAME, intentMap.containsKey(MY_INTENT_NAME)); - ServiceListener listener = capturedListener.getValue(); - - // Simulate adding custom intent service - ServiceEvent event = new ServiceEvent(ServiceEvent.REGISTERED, reference); - listener.serviceChanged(event); - - // our custom intent should now be available - Assert.assertTrue("IntentMap should contain " + MY_INTENT_NAME, intentMap.containsKey(MY_INTENT_NAME)); - Assert.assertEquals(testIntent, intentMap.get(MY_INTENT_NAME)); - - c.verify(); - } -} http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentUtilsTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentUtilsTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentUtilsTest.java deleted file mode 100644 index f7fe844..0000000 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/qos/IntentUtilsTest.java +++ /dev/null @@ -1,70 +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.cxf.dosgi.dsw.qos; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.apache.cxf.dosgi.dsw.Constants; -import org.junit.Assert; -import org.junit.Test; -import org.osgi.service.remoteserviceadmin.RemoteConstants; - -public class IntentUtilsTest { - - @Test - public void testMergeArrays() { - Assert.assertNull(IntentUtils.mergeArrays(null, null)); - - String[] sa1 = {}; - Assert.assertEquals(0, IntentUtils.mergeArrays(sa1, null).length); - - String[] sa2 = {"X"}; - Assert.assertEquals(1, IntentUtils.mergeArrays(null, sa2).length); - Assert.assertEquals("X", IntentUtils.mergeArrays(null, sa2)[0]); - - String[] sa3 = {"Y", "Z"}; - String[] sa4 = {"A", "Z"}; - Assert.assertEquals(3, IntentUtils.mergeArrays(sa3, sa4).length); - Assert.assertEquals(new HashSet<String>(Arrays.asList("A", "Y", "Z")), - new HashSet<String>(Arrays.asList(IntentUtils.mergeArrays(sa3, sa4)))); - } - - @SuppressWarnings("deprecation") - @Test - public void testRequestedIntents() { - Map<String, Object> props = new HashMap<String, Object>(); - Assert.assertEquals(0, IntentUtils.getRequestedIntents(props).size()); - - props.put(RemoteConstants.SERVICE_EXPORTED_INTENTS, "one"); - Assert.assertEquals(Collections.singleton("one"), IntentUtils.getRequestedIntents(props)); - - props.put(RemoteConstants.SERVICE_EXPORTED_INTENTS_EXTRA, new String[] {"two", "three"}); - Set<String> expected1 = new HashSet<String>(Arrays.asList("one", "two", "three")); - Assert.assertEquals(expected1, IntentUtils.getRequestedIntents(props)); - - props.put(Constants.EXPORTED_INTENTS_OLD, "A B C"); - Set<String> expected2 = new HashSet<String>(Arrays.asList("one", "two", "three", "A", "B", "C")); - Assert.assertEquals(expected2, IntentUtils.getRequestedIntents(props)); - } -} http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/OsgiUtilsTest.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/OsgiUtilsTest.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/OsgiUtilsTest.java deleted file mode 100644 index cc15ea6..0000000 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/OsgiUtilsTest.java +++ /dev/null @@ -1,152 +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.cxf.dosgi.dsw.util; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import junit.framework.TestCase; - -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.Version; -import org.osgi.service.packageadmin.ExportedPackage; -import org.osgi.service.packageadmin.PackageAdmin; -import org.osgi.service.remoteserviceadmin.EndpointDescription; -import org.osgi.service.remoteserviceadmin.RemoteConstants; - -@SuppressWarnings("deprecation") -public class OsgiUtilsTest extends TestCase { - - public void testMultiValuePropertyAsString() { - assertEquals(Collections.singleton("hi"), - OsgiUtils.getMultiValueProperty("hi")); - } - - public void testMultiValuePropertyAsArray() { - assertEquals(Arrays.asList("a", "b"), - OsgiUtils.getMultiValueProperty(new String[] {"a", "b"})); - } - - public void testMultiValuePropertyAsCollection() { - List<String> list = new ArrayList<String>(); - list.add("1"); - list.add("2"); - list.add("3"); - assertEquals(list, OsgiUtils.getMultiValueProperty(list)); - } - - public void testMultiValuePropertyNull() { - assertNull(OsgiUtils.getMultiValueProperty(null)); - } - - @SuppressWarnings({ - "rawtypes", "unchecked" - }) - public void testGetVersion() { - IMocksControl c = EasyMock.createNiceControl(); - BundleContext bc = c.createMock(BundleContext.class); - ServiceReference sref = c.createMock(ServiceReference.class); - PackageAdmin pa = c.createMock(PackageAdmin.class); - Bundle b = c.createMock(Bundle.class); - - EasyMock.expect(bc.getServiceReference(EasyMock.eq(PackageAdmin.class))).andReturn(sref); - EasyMock.expect(bc.getService(EasyMock.eq(sref))).andReturn(pa); - - Class<?> iClass = CharSequence.class; - - c.replay(); - // version 0.0.0 because of missing bundle - - assertEquals("0.0.0", OsgiUtils.getVersion(iClass, bc)); - - c.verify(); - c.reset(); - // version 1.2.3 - - EasyMock.expect(bc.getServiceReference(EasyMock.eq(PackageAdmin.class))).andReturn(sref); - EasyMock.expect(bc.getService(EasyMock.eq(sref))).andReturn(pa); - EasyMock.expect(pa.getBundle(EasyMock.eq(iClass))).andReturn(b); - - ExportedPackage[] exP = new ExportedPackage[] {new MyExportedPackage(iClass.getPackage(), "1.2.3"), - new MyExportedPackage(String.class.getPackage(), "4.5.6") }; - - EasyMock.expect(pa.getExportedPackages(EasyMock.eq(b))).andReturn(exP).atLeastOnce(); - - c.replay(); - assertEquals("1.2.3", OsgiUtils.getVersion(iClass, bc)); - c.verify(); - } - - private static class MyExportedPackage implements ExportedPackage { - - Package package1; - String version; - - MyExportedPackage(Package package1, String version) { - this.package1 = package1; - this.version = version; - } - - public Bundle getExportingBundle() { - return null; - } - - public Bundle[] getImportingBundles() { - return null; - } - - public String getName() { - return package1.getName(); - } - - public String getSpecificationVersion() { - return null; - } - - public Version getVersion() { - return new Version(version); - } - - public boolean isRemovalPending() { - return false; - } - } - - public void testGetProperty() { - Map<String, Object> p = new HashMap<String, Object>(); - p.put(RemoteConstants.ENDPOINT_ID, "http://google.de"); - p.put("notAString", new Object()); - p.put(org.osgi.framework.Constants.OBJECTCLASS, new String[]{"my.class"}); - p.put(RemoteConstants.SERVICE_IMPORTED_CONFIGS, new String[]{"my.config"}); - - EndpointDescription endpoint = new EndpointDescription(p); - - assertNull(OsgiUtils.getProperty(endpoint, "unknownProp")); - assertEquals(p.get(RemoteConstants.ENDPOINT_ID), OsgiUtils.getProperty(endpoint, RemoteConstants.ENDPOINT_ID)); - assertEquals(null, OsgiUtils.getProperty(endpoint, "notAString")); - } -} http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/Provider.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/Provider.java b/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/Provider.java deleted file mode 100644 index ecd7c78..0000000 --- a/dsw/cxf-dsw/src/test/java/org/apache/cxf/dosgi/dsw/util/Provider.java +++ /dev/null @@ -1,23 +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.cxf.dosgi.dsw.util; - - -public class Provider { -} http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/resources/OSGI-INF/remote-service/alt-remote-services.xml ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/resources/OSGI-INF/remote-service/alt-remote-services.xml b/dsw/cxf-dsw/src/test/resources/OSGI-INF/remote-service/alt-remote-services.xml deleted file mode 100644 index 36409ce..0000000 --- a/dsw/cxf-dsw/src/test/resources/OSGI-INF/remote-service/alt-remote-services.xml +++ /dev/null @@ -1,32 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- - 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. ---> - -<service-descriptions xmlns="http://www.osgi.org/xmlns/sd/v1.0.0"> - <service-description> - <provide interface="org.apache.cxf.dosgi.dsw.hooks.TestService" /> - <provide interface="org.apache.cxf.dosgi.dsw.hooks.CxfPublishHookTest$AdditionalInterface" /> - - <property name="osgi.remote.interfaces" value="*" /> - <property name="osgi.remote.requires.intents" value="SOAP HTTP" /> - <property name="osgi.remote.configuration.type" value="pojo" /> - <property name="osgi.remote.configuration.pojo.address" value="http://localhost:9000/hello" /> - </service-description> -</service-descriptions> http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/resources/OSGI-INF/remote-service/multi-services.xml ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/resources/OSGI-INF/remote-service/multi-services.xml b/dsw/cxf-dsw/src/test/resources/OSGI-INF/remote-service/multi-services.xml deleted file mode 100644 index 3d20c08..0000000 --- a/dsw/cxf-dsw/src/test/resources/OSGI-INF/remote-service/multi-services.xml +++ /dev/null @@ -1,38 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- - 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. ---> - -<service-descriptions xmlns="http://www.osgi.org/xmlns/sd/v1.0.0"> - <service-description> - <provide interface="org.apache.cxf.dosgi.dsw.hooks.TestService" /> - <provide interface="org.apache.cxf.dosgi.dsw.hooks.CxfPublishHookTest$AdditionalInterface" /> - <property name="osgi.remote.interfaces">org.apache.cxf.dosgi.dsw.hooks.TestService,org.apache.cxf.dosgi.dsw.hooks.CxfPublishHookTest$AdditionalInterface</property> - <property name="osgi.remote.requires.intents">SOAP HTTP</property> - <property name="osgi.remote.configuration.type">pojo</property> - <property name="osgi.remote.configuration.pojo.address" - interface="org.apache.cxf.dosgi.dsw.hooks.TestService"> - http://localhost:9001/hello - </property> - <property name="osgi.remote.configuration.pojo.address" - interface="org.apache.cxf.dosgi.dsw.hooks.CxfPublishHookTest$AdditionalInterface"> - http://localhost:9002/hello - </property> - </service-description> -</service-descriptions> http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/resources/OSGI-INF/remote-service/remote-services.xml ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/resources/OSGI-INF/remote-service/remote-services.xml b/dsw/cxf-dsw/src/test/resources/OSGI-INF/remote-service/remote-services.xml deleted file mode 100644 index 45b2a20..0000000 --- a/dsw/cxf-dsw/src/test/resources/OSGI-INF/remote-service/remote-services.xml +++ /dev/null @@ -1,32 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- - 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. ---> - -<service-descriptions xmlns="http://www.osgi.org/xmlns/sd/v1.0.0"> - <service-description> - <provide interface="org.apache.cxf.dosgi.dsw.hooks.TestService" /> - <provide interface="org.apache.cxf.dosgi.dsw.hooks.CxfPublishHookTest$AdditionalInterface" /> - - <property name="osgi.remote.interfaces">*</property> - <property name="osgi.remote.requires.intents">SOAP HTTP</property> - <property name="osgi.remote.configuration.type">pojo</property> - <property name="osgi.remote.configuration.pojo.address">http://localhost:9000/hello</property> - </service-description> -</service-descriptions> http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/resources/test-resources/rs1.xml ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/resources/test-resources/rs1.xml b/dsw/cxf-dsw/src/test/resources/test-resources/rs1.xml deleted file mode 100644 index f67a833..0000000 --- a/dsw/cxf-dsw/src/test/resources/test-resources/rs1.xml +++ /dev/null @@ -1,31 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- - 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. ---> - -<service-descriptions xmlns="http://www.osgi.org/xmlns/sd/v1.0.0"> - <service-description> - <provide interface="SomeService" /> - <property name="osgi.remote.requires.intents">confidentiality</property> - </service-description> - <service-description> - <provide interface="SomeOtherService" /> - <provide interface="WithSomeSecondInterface" /> - </service-description> -</service-descriptions> http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/resources/test-resources/rs2.xml ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/resources/test-resources/rs2.xml b/dsw/cxf-dsw/src/test/resources/test-resources/rs2.xml deleted file mode 100644 index 098aa21..0000000 --- a/dsw/cxf-dsw/src/test/resources/test-resources/rs2.xml +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> - -<!-- - 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. ---> - -<service-descriptions xmlns="http://www.osgi.org/xmlns/sd/v1.0.0"> - <service-description> - <provide interface="org.example.Service" /> - <property name="deployment.intents">confidentiality.message integrity</property> - <property name="osgi.remote.interfaces">*</property> - </service-description> -</service-descriptions> http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/resources/test-resources/sd-1.xml ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/resources/test-resources/sd-1.xml b/dsw/cxf-dsw/src/test/resources/test-resources/sd-1.xml deleted file mode 100644 index 483b196..0000000 --- a/dsw/cxf-dsw/src/test/resources/test-resources/sd-1.xml +++ /dev/null @@ -1,3 +0,0 @@ -<test> - <some-other-tag/> -</test> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/resources/test-resources/sd.xml ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/resources/test-resources/sd.xml b/dsw/cxf-dsw/src/test/resources/test-resources/sd.xml deleted file mode 100644 index c7cebfb..0000000 --- a/dsw/cxf-dsw/src/test/resources/test-resources/sd.xml +++ /dev/null @@ -1,8 +0,0 @@ -<service-decorations xmlns="http://cxf.apache.org/xmlns/service-decoration/1.0.0"> - <service-decoration> - <match interface="org.acme.foo.*"> - <match-property name="test.prop" value="xyz"/> - <add-property name="test.too" value="ahaha" type="java.lang.String"/> - </match> - </service-decoration> -</service-decorations> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/resources/test-resources/sd0.xml ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/resources/test-resources/sd0.xml b/dsw/cxf-dsw/src/test/resources/test-resources/sd0.xml deleted file mode 100644 index 0ad0ad1..0000000 --- a/dsw/cxf-dsw/src/test/resources/test-resources/sd0.xml +++ /dev/null @@ -1,2 +0,0 @@ -<service-decorations xmlns="http://cxf.apache.org/xmlns/service-decoration/1.0.0"> -</service-decorations> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/resources/test-resources/sd1.xml ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/resources/test-resources/sd1.xml b/dsw/cxf-dsw/src/test/resources/test-resources/sd1.xml deleted file mode 100644 index 6a5e811..0000000 --- a/dsw/cxf-dsw/src/test/resources/test-resources/sd1.xml +++ /dev/null @@ -1,8 +0,0 @@ -<service-decorations xmlns="http://cxf.apache.org/xmlns/service-decoration/1.0.0"> - <service-decoration> - <match interface="org.test.A"> - <add-property name="A" value="B"/> - <add-property name="C" value="2" type="java.lang.Integer"/> - </match> - </service-decoration> -</service-decorations> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-dsw/src/test/resources/test-resources/sd2.xml ---------------------------------------------------------------------- diff --git a/dsw/cxf-dsw/src/test/resources/test-resources/sd2.xml b/dsw/cxf-dsw/src/test/resources/test-resources/sd2.xml deleted file mode 100644 index fb6a93a..0000000 --- a/dsw/cxf-dsw/src/test/resources/test-resources/sd2.xml +++ /dev/null @@ -1,14 +0,0 @@ -<service-decorations xmlns="http://cxf.apache.org/xmlns/service-decoration/1.0.0"> - <service-decoration> - <match interface="org.test.(B|C)"> - <match-property name="x" value="y"/> - <add-property name="bool" value="true" type="java.lang.Boolean"/> - </match> - </service-decoration> - <service-decoration> - <match interface="org.test.(B|C)"> - <match-property name="x" value="z"/> - <add-property name="bool" value="false" type="java.lang.Boolean"/> - </match> - </service-decoration> -</service-decorations> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-topology-manager/pom.xml ---------------------------------------------------------------------- diff --git a/dsw/cxf-topology-manager/pom.xml b/dsw/cxf-topology-manager/pom.xml deleted file mode 100644 index b6c143e..0000000 --- a/dsw/cxf-topology-manager/pom.xml +++ /dev/null @@ -1,111 +0,0 @@ -<?xml version='1.0' encoding='UTF-8' ?> -<!-- - 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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - - <modelVersion>4.0.0</modelVersion> - <artifactId>cxf-dosgi-ri-topology-manager</artifactId> - <packaging>bundle</packaging> - <name>Distributed OSGi Topology Manager implementation</name> - - <parent> - <groupId>org.apache.cxf.dosgi</groupId> - <artifactId>cxf-dosgi-ri-parent</artifactId> - <version>1.8-SNAPSHOT</version> - <relativePath>../../parent/pom.xml</relativePath> - </parent> - - <properties> - <topDirectoryLocation>../..</topDirectoryLocation> - </properties> - - <dependencies> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.core</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.cxf.dosgi</groupId> - <artifactId>cxf-dosgi-ri-provider-api</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - </dependency> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-jdk14</artifactId> - <version>1.7.16</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.easymock</groupId> - <artifactId>easymockclassextension</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>hamcrest-all</artifactId> - <version>1.3</version> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <configuration> - <instructions> - <Bundle-Name>CXF dOSGi Topology Manager</Bundle-Name> - <Bundle-Description>The default CXF Topology Manager as described in the OSGi Remote Service Admin specification</Bundle-Description> - <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> - <Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor> - <Bundle-Activator>org.apache.cxf.dosgi.topologymanager.Activator</Bundle-Activator> - <Import-Package> - org.osgi.service.remoteserviceadmin;version="[${remote.service.admin.interfaces.version},2)", - * - </Import-Package> - <Export-Package> - !* - </Export-Package> - </instructions> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - </plugin> - </plugins> - </build> -</project> http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/Activator.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/Activator.java b/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/Activator.java deleted file mode 100644 index 62ec1a9..0000000 --- a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/Activator.java +++ /dev/null @@ -1,192 +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.cxf.dosgi.topologymanager; - -import java.util.Dictionary; -import java.util.Hashtable; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.concurrent.TimeUnit; - -import org.apache.cxf.dosgi.dsw.api.ExportPolicy; -import org.apache.cxf.dosgi.topologymanager.exporter.DefaultExportPolicy; -import org.apache.cxf.dosgi.topologymanager.exporter.EndpointListenerNotifier; -import org.apache.cxf.dosgi.topologymanager.exporter.EndpointRepository; -import org.apache.cxf.dosgi.topologymanager.exporter.TopologyManagerExport; -import org.apache.cxf.dosgi.topologymanager.importer.TopologyManagerImport; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Filter; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceEvent; -import org.osgi.framework.ServiceReference; -import org.osgi.service.remoteserviceadmin.EndpointListener; -import org.osgi.service.remoteserviceadmin.RemoteConstants; -import org.osgi.service.remoteserviceadmin.RemoteServiceAdmin; -import org.osgi.util.tracker.ServiceTracker; -import org.osgi.util.tracker.ServiceTrackerCustomizer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class Activator implements BundleActivator { - public static final String RSA_EXPORT_POLICY_FILTER = "rsa.export.policy.filter"; - static final String DOSGI_SERVICES = "(" + RemoteConstants.SERVICE_EXPORTED_INTERFACES + "=*)"; - private static final Logger LOG = LoggerFactory.getLogger(Activator.class); - - private TopologyManagerExport exportManager; - private TopologyManagerImport importManager; - private EndpointListenerNotifier notifier; - private ServiceTracker<RemoteServiceAdmin, RemoteServiceAdmin> rsaTracker; - private ThreadPoolExecutor exportExecutor; - private ServiceTracker<EndpointListener, EndpointListener> epListenerTracker; - private ServiceTracker<ExportPolicy, ExportPolicy> policyTracker; - - public void start(final BundleContext bc) throws Exception { - Dictionary<String, String> props = new Hashtable<String, String>(); - props.put("name", "default"); - bc.registerService(ExportPolicy.class, new DefaultExportPolicy(), props); - - Filter policyFilter = exportPolicyFilter(bc); - policyTracker = new ServiceTracker<ExportPolicy, ExportPolicy>(bc, policyFilter, null) { - - @Override - public ExportPolicy addingService(ServiceReference<ExportPolicy> reference) { - ExportPolicy policy = super.addingService(reference); - if (exportManager == null) { - doStart(bc, policy); - } - return policy; - } - - @Override - public void removedService(ServiceReference<ExportPolicy> reference, ExportPolicy service) { - if (exportManager != null) { - doStop(bc); - } - super.removedService(reference, service); - } - }; - policyTracker.open(); - } - - private Filter exportPolicyFilter(BundleContext bc) throws InvalidSyntaxException { - String filter = bc.getProperty(RSA_EXPORT_POLICY_FILTER); - if (filter == null) { - filter = "(name=default)"; - } - return FrameworkUtil.createFilter(String.format("(&(objectClass=%s)%s)", ExportPolicy.class.getName(), filter)); - } - - public void doStart(final BundleContext bc, ExportPolicy policy) { - LOG.debug("TopologyManager: start()"); - EndpointRepository endpointRepo = new EndpointRepository(); - notifier = new EndpointListenerNotifier(endpointRepo); - epListenerTracker = new EndpointListenerTracker(bc); - endpointRepo.setNotifier(notifier); - exportExecutor = new ThreadPoolExecutor(5, 10, 50, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); - exportManager = new TopologyManagerExport(endpointRepo, exportExecutor, policy); - importManager = new TopologyManagerImport(bc); - rsaTracker = new RSATracker(bc, RemoteServiceAdmin.class, null); - bc.addServiceListener(exportManager); - rsaTracker.open(); - epListenerTracker.open(); - exportExistingServices(bc); - importManager.start(); - } - - public void stop(BundleContext bc) throws Exception { - policyTracker.close(); - } - - public void doStop(BundleContext bc) { - LOG.debug("TopologyManager: stop()"); - epListenerTracker.close(); - bc.removeServiceListener(exportManager); - exportExecutor.shutdown(); - importManager.stop(); - rsaTracker.close(); - exportManager = null; - } - - public void exportExistingServices(BundleContext context) { - try { - // cast to String is necessary for compiling against OSGi core version >= 4.3 - ServiceReference<?>[] references = context.getServiceReferences((String)null, DOSGI_SERVICES); - if (references != null) { - for (ServiceReference<?> sref : references) { - exportManager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, sref)); - } - } - } catch (InvalidSyntaxException e) { - LOG.error("Error in filter {}. This should not occur!", DOSGI_SERVICES); - } - } - - private final class EndpointListenerTracker extends ServiceTracker<EndpointListener, EndpointListener> { - private EndpointListenerTracker(BundleContext context) { - super(context, EndpointListener.class, null); - } - - @Override - public EndpointListener addingService(ServiceReference<EndpointListener> reference) { - EndpointListener listener = super.addingService(reference); - notifier.add(listener, EndpointListenerNotifier.getFiltersFromEndpointListenerScope(reference)); - return listener; - } - - @Override - public void modifiedService(ServiceReference<EndpointListener> reference, - EndpointListener listener) { - super.modifiedService(reference, listener); - notifier.add(listener, EndpointListenerNotifier.getFiltersFromEndpointListenerScope(reference)); - } - - @Override - public void removedService(ServiceReference<EndpointListener> reference, - EndpointListener listener) { - notifier.remove(listener); - super.removedService(reference, listener); - } - } - - private final class RSATracker extends ServiceTracker<RemoteServiceAdmin, RemoteServiceAdmin> { - private RSATracker(BundleContext context, Class<RemoteServiceAdmin> clazz, - ServiceTrackerCustomizer<RemoteServiceAdmin, RemoteServiceAdmin> customizer) { - super(context, clazz, customizer); - } - - @Override - public RemoteServiceAdmin addingService(ServiceReference<RemoteServiceAdmin> reference) { - RemoteServiceAdmin rsa = super.addingService(reference); - LOG.debug("New RemoteServiceAdmin {} detected, trying to import and export services with it", rsa); - importManager.add(rsa); - exportManager.add(rsa); - return rsa; - } - - @Override - public void removedService(ServiceReference<RemoteServiceAdmin> reference, - RemoteServiceAdmin rsa) { - exportManager.remove(rsa); - importManager.remove(rsa); - super.removedService(reference, rsa); - } - } -} http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/DefaultExportPolicy.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/DefaultExportPolicy.java b/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/DefaultExportPolicy.java deleted file mode 100644 index 689ebab..0000000 --- a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/DefaultExportPolicy.java +++ /dev/null @@ -1,37 +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.cxf.dosgi.topologymanager.exporter; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.cxf.dosgi.dsw.api.ExportPolicy; -import org.osgi.framework.ServiceReference; - -/** - * The default is to not customize the way services are exported - */ -public class DefaultExportPolicy implements ExportPolicy { - - @Override - public Map<String, ?> additionalParameters(ServiceReference<?> sref) { - return new HashMap<String, Object>(); - } - -} http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java b/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java deleted file mode 100644 index 13d7dab..0000000 --- a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java +++ /dev/null @@ -1,133 +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.cxf.dosgi.topologymanager.exporter; - -import java.util.Dictionary; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -import org.osgi.framework.Filter; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; -import org.osgi.service.remoteserviceadmin.EndpointDescription; -import org.osgi.service.remoteserviceadmin.EndpointListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Tracks EndpointListeners and allows to notify them of endpoints. - */ -public class EndpointListenerNotifier implements EndpointListener { - private static final Logger LOG = LoggerFactory.getLogger(EndpointListenerNotifier.class); - private enum NotifyType { ADDED, REMOVED }; - private Map<EndpointListener, Set<Filter>> listeners; - private EndpointRepository endpointRepo; - - public EndpointListenerNotifier(final EndpointRepository endpointRepo) { - this.endpointRepo = endpointRepo; - this.listeners = new ConcurrentHashMap<EndpointListener, Set<Filter>>(); - } - - public static Set<Filter> getFiltersFromEndpointListenerScope(ServiceReference<EndpointListener> sref) { - Set<Filter> filters = new HashSet<Filter>(); - String[] scopes = StringPlus.parse(sref.getProperty(EndpointListener.ENDPOINT_LISTENER_SCOPE)); - for (String scope : scopes) { - try { - filters.add(FrameworkUtil.createFilter(scope)); - } catch (InvalidSyntaxException e) { - LOG.error("invalid endpoint listener scope: {}", scope, e); - } - } - return filters; - } - - public void add(EndpointListener ep, Set<Filter> filters) { - LOG.debug("new EndpointListener detected"); - listeners.put(ep, filters); - for (EndpointDescription endpoint : endpointRepo.getAllEndpoints()) { - notifyListener(NotifyType.ADDED, ep, filters, endpoint); - } - } - - public void remove(EndpointListener ep) { - LOG.debug("EndpointListener modified"); - listeners.remove(ep); - } - - @Override - public void endpointAdded(EndpointDescription endpoint, String matchedFilter) { - notifyListeners(NotifyType.ADDED, endpoint); - } - - @Override - public void endpointRemoved(EndpointDescription endpoint, String matchedFilter) { - notifyListeners(NotifyType.REMOVED, endpoint); - } - - /** - * Notifies all endpoint listeners about endpoints being added or removed. - * - * @param added specifies whether endpoints were added (true) or removed (false) - * @param endpoints the endpoints the listeners should be notified about - */ - private void notifyListeners(NotifyType type, EndpointDescription endpoint) { - for (EndpointListener listener : listeners.keySet()) { - notifyListener(type, listener, listeners.get(listener), endpoint); - } - } - - /** - * Notifies an endpoint listener about endpoints being added or removed. - * - * @param type specifies whether endpoints were added (true) or removed (false) - * @param endpointListenerRef the ServiceReference of an EndpointListener to notify - * @param endpoints the endpoints the listener should be notified about - */ - private void notifyListener(NotifyType type, EndpointListener listener, Set<Filter> filters, - EndpointDescription endpoint) { - LOG.debug("Endpoint {}", type); - Set<Filter> matchingFilters = getMatchingFilters(filters, endpoint); - for (Filter filter : matchingFilters) { - if (type == NotifyType.ADDED) { - listener.endpointAdded(endpoint, filter.toString()); - } else { - listener.endpointRemoved(endpoint, filter.toString()); - } - } - } - - private static Set<Filter> getMatchingFilters(Set<Filter> filters, EndpointDescription endpoint) { - Set<Filter> matchingFilters = new HashSet<Filter>(); - Dictionary<String, Object> dict = new Hashtable<String, Object>(endpoint.getProperties()); - for (Filter filter : filters) { - if (filter.match(dict)) { - LOG.debug("Filter {} matches endpoint {}", filter, dict); - matchingFilters.add(filter); - } else { - LOG.trace("Filter {} does not match endpoint {}", filter, dict); - } - } - return matchingFilters; - } - -} http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java b/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java deleted file mode 100644 index 2a7bab3..0000000 --- a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java +++ /dev/null @@ -1,140 +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.cxf.dosgi.topologymanager.exporter; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.osgi.framework.ServiceReference; -import org.osgi.service.remoteserviceadmin.EndpointDescription; -import org.osgi.service.remoteserviceadmin.EndpointListener; -import org.osgi.service.remoteserviceadmin.RemoteServiceAdmin; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Holds all endpoints that are exported by a TopologyManager. For each ServiceReference that is exported a - * map is maintained which contains information on the endpoints for each RemoteAdminService that created the - * endpoints. - */ -@SuppressWarnings("rawtypes") -public class EndpointRepository { - - private static final Logger LOG = LoggerFactory.getLogger(EndpointRepository.class); - - private final Map<ServiceReference, Map<RemoteServiceAdmin, Collection<EndpointDescription>>> exportedServices - = new LinkedHashMap<ServiceReference, Map<RemoteServiceAdmin, Collection<EndpointDescription>>>(); - - private EndpointListener notifier; - - public void setNotifier(EndpointListener notifier) { - this.notifier = notifier; - } - - - /** - * Remove all services exported by the given rsa. - * - * @param rsa the RemoteServiceAdmin to remove - * @return list of removed endpoints - */ - public synchronized List<EndpointDescription> removeRemoteServiceAdmin(RemoteServiceAdmin rsa) { - LOG.debug("RemoteServiceAdmin removed: {}", rsa.getClass().getName()); - List<EndpointDescription> removedEndpoints = new ArrayList<EndpointDescription>(); - for (Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports : exportedServices.values()) { - Collection<EndpointDescription> endpoints = exports.get(rsa); - if (endpoints != null) { - removedEndpoints.addAll(endpoints); - exports.remove(rsa); - } - } - endpointsRemoved(removedEndpoints); - return removedEndpoints; - } - - public synchronized void removeService(ServiceReference sref) { - List<EndpointDescription> removedEndpoints = new ArrayList<EndpointDescription>(); - Map<RemoteServiceAdmin, Collection<EndpointDescription>> rsaToEndpoints = exportedServices.get(sref); - if (rsaToEndpoints != null) { - for (Collection<EndpointDescription> endpoints : rsaToEndpoints.values()) { - removedEndpoints.addAll(endpoints); - } - exportedServices.remove(sref); - } - endpointsRemoved(removedEndpoints); - } - - public synchronized void addService(ServiceReference sref) { - if (!exportedServices.containsKey(sref)) { - LOG.info("Marking service from bundle {} for export", sref.getBundle().getSymbolicName()); - exportedServices.put(sref, new LinkedHashMap<RemoteServiceAdmin, Collection<EndpointDescription>>()); - } - } - - public synchronized void addEndpoints(ServiceReference sref, RemoteServiceAdmin rsa, - List<EndpointDescription> endpoints) { - addService(sref); - Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports = exportedServices.get(sref); - exports.put(rsa, endpoints); - endpointsAdded(endpoints); - } - - synchronized boolean isAlreadyExportedForRsa(ServiceReference sref, RemoteServiceAdmin rsa) { - Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports = exportedServices.get(sref); - return exports != null && exports.containsKey(rsa); - } - - public synchronized Collection<EndpointDescription> getAllEndpoints() { - List<EndpointDescription> allEndpoints = new ArrayList<EndpointDescription>(); - for (Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports : exportedServices.values()) { - for (Collection<EndpointDescription> endpoints : exports.values()) { - allEndpoints.addAll(endpoints); - } - } - return allEndpoints; - } - - public synchronized Set<ServiceReference> getServicesToBeExportedFor(RemoteServiceAdmin rsa) { - Set<ServiceReference> servicesToBeExported = new HashSet<ServiceReference>(); - for (Map.Entry<ServiceReference, Map<RemoteServiceAdmin, Collection<EndpointDescription>>> entry - : exportedServices.entrySet()) { - if (!entry.getValue().containsKey(rsa)) { - servicesToBeExported.add(entry.getKey()); - } - } - return servicesToBeExported; - } - - private void endpointsAdded(List<EndpointDescription> endpoints) { - for (EndpointDescription epd : endpoints) { - notifier.endpointAdded(epd, null); - } - } - - private void endpointsRemoved(List<EndpointDescription> endpoints) { - for (EndpointDescription epd : endpoints) { - notifier.endpointRemoved(epd, null); - } - } -} http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/StringPlus.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/StringPlus.java b/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/StringPlus.java deleted file mode 100644 index 1198154..0000000 --- a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/StringPlus.java +++ /dev/null @@ -1,57 +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.cxf.dosgi.topologymanager.exporter; - -import java.util.Collection; - -public final class StringPlus { - - private StringPlus() { - } - - /** - * Returns the value of a "string+" property as an array of strings. - * <p> - * A "string+" property can have a value which is either a string, - * an array of strings, or a collection of strings. - * <p> - * If the given value is not of one of the valid types, or is null, - * an empty array is returned. - * - * @param property a "string+" property value - * @return the property value as an array of strings, or an empty array - */ - public static String[] parse(Object property) { - if (property instanceof String) { - return new String[] {(String)property}; - } else if (property instanceof String[]) { - return (String[])property; - } else if (property instanceof Collection) { - try { - @SuppressWarnings("unchecked") - Collection<String> strings = (Collection<String>)property; - return strings.toArray(new String[strings.size()]); - } catch (ArrayStoreException ase) { - // ignore collections with wrong type - } - } - return new String[0]; - } - -} http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java b/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java deleted file mode 100644 index ad3736c..0000000 --- a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java +++ /dev/null @@ -1,195 +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.cxf.dosgi.topologymanager.exporter; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.Executor; - -import org.apache.cxf.dosgi.dsw.api.ExportPolicy; -import org.osgi.framework.Bundle; -import org.osgi.framework.ServiceEvent; -import org.osgi.framework.ServiceListener; -import org.osgi.framework.ServiceReference; -import org.osgi.service.remoteserviceadmin.EndpointDescription; -import org.osgi.service.remoteserviceadmin.ExportReference; -import org.osgi.service.remoteserviceadmin.ExportRegistration; -import org.osgi.service.remoteserviceadmin.RemoteConstants; -import org.osgi.service.remoteserviceadmin.RemoteServiceAdmin; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Manages exported endpoints of DOSGi services and notifies EndpointListeners of changes. - * - * <li> Tracks local RemoteServiceAdmin instances by using a ServiceTracker - * <li> Uses a ServiceListener to track local OSGi services - * <li> When a service is published that is supported by DOSGi the - * known RemoteServiceAdmins are instructed to export the service and - * the EndpointListeners are notified - * <li> When a service is unpublished the EndpointListeners are notified. - * The endpoints are not closed as the ExportRegistration takes care of this - */ -public class TopologyManagerExport implements ServiceListener { - private static final Logger LOG = LoggerFactory.getLogger(TopologyManagerExport.class); - - private final Executor execService; - private final EndpointRepository endpointRepo; - private ExportPolicy policy; - private final Set<RemoteServiceAdmin> rsaSet; - - - public TopologyManagerExport(final EndpointRepository endpointRepo, Executor executor, ExportPolicy policy) { - this.endpointRepo = endpointRepo; - this.policy = policy; - this.rsaSet = new HashSet<RemoteServiceAdmin>(); - this.execService = executor; - } - - // track all service registrations so we can export any services that are configured to be exported - // ServiceListener events may be delivered out of order, concurrently, re-entrant, etc. (see spec or docs) - public void serviceChanged(ServiceEvent event) { - ServiceReference<?> sref = event.getServiceReference(); - if (event.getType() == ServiceEvent.REGISTERED) { - LOG.debug("Received REGISTERED ServiceEvent: {}", event); - export(sref); - } else if (event.getType() == ServiceEvent.UNREGISTERING) { - LOG.debug("Received UNREGISTERING ServiceEvent: {}", event); - endpointRepo.removeService(sref); - } - } - - public void add(RemoteServiceAdmin rsa) { - rsaSet.add(rsa); - for (ServiceReference<?> serviceRef : endpointRepo.getServicesToBeExportedFor(rsa)) { - export(serviceRef); - } - }; - - public void remove(RemoteServiceAdmin rsa) { - rsaSet.remove(rsa); - endpointRepo.removeRemoteServiceAdmin(rsa); - }; - - private void export(final ServiceReference<?> sref) { - execService.execute(new Runnable() { - public void run() { - doExport(sref); - } - }); - } - - private void doExport(final ServiceReference<?> sref) { - Map<String, ?> addProps = policy.additionalParameters(sref); - if (!shouldExport(sref, addProps)) { - LOG.debug("Skipping service {}", sref); - return; - } - LOG.debug("Exporting service {}", sref); - endpointRepo.addService(sref); // mark for future export even if there are currently no RSAs - if (rsaSet.size() == 0) { - LOG.error("No RemoteServiceAdmin available! Unable to export service from bundle {}, interfaces: {}", - getSymbolicName(sref.getBundle()), - sref.getProperty(org.osgi.framework.Constants.OBJECTCLASS)); - return; - } - - for (RemoteServiceAdmin remoteServiceAdmin : rsaSet) { - LOG.info("TopologyManager: handling remoteServiceAdmin " + remoteServiceAdmin); - if (endpointRepo.isAlreadyExportedForRsa(sref, remoteServiceAdmin)) { - // already handled by this remoteServiceAdmin - LOG.debug("already handled by this remoteServiceAdmin -> skipping"); - } else { - - exportServiceUsingRemoteServiceAdmin(sref, remoteServiceAdmin, addProps); - } - } - } - - private boolean shouldExport(ServiceReference<?> sref, Map<String, ?> addProps) { - String exported = (String)sref.getProperty(RemoteConstants.SERVICE_EXPORTED_INTERFACES); - String addExported = (String)addProps.get(RemoteConstants.SERVICE_EXPORTED_INTERFACES); - String effectiveExported = addExported != null ? addExported : exported; - return (effectiveExported != null) && !effectiveExported.isEmpty(); - } - - private Object getSymbolicName(Bundle bundle) { - return bundle == null ? null : bundle.getSymbolicName(); - } - - private void exportServiceUsingRemoteServiceAdmin(final ServiceReference<?> sref, - final RemoteServiceAdmin remoteServiceAdmin, - Map<String, ?> addProps) { - // abort if the service was unregistered by the time we got here - // (we check again at the end, but this optimization saves unnecessary heavy processing) - if (sref.getBundle() == null) { - LOG.info("TopologyManager: export aborted for {} since it was unregistered", sref); - endpointRepo.removeService(sref); - return; - } - // do the export - LOG.debug("exporting {}...", sref); - // TODO: additional parameter Map? - Collection<ExportRegistration> exportRegs = remoteServiceAdmin.exportService(sref, addProps); - // process successful/failed registrations - List<EndpointDescription> endpoints = new ArrayList<EndpointDescription>(); - for (ExportRegistration reg : exportRegs) { - if (reg.getException() == null) { - EndpointDescription endpoint = getExportedEndpoint(reg); - LOG.info("TopologyManager: export succeeded for {}, endpoint ", sref, endpoint); - endpoints.add(endpoint); - } else { - LOG.error("TopologyManager: export failed for {}", sref); - reg.close(); - } - } - // abort export if service was unregistered in the meanwhile (since we have a race - // with the unregister event which may have already been handled, so we'll miss it) - if (sref.getBundle() == null) { - LOG.info("TopologyManager: export reverted for {} since service was unregistered", sref); - endpointRepo.removeService(sref); - for (ExportRegistration reg : exportRegs) { - reg.close(); - } - return; - } - // add the new exported endpoints - if (!endpoints.isEmpty()) { - LOG.info("TopologyManager: export successful for {}, endpoints: {}", sref, endpoints); - endpointRepo.addEndpoints(sref, remoteServiceAdmin, endpoints); - } - } - - /** - * Retrieves an exported Endpoint (while safely handling nulls). - * - * @param exReg an export registration - * @return exported Endpoint or null if not present - */ - private EndpointDescription getExportedEndpoint(ExportRegistration exReg) { - ExportReference ref = (exReg == null) ? null : exReg.getExportReference(); - return (ref == null) ? null : ref.getExportedEndpoint(); - } - - -} http://git-wip-us.apache.org/repos/asf/aries-rsa/blob/d73a3a7f/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/EndpointListenerManager.java ---------------------------------------------------------------------- diff --git a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/EndpointListenerManager.java b/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/EndpointListenerManager.java deleted file mode 100644 index 7812e52..0000000 --- a/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/importer/EndpointListenerManager.java +++ /dev/null @@ -1,98 +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.cxf.dosgi.topologymanager.importer; - -import java.util.ArrayList; -import java.util.Dictionary; -import java.util.Hashtable; -import java.util.List; - -import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; -import org.osgi.service.remoteserviceadmin.EndpointListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Manages an EndpointListener and adjusts its scope according to requested service filters. - */ -public class EndpointListenerManager { - - private static final Logger LOG = LoggerFactory.getLogger(EndpointListenerManager.class); - - private final BundleContext bctx; - private volatile ServiceRegistration<EndpointListener> serviceRegistration; - private final List<String> filters = new ArrayList<String>(); - private final EndpointListener endpointListener; - - public EndpointListenerManager(BundleContext bc, EndpointListener endpointListener) { - this.bctx = bc; - this.endpointListener = endpointListener; - } - - protected void start() { - serviceRegistration = bctx.registerService(EndpointListener.class, endpointListener, - getRegistrationProperties()); - } - - public void stop() { - if (serviceRegistration != null) { - serviceRegistration.unregister(); - } - } - - protected void extendScope(String filter) { - if (filter == null) { - return; - } - LOG.debug("EndpointListener: extending scope by {}", filter); - synchronized (filters) { - filters.add(filter); - } - updateRegistration(); - } - - protected void reduceScope(String filter) { - if (filter == null) { - return; - } - LOG.debug("EndpointListener: reducing scope by {}", filter); - synchronized (filters) { - filters.remove(filter); - } - updateRegistration(); - } - - private Dictionary<String, Object> getRegistrationProperties() { - Dictionary<String, Object> p = new Hashtable<String, Object>(); - - synchronized (filters) { - LOG.debug("Current filter: {}", filters); - p.put(EndpointListener.ENDPOINT_LISTENER_SCOPE, new ArrayList<String>(filters)); - } - - return p; - } - - private void updateRegistration() { - if (serviceRegistration != null) { - serviceRegistration.setProperties(getRegistrationProperties()); - } - } -}
