felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uiter...@apache.org
Subject svn commit: r1487106 [2/2] - in /felix/sandbox/uiterlix/MTDMTest: ./ .settings/ src/ src/nl/ src/nl/uiterlinden/ src/nl/uiterlinden/mtdmtest/ src/nl/uiterlinden/mtdmtest/a/ src/nl/uiterlinden/mtdmtest/aspect/ src/nl/uiterlinden/mtdmtest/b/ src/nl/uiter...
Date Tue, 28 May 2013 20:38:14 GMT
Added: felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/instance/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/instance/Activator.java?rev=1487106&view=auto
==============================================================================
--- felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/instance/Activator.java (added)
+++ felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/instance/Activator.java Tue
May 28 20:38:13 2013
@@ -0,0 +1,45 @@
+package nl.uiterlinden.mtdmtest.instance;
+
+import nl.uiterlinden.mtdmtest.base.Node;
+
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+
+public class Activator extends DependencyActivatorBase {
+	
+	private static DependencyManager manager;
+
+	@Override
+	public void init(BundleContext context, final DependencyManager manager)
+			throws Exception {
+		
+		Activator.manager = manager;
+		new Thread(new Runnable() {
+
+			@Override
+			public void run() {
+				try {
+					Thread.sleep(1000);
+					manager.add(createComponent().setInterface(Node.class.getName(), null).setImplementation(NodeImpl.class));
+				} catch (InterruptedException e) {
+					e.printStackTrace();
+				}
+				
+			}
+			
+		}).start();
+//		manager.add(createComponent().setInterface(Node.class.getName(), null).setImplementation(NodeImpl.class));
+	}
+
+	@Override
+	public void destroy(BundleContext context, DependencyManager manager)
+			throws Exception {
+
+	}
+
+	public static DependencyManager dependencyManager() {
+		return manager;
+	}
+	
+}

Added: felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/instance/NodeImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/instance/NodeImpl.java?rev=1487106&view=auto
==============================================================================
--- felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/instance/NodeImpl.java (added)
+++ felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/instance/NodeImpl.java Tue
May 28 20:38:13 2013
@@ -0,0 +1,188 @@
+package nl.uiterlinden.mtdmtest.instance;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import nl.uiterlinden.mtdmtest.base.InstanceProvider;
+import nl.uiterlinden.mtdmtest.base.InstanceProviderImpl;
+import nl.uiterlinden.mtdmtest.base.Node;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+
+public class NodeImpl implements Node {
+	
+	private static final int COUNT = Node.PRODUCER_COUNT;
+	List<Component> components = new ArrayList<Component>();
+	private final AtomicInteger count = new AtomicInteger(0);
+	Executor executor = Executors.newFixedThreadPool(Node.THREADCOUNT);
+	private final AtomicBoolean registered = new AtomicBoolean(false);
+
+	@Override
+	public void register(final int run) {
+		try {
+			doRegister(run);
+			Thread.sleep(100);
+			waitForRegister();
+			doUnregister(run);
+			Thread.sleep(100);
+			waitForUnRegister();
+			doRegister(run);
+			Thread.sleep(100);
+			waitForRegister();
+			doUnregister(run);
+			Thread.sleep(100);
+			waitForUnRegister();
+			doRegister(run);
+			Thread.sleep(100);
+			waitForRegister();
+			registered.set(true);
+		} catch (InterruptedException ie) {
+			
+		}
+	}
+	
+	private void waitForRegister() {
+		boolean cont = false;
+		while (!cont) {
+			try {
+				Thread.sleep(20);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+			cont = count.get() == COUNT && components.size() == COUNT;
+		}
+	}
+	
+	private void waitForUnRegister() {
+		boolean cont = false;
+		while (!cont) {
+			try {
+				Thread.sleep(20);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+			cont = unregistered();
+		}
+	}
+
+	private void doRegister(final int run) {
+		final DependencyManager manager = Activator.dependencyManager();
+		System.out.println(run + " Register instance providers " + components.size() + "/" + count.get());
+		for (int i = 0; i < COUNT; i++) {
+			final int number = i;
+			Runnable runnable = new Runnable() {
+				@Override
+				public void run() {
+					try {
+//						Thread.sleep(5);
+						InstanceProvider instanceProviderImpl = new InstanceProviderImpl("" + number);
+						Properties props = new Properties();
+						props.setProperty("instanceprovider.id", "" + number);
+						props.setProperty("test.run", "" + run);
+						Component producer = manager.createComponent().setInterface(InstanceProvider.class.getName(),
props)
+								.setImplementation(instanceProviderImpl);
+						manager.add(producer);
+						synchronized(components) {
+							components.add(producer);
+							count.incrementAndGet();
+						}
+
+//						Component producerWannabe = manager.createComponent().setInterface(ProducerWannabe.class.getName(),
null)
+//								.setImplementation(ProducerWannabeImpl.class);
+//							
+//						manager.add(producerWannabe);
+//						synchronized(components) {
+//							components.add(producerWannabe);
+//						}
+//						count.incrementAndGet();
+
+					} catch (Exception e) {
+						e.printStackTrace();
+					}
+				}
+			};
+			if (Node.THREADCOUNT > 1) {
+				executor.execute(runnable);
+			} else {
+				runnable.run();
+			}
+		}
+		// wait for completion
+		while (count.get() < (COUNT)) {
+			try {
+				Thread.sleep(10);
+//				System.out.println("waiting for producer launch.. " + count);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+		}
+		System.out.println(run + " Registered instance providers " + components.size() + "/" +
count.get());
+	}
+
+	@Override
+	public void unregister(int run) {
+		doUnregister(run);
+	}
+
+	private void doUnregister(int run) {
+		// also multithreaded removal
+		final DependencyManager manager = Activator.dependencyManager();
+		System.out.println(run + " clearing instance providers... " + components.size() + "/" +
count.get());
+		for (Component component : components) {
+			final Component componentToRemove = component;
+			Runnable runnable = new Runnable() {
+
+				@Override
+				public void run() {
+					manager.remove(componentToRemove);
+					count.decrementAndGet();
+				}
+			};
+			if (Node.THREADCOUNT > 1) {
+				executor.execute(runnable);
+			} else {
+				runnable.run();
+			}
+		}
+		int sleep = 0;
+		while (count.get() > 0) {
+			try {
+				Thread.sleep(10);
+				sleep = sleep + 10;
+				if (sleep == 1000) {
+					System.out.println("problem...");
+				}
+//				System.out.println("waiting for producer cleanup.. " + count);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+		}
+		synchronized (components) {
+			components.clear();
+		}
+		System.out.println(run + " cleared instance providers... " + components.size() + "/" +
count.get());
+		registered.set(false);
+	}
+
+	@Override
+	public boolean registered() {
+		return registered.get();
+	}
+
+	@Override
+	public boolean unregistered() {
+		return count.get() == 0 && components.isEmpty();
+	}
+	
+	@Override
+	public String toString() {
+		return "Producers";
+	}
+
+}

Added: felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/instancebound/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/instancebound/Activator.java?rev=1487106&view=auto
==============================================================================
--- felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/instancebound/Activator.java
(added)
+++ felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/instancebound/Activator.java
Tue May 28 20:38:13 2013
@@ -0,0 +1,68 @@
+package nl.uiterlinden.mtdmtest.instancebound;
+
+import java.util.Properties;
+
+import nl.uiterlinden.mtdmtest.base.Producer;
+import nl.uiterlinden.mtdmtest.base.ProducerImpl;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+
+public class Activator extends DependencyActivatorBase {
+	
+	private volatile DependencyManager dependencyManager;
+
+	@Override
+	public void init(BundleContext context, DependencyManager manager)
+			throws Exception {
+
+		manager.add(createComponent().setImplementation(this));
+		
+	}
+
+	@Override
+	public void destroy(BundleContext context, DependencyManager manager)
+			throws Exception {
+		// TODO Auto-generated method stub
+
+	}
+	
+	void init(final Component component) {
+		System.out.println("init");
+		
+		System.out.println("Add dependeny on producer 1");
+		component.add(dependencyManager.createServiceDependency().setService(Producer.class, "(producer.id=1)").setRequired(true).setInstanceBound(true));
+		try {
+			// launching separate thread to start producer 1
+			Runnable r = new Runnable() {
+
+				@Override
+				public void run() {
+					Producer producer = new ProducerImpl("1");
+					Properties props = new Properties();
+					props.setProperty("producer.id", producer.getId());
+					component.getDependencyManager().add(createComponent().setInterface(Producer.class.getName(),
props).setImplementation(producer));
+				}
+			};
+			new Thread(r).start();
+			System.out.println("Sleeping");
+			Thread.sleep(100);
+		} catch (InterruptedException e) {
+			e.printStackTrace();
+		}
+		System.out.println("Add dependeny on producer 2");
+		component.add(dependencyManager.createServiceDependency().setService(Producer.class, "(producer.id=2)").setRequired(true).setInstanceBound(true));
+		
+	}
+	
+	void start() {
+		System.out.println("start");
+	}
+	
+	void stop() {
+		System.out.println("stop");
+	}
+
+}

Added: felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/run/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/run/Activator.java?rev=1487106&view=auto
==============================================================================
--- felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/run/Activator.java (added)
+++ felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/run/Activator.java Tue May
28 20:38:13 2013
@@ -0,0 +1,67 @@
+package nl.uiterlinden.mtdmtest.run;
+import nl.uiterlinden.mtdmtest.base.Node;
+import nl.uiterlinden.mtdmtest.base.Producer;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.ServiceDependency;
+import org.osgi.framework.BundleContext;
+
+public class Activator extends DependencyActivatorBase {
+
+	@Override
+	public void init(BundleContext context, DependencyManager manager)
+			throws Exception {
+
+		
+		Component coordinator = createComponent().setImplementation(Coordinator.class);
+		coordinator.add(createServiceDependency().setService(Node.class).setCallbacks("addNode",
"removeNode"));
+//		ServiceDependency dependency = createServiceDependency().setService(Producer.class)
+//				.setCallbacks("addProducer", null, "removeProducer", "swapProducer");
+//		coordinator.add(dependency);
+		manager.add(coordinator);
+		
+//		Component sidekick = createComponent().setImplementation(SideKick.class);
+//		dependency = createServiceDependency().setService(Producer.class, "(producer.id=5)")
+//				.setCallbacks("addProducer", null, "removeProducer", "swapProducer").setRequired(true);
+////		dependency.enableDebug("5");
+//		sidekick.add(dependency);
+//		dependency = createServiceDependency().setService(Producer.class, "(producer.id=7)")
+//				.setCallbacks("addProducer", null, "removeProducer", "swapProducer").setRequired(true);
+//		sidekick.add(dependency);
+////		dependency.enableDebug("7");
+//		dependency = createServiceDependency().setService(Producer.class, "(producer.id=9)")
+//				.setCallbacks("addProducer", null, "removeProducer", "swapProducer").setRequired(true);
+//		sidekick.add(dependency);
+////		dependency.enableDebug("9");
+//		dependency = createServiceDependency().setService(Producer.class, "(producer.id=11)")
+//				.setCallbacks("addProducer", null, "removeProducer", "swapProducer").setRequired(true);
+//		sidekick.add(dependency);
+////		dependency.enableDebug("11");
+//		dependency = createServiceDependency().setService(Producer.class, "(producer.id=15)")
+//				.setCallbacks("addProducer", null, "removeProducer", "swapProducer").setRequired(true);
+//		sidekick.add(dependency);
+////		dependency.enableDebug("15");
+//		dependency = createServiceDependency().setService(Producer.class, "(producer.id=17)")
+//				.setCallbacks("addProducer", null, "removeProducer", "swapProducer").setRequired(true);
+//		sidekick.add(dependency);
+////		dependency.enableDebug("17");
+//		dependency = createServiceDependency().setService(Producer.class, "(producer.id=19)")
+//				.setCallbacks("addProducer", null, "removeProducer", "swapProducer").setRequired(true);
+//		sidekick.add(dependency);
+////		dependency.enableDebug("19");
+//		dependency = createServiceDependency().setService(Producer.class).setRequired(true);
+//		sidekick.add(dependency);
+//		dependency = createServiceDependency().setService(Node.class).setRequired(true);
+//		sidekick.add(dependency);
+//		manager.add(sidekick);
+	}
+
+	@Override
+	public void destroy(BundleContext context, DependencyManager manager)
+			throws Exception {
+
+	}
+
+}

Added: felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/run/Coordinator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/run/Coordinator.java?rev=1487106&view=auto
==============================================================================
--- felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/run/Coordinator.java (added)
+++ felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/run/Coordinator.java Tue May
28 20:38:13 2013
@@ -0,0 +1,247 @@
+package nl.uiterlinden.mtdmtest.run;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import nl.uiterlinden.mtdmtest.base.Node;
+import nl.uiterlinden.mtdmtest.base.Producer;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.Dependency;
+import org.apache.felix.dm.DependencyManager;
+import org.apache.felix.dm.ServiceDependency;
+import org.osgi.framework.ServiceReference;
+
+public class Coordinator {
+	
+	private static final int WAIT_TIME = 2000; // wait two seconds after launch
+	private volatile DependencyManager manager;
+	private volatile Component component;
+	private Map<ServiceReference, Producer> producers = new HashMap<ServiceReference,
Producer>();
+	private Map<ServiceReference, Node> nodes = new HashMap<ServiceReference, Node>();
+	private int index = 0;
+	private int run = 1;
+
+	void addNode(ServiceReference ref, Node node) {
+		System.out.println("added node: " + node.getClass().getName());
+		nodes.put(ref, node);
+	}
+	
+	void init() {
+		System.out.println("Using " + Node.THREADCOUNT + " threads.");
+	}
+	
+	void start() {
+		System.out.println("Start!");
+		new Thread(new Runnable() {
+			boolean shouldRun = true;
+			public void run() {
+				
+				Component sidekick = createSideKick();
+				System.out.println("Adding sidekick");
+				manager.add(sidekick);
+				
+				while (nodes.size() != 4) {
+					try {
+						Thread.sleep(500);
+					} catch (InterruptedException e) {
+						e.printStackTrace();
+					}
+					System.out.println("Waiting for nodes...");
+				}
+				
+				System.out.println(run + " nodes register");
+				for (Node node : nodes.values()) {
+					final Node n = node;
+					Runnable runnable = new Runnable() {
+
+						@Override
+						public void run() {
+							n.register(run);
+						}
+					};
+					if (Node.THREADCOUNT > 1) {
+						new Thread(runnable).start();
+					} else {
+						runnable.run();
+					}
+				}
+				
+				boolean cont = false;
+				while (!cont) {
+					try {
+						Thread.sleep(10);
+					} catch (InterruptedException e) {
+						e.printStackTrace();
+					}
+					cont = true;
+					for (Node node : nodes.values()) {
+						cont &= node.registered();
+					}
+				}
+//				System.out.println("Wait and see what happens...");
+//				try {
+//					Thread.sleep(1000);
+//				} catch (InterruptedException e1) {
+//					e1.printStackTrace();
+//				}
+				
+				System.out.println(run + " nodes unregister");
+				for (Node node : nodes.values()) {
+					final Node n = node;
+					Runnable runnable = new Runnable() {
+
+						@Override
+						public void run() {
+							n.unregister(run);
+						}
+					};
+					if (Node.THREADCOUNT > 1) {
+						new Thread(runnable).start();
+					} else {
+						runnable.run();
+					}
+				}
+				
+				cont = false;
+				while (!cont) {
+					try {
+						Thread.sleep(10);
+					} catch (InterruptedException e) {
+						e.printStackTrace();
+					}
+					cont = true;
+					for (Node node : nodes.values()) {
+//						System.out.println(node + ": " + node.unregistered());
+						cont &= node.unregistered();
+					}
+//					System.out.println("cont: " + cont);
+				}
+				
+				synchronized (producers) {
+					System.out.println("producers: " + producers.size());
+					if (producers.size() > 0) {
+						throw new IllegalStateException("Invalid producer count...");
+					}
+					for (Object depObject : component.getDependencies()) {
+						Dependency dep = (Dependency) depObject;
+						System.out.println("dep: " + dep.isAvailable() + " -> " + dep);
+					}
+				}
+				System.out.println("Done!");
+				System.out.println("removing sidekick");
+				manager.remove(sidekick);
+				run ++;
+//				try {
+//					Thread.sleep(5000);
+//				} catch (InterruptedException e) {
+//					e.printStackTrace();
+//				}
+				Coordinator.this.start();
+			}
+		}).start();
+	}
+	
+	Component createSideKick() {
+		Component sidekick = manager.createComponent().setImplementation(SideKick.class);
+		for (int i = 0; i < Node.PRODUCER_COUNT; i++) {
+		ServiceDependency dependency = manager.createServiceDependency().setService(Producer.class,
"(producer.id=" + i + ")")
+				.setCallbacks("addProducer", null, "removeProducer", "swapProducer").setRequired(true);
+//		dependency.enableDebug("prod");
+		sidekick.add(dependency);
+		}
+//		dependency = manager.createServiceDependency().setService(Producer.class, "(producer.id=7)")
+//				.setCallbacks("addProducer", null, "removeProducer", "swapProducer").setRequired(true);
+//		sidekick.add(dependency);
+////		dependency.enableDebug("7");
+//		dependency = manager.createServiceDependency().setService(Producer.class, "(producer.id=9)")
+//				.setCallbacks("addProducer", null, "removeProducer", "swapProducer").setRequired(true);
+//		sidekick.add(dependency);
+////		dependency.enableDebug("9");
+//		dependency = manager.createServiceDependency().setService(Producer.class, "(producer.id=11)")
+//				.setCallbacks("addProducer", null, "removeProducer", "swapProducer").setRequired(true);
+//		sidekick.add(dependency);
+////		dependency.enableDebug("11");
+//		dependency = manager.createServiceDependency().setService(Producer.class, "(producer.id=15)")
+//				.setCallbacks("addProducer", null, "removeProducer", "swapProducer").setRequired(true);
+//		sidekick.add(dependency);
+////		dependency.enableDebug("15");
+//		dependency = manager.createServiceDependency().setService(Producer.class, "(producer.id=17)")
+//				.setCallbacks("addProducer", null, "removeProducer", "swapProducer").setRequired(true);
+//		sidekick.add(dependency);
+////		dependency.enableDebug("17");
+//		dependency = manager.createServiceDependency().setService(Producer.class, "(producer.id=19)")
+//				.setCallbacks("addProducer", null, "removeProducer", "swapProducer").setRequired(true);
+//		sidekick.add(dependency);
+//		dependency.enableDebug("19");
+//		dependency = manager.createServiceDependency().setService(Producer.class).setRequired(true);
+//		sidekick.add(dependency);
+//		dependency = manager.createServiceDependency().setService(Node.class).setRequired(true);
+//		sidekick.add(dependency);
+		return sidekick;
+	}
+	
+	void removeNode(Node node) {
+	}
+	
+	void addProducer(ServiceReference ref, Producer producer) {
+		if (ref == null || producer == null) {
+			System.err.println("Missing argument...");
+			System.exit(0);
+		}
+		synchronized (producers) {
+//			System.out.println("****  " + Thread.currentThread().getId() + " #" + index + " @" +
producer.getId() + " add " + ref);
+			producers.put(ref, producer);
+			index ++;
+		}
+	}
+	
+	void removeProducer(ServiceReference ref, Producer producer) {
+		if (ref == null || producer == null) {
+			System.err.println("Missing argument...");
+			System.exit(0);
+		}
+		synchronized (producers) {
+//			System.out.println("****  " + Thread.currentThread().getId() + " #" + index + " remove
" + ref);
+			if (!producers.containsKey(ref)) {
+				System.err.println("Illegal remove!");
+				System.err.println("**** #" + index + " remove " + ref);
+				System.exit(0);
+				throw new IllegalStateException("Cannot remove a producer that does not exist!");
+			}
+			producers.remove(ref);
+			index ++;
+		}
+	}
+	
+	void swapProducer(ServiceReference oldRef, Producer oldProducer, ServiceReference newRef,
Producer newProducer) {
+		if (oldRef == null || oldProducer == null || newRef == null || newProducer == null) {
+			System.err.println("Missing argument...");
+			System.exit(0);
+		}
+		if (!newProducer.getId().equals(oldProducer.getId())) {
+			System.err.println("Wrong producer swap, id's mismatch...\n" + oldRef + "\n" + newRef);
+			System.exit(0);
+		}
+		synchronized (producers) {
+//			System.out.println("****  " + Thread.currentThread().getId() + " #" + index + " @" +
newProducer.getId() + " " + newRef.getProperty("service.ranking") + " replaces " + oldRef.getProperty("service.ranking"));
+			if (!producers.containsKey(oldRef)) {
+				System.err.println("Illegal swap!");
+				System.err.println("****  #" + index + " @" + newProducer.getId() + " " + newRef.getProperty("service.ranking")
+ " replaces " + oldRef.getProperty("service.ranking"));
+				// dump refs for this producer
+				System.out.println("current admin for " + newProducer.getId());
+				for (Entry<ServiceReference, Producer> entry : producers.entrySet()) {
+					if (entry.getValue().getId().equals(newProducer.getId())) {
+						System.out.println("ref: " + entry.getKey());
+					}
+				}
+				System.out.println("Breakpoint opportunity");
+				System.exit(0);
+			}
+			producers.remove(oldRef);
+			producers.put(newRef, newProducer);
+			index ++;
+		}
+	}
+}

Added: felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/run/SideKick.java
URL: http://svn.apache.org/viewvc/felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/run/SideKick.java?rev=1487106&view=auto
==============================================================================
--- felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/run/SideKick.java (added)
+++ felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/run/SideKick.java Tue May
28 20:38:13 2013
@@ -0,0 +1,107 @@
+package nl.uiterlinden.mtdmtest.run;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import nl.uiterlinden.mtdmtest.base.Node;
+import nl.uiterlinden.mtdmtest.base.Producer;
+
+import org.apache.felix.dm.Component;
+import org.osgi.framework.ServiceReference;
+
+public class SideKick  {
+
+	private Map<ServiceReference, Producer> producers = new HashMap<ServiceReference,
Producer>();
+	private int index;
+	private volatile Node node;
+	private volatile Producer p;
+	private volatile Component c;
+
+	void init() {
+		System.out.println(Thread.currentThread().getId() + " SIDEKICK INIT!");
+		synchronized (producers) {
+			if (producers.size() != Node.PRODUCER_COUNT) { // || node == null || p == null) {
+				System.out.println("producer count: " + producers.size());
+				System.err.println("EARLY INIT (SIDEKICK)");
+				System.exit(13);
+			}
+		}
+	}
+	
+	void start() {
+		System.out.println(Thread.currentThread().getId() + " SIDEKICK START!");
+		synchronized (producers) {
+			if (producers.size() != Node.PRODUCER_COUNT) { // || node == null || p == null) {
+				System.out.println("producer count: " + producers.size());
+				System.err.println("EARLY START (SIDEKICK)");
+				System.exit(13);
+			}
+		}
+	}
+
+	void addProducer(ServiceReference ref, Producer producer) {
+		if (ref == null || producer == null) {
+			System.err.println("Missing argument...");
+			System.exit(0);
+		}
+		synchronized (producers) {
+			System.out.println("****  " + Thread.currentThread().getId() + " #" + index + " @" + producer.getId()
+ " add " + ref);
+			producers.put(ref, producer);
+			index ++;
+		}
+//		try {
+//			Thread.sleep(500);
+//		} catch (InterruptedException e) {
+//			e.printStackTrace();
+//		}
+	}
+	
+	void removeProducer(ServiceReference ref, Producer producer) {
+		if (ref == null || producer == null) {
+			System.err.println("Missing argument...");
+			System.exit(0);
+		}
+		synchronized (producers) {
+			System.out.println("****  " + Thread.currentThread().getId() + " #" + index + " remove
" + ref);
+			if (!producers.containsKey(ref)) {
+				System.err.println("Illegal remove!");
+				System.err.println("**** #" + index + " remove " + ref);
+				System.exit(0);
+				throw new IllegalStateException("Cannot remove a producer that does not exist!");
+			}
+			producers.remove(ref);
+			index ++;
+		}
+	}
+	
+	void swapProducer(ServiceReference oldRef, Producer oldProducer, ServiceReference newRef,
Producer newProducer) {
+		if (oldRef == null || oldProducer == null || newRef == null || newProducer == null) {
+			System.err.println("Missing argument...");
+			System.exit(0);
+		}
+		if (!newProducer.getId().equals(oldProducer.getId())) {
+			System.err.println("Wrong producer swap, id's mismatch...\n" + oldRef + "\n" + newRef);
+			System.exit(0);
+		}
+		synchronized (producers) {
+			System.out.println("****  " + Thread.currentThread().getId() + " #" + index + " @" + newProducer.getId()
+ " " + newRef.getProperty("service.ranking") + " replaces " + oldRef.getProperty("service.ranking"));
+			if (!producers.containsKey(oldRef)) {
+				System.err.println("Illegal swap (side)!");
+				System.err.println("****  " + Thread.currentThread().getId() + " #" + index + " @" +
newProducer.getId() + " " + newRef.getProperty("service.ranking") + " replaces " + oldRef.getProperty("service.ranking"));
+				// dump refs for this producer
+				System.out.println("current admin for " + newProducer.getId());
+				for (Entry<ServiceReference, Producer> entry : producers.entrySet()) {
+					if (entry.getValue().getId().equals(newProducer.getId())) {
+						System.out.println("ref: " + entry.getKey());
+					}
+				}
+				System.out.println("Breakpoint opportunity");
+				System.exit(0);
+			}
+			producers.remove(oldRef);
+			producers.put(newRef, newProducer);
+			index ++;
+		}
+	}
+}

Added: felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/simple/Activator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/simple/Activator.java?rev=1487106&view=auto
==============================================================================
--- felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/simple/Activator.java (added)
+++ felix/sandbox/uiterlix/MTDMTest/src/nl/uiterlinden/mtdmtest/simple/Activator.java Tue
May 28 20:38:13 2013
@@ -0,0 +1,91 @@
+package nl.uiterlinden.mtdmtest.simple;
+
+import java.util.Properties;
+
+import nl.uiterlinden.mtdmtest.base.InstanceProvider;
+import nl.uiterlinden.mtdmtest.base.InstanceProviderImpl;
+import nl.uiterlinden.mtdmtest.base.Producer;
+import nl.uiterlinden.mtdmtest.base.ProducerImpl;
+import nl.uiterlinden.mtdmtest.base.ProducerWannabe;
+import nl.uiterlinden.mtdmtest.base.ProducerWannabeImpl;
+
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+public class Activator extends DependencyActivatorBase {
+
+	@Override
+	public void init(BundleContext context, DependencyManager manager)
+			throws Exception {
+
+		Producer producer = new ProducerImpl("1");
+		producer.setVerbose(true);
+		
+		ProducerWannabe wb = new ProducerWannabeImpl();
+		Properties wbProps = new Properties();
+		wbProps.setProperty("producerwannabe.id", producer.getId());
+		Component wbComponent = manager.createComponent().setInterface(ProducerWannabe.class.getName(),
wbProps).setImplementation(wb);
+		System.out.println("add wannabeproducer");
+		manager.add(wbComponent);
+		
+		InstanceProvider ip = new InstanceProviderImpl(producer.getId());
+		Properties ipProps = new Properties();
+		ipProps.setProperty("instanceprovider.id", "" + producer.getId());
+		Component ipComponent = manager.createComponent().setInterface(InstanceProvider.class.getName(),
ipProps).setImplementation(ip);
+		System.out.println("add instanceprovider");
+		manager.add(ipComponent);
+		
+		Properties props1 = new Properties();
+		props1.setProperty("producer.id", producer.getId());
+		Component producerComponent1 = manager.createComponent().setInterface(Producer.class.getName(),
props1).setImplementation(producer);
+		System.out.println("add producer");
+		manager.add(producerComponent1);
+		
+		System.out.println("remove wannabeproducer");
+		manager.remove(wbComponent);
+		System.out.println("remove instanceprovider");
+		manager.remove(ipComponent);
+		System.out.println("remove producer");
+		manager.remove(producerComponent1);
+		
+		System.out.println("done!");
+		
+	}
+
+	@Override
+	public void destroy(BundleContext context, DependencyManager manager)
+			throws Exception {
+
+	}
+	
+	void init() {
+		System.out.println("init");
+	}
+
+	void start() {
+		System.out.println("start");
+	}
+	
+	void stop() {
+		System.out.println("stop");
+	}
+	
+	void destroy() {
+		System.out.println("destroy");
+	}
+	
+	void addProducer(ServiceReference ref, Producer producer) {
+		System.out.println("*** add: " + ref);
+	}
+	
+	void removeProducer(ServiceReference ref, Producer producer) {
+		System.out.println("*** remove: " + ref);
+	}
+	
+	void swapProducer(ServiceReference oldRef, Producer oldProducer, ServiceReference newRef,
Producer newProducer) {
+		System.out.println("*** swap: " + newRef);
+	}
+}

Added: felix/sandbox/uiterlix/MTDMTest/test/.gitignore
URL: http://svn.apache.org/viewvc/felix/sandbox/uiterlix/MTDMTest/test/.gitignore?rev=1487106&view=auto
==============================================================================
    (empty)

Added: felix/sandbox/uiterlix/MTDMTest/test/nl/uiterlinden/mtdmtest/index/MultiPropertyFilterIndexTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/uiterlix/MTDMTest/test/nl/uiterlinden/mtdmtest/index/MultiPropertyFilterIndexTest.java?rev=1487106&view=auto
==============================================================================
--- felix/sandbox/uiterlix/MTDMTest/test/nl/uiterlinden/mtdmtest/index/MultiPropertyFilterIndexTest.java
(added)
+++ felix/sandbox/uiterlix/MTDMTest/test/nl/uiterlinden/mtdmtest/index/MultiPropertyFilterIndexTest.java
Tue May 28 20:38:13 2013
@@ -0,0 +1,301 @@
+package nl.uiterlinden.mtdmtest.index;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceReference;
+
+public class MultiPropertyFilterIndexTest {
+
+	public MultiPropertyFilterIndexTest() {
+		
+	}
+	
+	@Before
+	public void setUp() {
+		
+	}
+	
+	@Test
+	public void testSimpleIndexConfiguration() {
+		AdvancedMultiPropertyFilterIndex index = new AdvancedMultiPropertyFilterIndex("objectClass");
+		Collection<Property> properties = index.getProperties();
+		assertEquals(properties.size(), 1);
+		
+		Property property = properties.iterator().next();
+		assertEquals("objectclass", property.getKey());
+	}
+	
+	@Test
+	public void testMultiIndexConfiguration() {
+		AdvancedMultiPropertyFilterIndex index = new AdvancedMultiPropertyFilterIndex("objectClass,name");
+		Collection<Property> properties = index.getProperties();
+		assertEquals(properties.size(), 2);
+		
+		Iterator<Property> propertyIterator = properties.iterator();
+		Property property = propertyIterator.next();
+		assertEquals("objectclass", property.getKey());
+		assertEquals(false, property.isNegate());
+		
+		property = propertyIterator.next();
+		assertEquals("name", property.getKey());
+		assertEquals(false, property.isNegate());
+	}
+	
+	@Test
+	public void testMultiIndexConfigurationWithNegate() {
+		AdvancedMultiPropertyFilterIndex index = new AdvancedMultiPropertyFilterIndex("objectClass,name,!city*");
+		Collection<Property> properties = index.getProperties();
+		assertEquals(properties.size(), 3);
+		
+		Iterator<Property> propertyIterator = properties.iterator();
+		Property property = propertyIterator.next();
+		assertEquals("objectclass", property.getKey());
+		assertEquals(false, property.isNegate());
+		
+		property = propertyIterator.next();
+		assertEquals("name", property.getKey());
+		assertEquals(false, property.isNegate());
+		
+		property = propertyIterator.next();
+		assertEquals("city", property.getKey());
+		assertEquals("*", property.getValue());
+		assertEquals(true, property.isNegate());
+		assertEquals(true, property.isWildcard());
+	}
+	
+	@Test
+	public void testFilterTokenizerSimple() {
+		String filterString = "(&(objectClass=OBJECTCLASS)(&(model=MODEL)(concept=CONCEPT)(role=ROLE)(!(context=*))))";
+		Filter filter = Filter.parse(filterString);
+		
+		assertEquals(true, filter.isValid());
+		Set<String> propertyKeys = filter.getPropertyKeys();
+		assertEquals(5, propertyKeys.size());
+		
+		assertEquals(true, filter.containsProperty("objectclass"));
+		assertEquals(true, filter.containsProperty("model"));
+		assertEquals(true, filter.containsProperty("concept"));
+		assertEquals(true, filter.containsProperty("role"));
+		assertEquals(true, filter.containsProperty("context"));
+	}
+
+	@Test
+	public void testFilterTokenizerMulti() {
+		String filterString = "(&(objectClass=OBJECTCLASS)(&(model=MODEL)(concept=CONCEPT1)(concept=CONCEPT2)(role=ROLE)(!(context=*))))";
+		Filter filter = Filter.parse(filterString);
+		
+		assertEquals(true, filter.isValid());
+		Set<String> propertyKeys = filter.getPropertyKeys();
+		assertEquals(5, propertyKeys.size());
+		
+		assertEquals(true, filter.containsProperty("objectclass"));
+		assertEquals(true, filter.containsProperty("model"));
+		assertEquals(true, filter.containsProperty("concept"));
+		assertEquals(true, filter.containsProperty("role"));
+		assertEquals(true, filter.containsProperty("context"));
+		Property conceptProperty = filter.getProperty("concept");
+		Set<String> values = conceptProperty.getValues();
+		assertEquals(2, values.size());
+	}
+	
+	@Test
+	public void testFilterApplicableSimple() {
+		AdvancedMultiPropertyFilterIndex index = new AdvancedMultiPropertyFilterIndex("objectClass,name");
+		assertEquals(true, index.isApplicable(null, "(&(objectClass=c)(name=a))"));
+		assertEquals(true, index.isApplicable("c", "(name=a)"));
+		assertEquals(false, index.isApplicable(null, "(name=a)"));
+		assertEquals(true, index.isApplicable(null, "(&(objectClass=c)(name=a)(name=b))"));
+		assertEquals(false, index.isApplicable(null, "(&(objectClass=c)(!(name=a))"));
+		assertEquals(false, index.isApplicable(null, "(&(objectClass=c)(name=*))"));
+		assertEquals(false, index.isApplicable(null, "(&(objectClass=c)(name=a)(name=b)(city=x)"));
+		assertEquals(true, index.isApplicable(null, "(&(objectClass=c)(name=a & b))"));
+		index = new AdvancedMultiPropertyFilterIndex("name");
+		assertEquals(false, index.isApplicable(null, "(&(objectClass=c)(name=a))"));
+		assertEquals(false, index.isApplicable("c", null));
+		
+		index = new AdvancedMultiPropertyFilterIndex("objectClass");
+		assertEquals(true, index.isApplicable("c", null));
+	}
+	
+	@Test
+	public void testReferenceApplicableSimple() {
+		AdvancedMultiPropertyFilterIndex index = new AdvancedMultiPropertyFilterIndex("objectClass,name");
+		assertEquals(true, index.isApplicable(new ServiceReferenceImpl().set("objectClass", "a").set("name","b")));
+		assertEquals(true, index.isApplicable(new ServiceReferenceImpl().set("objectClass", "a").set("name","b").set("name","c")));
+		assertEquals(false, index.isApplicable(new ServiceReferenceImpl().set("objectClass", "a")));
+		assertEquals(false, index.isApplicable(new ServiceReferenceImpl().set("name", "b")));
+		assertEquals(false, index.isApplicable(new ServiceReferenceImpl().set("objectClass", "a").set("city","b")));
+	}
+	
+	@Test
+	public void testFilterCreateKey() {
+		assertEquals(Filter.parse("(&(objectClass=c)(name=a))").createKey(), "name=a;objectclass=c");
+		assertEquals(Filter.parse("(&(x=a)(y=c))").createKey(), "x=a;y=c");
+		assertEquals(Filter.parse("(&(y=c)(x=a))").createKey(), "x=a;y=c");
+		assertEquals(Filter.parse("(&(name=a)(name=c))").createKey(), "name=a;name=c");
+		assertEquals(Filter.parse("(&(name=c)(name=a))").createKey(), "name=a;name=c");
+	}
+	
+	@Test
+	public void testCreateKeysFromServiceReference() {
+		AdvancedMultiPropertyFilterIndex index = new AdvancedMultiPropertyFilterIndex("objectClass,name,city");
+		ServiceReferenceImpl ref = new ServiceReferenceImpl().set("objectClass", "a").set("name",
"b").set("city","c");
+		assertEquals("[city=c;name=b;objectclass=a]", index.createKeys(ref).toString());
+		ref = new ServiceReferenceImpl().set("objectClass", "a").set("name", "b").set("city", "c").set("county","d");
+		assertEquals("[city=c;name=b;objectclass=a]", index.createKeys(ref).toString());
+		ref = new ServiceReferenceImpl().set("objectClass", "a").set("name", new String[] {"b",
"a"});
+		assertEquals("[name=a;objectclass=a, name=a;name=b;objectclass=a, name=b;objectclass=a]",
index.createKeys(ref).toString());
+		ref = new ServiceReferenceImpl().set("z", new String[] { "p", "q" }).set("x", new String[]
{"b", "a"});
+		assertEquals("[]", index.createKeys(ref).toString());
+		ref = new ServiceReferenceImpl().set("name", new String[] { "a", "b" }).set("city", new
String[] {"c", "d"});
+		assertEquals("[city=c;name=a, city=c;city=d;name=a, city=d;name=a, city=c;name=a;name=b,
city=c;city=d;name=a;name=b, city=d;name=a;name=b, city=c;name=b, city=c;city=d;name=b, city=d;name=b]",
index.createKeys(ref).toString());
+	}
+	
+	@Test
+	public void testCreateKeyFromFilter() {
+		AdvancedMultiPropertyFilterIndex index = new AdvancedMultiPropertyFilterIndex("objectClass,x");
+		assertEquals("objectclass=MyClass;x=1", index.createKeyFromFilter("MyClass", "(x=1)"));
+		assertEquals("objectclass=MyClass;x=1;y=2", index.createKeyFromFilter("MyClass", "(&(x=1)(y=2))"));
+		
+		assertEquals("objectclass=MyClass;x=1", index.createKeyFromFilter("MyClass", "(&(x=1)(!(y=*)))"));
+	}
+	
+	@Test
+	public void testSimpleReferenceAdd() {
+		AdvancedMultiPropertyFilterIndex index = new AdvancedMultiPropertyFilterIndex("objectclass,name");
+		
+		ServiceReferenceImpl ref = new ServiceReferenceImpl().set("objectClass", "MyClass");
+		assertEquals(false, index.isApplicable(ref));
+		
+		ref = new ServiceReferenceImpl().set("objectClass", "MyClass").set("name", "x");
+		assertEquals(true, index.isApplicable(ref));
+		index.addedService(ref, new Object());
+		
+		assertEquals(true, index.isApplicable("MyClass", "(name=x)"));
+		List references = index.getAllServiceReferences("MyClass", "(name=x)");
+		assertEquals(references.size(), 1);
+		
+		ref = new ServiceReferenceImpl().set("objectClass", "MyClass").set("name", new String[]
{ "y", "x" });
+		assertEquals(true, index.isApplicable(ref));
+		index.addedService(ref, new Object());
+		
+		assertEquals(true, index.isApplicable("MyClass", "(name=y)"));
+		references = index.getAllServiceReferences("MyClass", "(name=y)");
+		assertEquals(references.size(), 1);
+		
+		assertEquals(true, index.isApplicable("MyClass", "(&(name=y)(name=x))"));
+		references = index.getAllServiceReferences("MyClass", "(&(name=y)(name=x))");
+		assertEquals(references.size(), 1);
+		
+		assertEquals(true, index.isApplicable("MyClass", "(name=x)"));
+		references = index.getAllServiceReferences("MyClass", "(name=x)");
+		assertEquals(references.size(), 2);
+		
+		// remove
+		index.removedService(ref, new Object());
+		references = index.getAllServiceReferences("MyClass", "(name=x)");
+		assertEquals(references.size(), 1);
+		
+		ref = new ServiceReferenceImpl().set("objectClass", "MyClass").set("name", "a & b");
+		assertEquals(true, index.isApplicable(ref));
+		index.addedService(ref, new Object());
+		
+		assertEquals(true, index.isApplicable("MyClass", "(name=a & b)"));
+		references = index.getAllServiceReferences("MyClass", "(name=a & b)");
+		assertEquals(references.size(), 1);
+
+	}
+	
+	@Test
+	public void testReferenceApplicableWithNegate() {
+		AdvancedMultiPropertyFilterIndex index = new AdvancedMultiPropertyFilterIndex("objectclass,name,!city*");
+		
+		ServiceReferenceImpl ref = new ServiceReferenceImpl().set("objectClass", "MyClass").set("name",
"x");
+		assertEquals(true, index.isApplicable(ref));
+		
+		ref = new ServiceReferenceImpl().set("objectClass", "MyClass").set("name", "x").set("city",
"y");
+		assertEquals(false, index.isApplicable(ref));
+		
+		ref = new ServiceReferenceImpl().set("objectClass", "MyClass").set("street", "x");
+		assertEquals(false, index.isApplicable(ref));
+		
+		ref = new ServiceReferenceImpl().set("objectClass", "MyClass").set("street", "x");
+		assertEquals(false, index.isApplicable(ref));
+	}
+	
+	@Test
+	public void testFilterApplicableWithNegate() {
+		AdvancedMultiPropertyFilterIndex index = new AdvancedMultiPropertyFilterIndex("objectclass,name,!city*");
+		
+		assertEquals(false, index.isApplicable(null, "(&(objectClass=c)(name=a))"));
+		assertEquals(true, index.isApplicable(null, "(&(objectClass=c)(name=a)(!(city=*))"));
+		assertEquals(false, index.isApplicable(null, "(&(objectClass=c)(name=a)(city=*)"));
+		assertEquals(true, index.isApplicable(null, "(&(objectClass=c)(name=a)(name=b)(!(city=*))"));
+	}
+	
+	@Test
+	public void testIndexWithNegateFilter() {
+		AdvancedMultiPropertyFilterIndex index = new AdvancedMultiPropertyFilterIndex("objectclass,name,!city*");
+
+		ServiceReferenceImpl ref = new ServiceReferenceImpl().set("objectClass", "MyClass").set("name",
"x").set("city", "y");
+		assertEquals(false, index.isApplicable(ref));
+		
+		ref = new ServiceReferenceImpl().set("objectClass", "MyClass").set("name", "x");
+		assertEquals(true, index.isApplicable(ref));
+		index.addedService(ref, new Object());
+		
+		
+		assertEquals(true, index.isApplicable("MyClass", "(&(name=x)(!(city=*))"));
+		List references = index.getAllServiceReferences("MyClass", "(&(name=x)(!(city=*))");
+		assertEquals(references.size(), 1);
+		
+		// remove
+		index.removedService(ref, new Object());
+		references = index.getAllServiceReferences("MyClass", "(&(name=x)(!(city=*))");
+		assertEquals(0, references.size());
+	}
+	
+	@Test
+	public void testSimpleServiceListener() {
+		AdvancedMultiPropertyFilterIndex index = new AdvancedMultiPropertyFilterIndex("objectclass,name");
+		
+		ServiceListenerImpl listener = new ServiceListenerImpl();
+		index.addServiceListener(listener, "(&(objectClass=MyClass)(name=x)");
+		assertEquals(index.getServiceListeners().size(), 1);
+		
+		ServiceReferenceImpl ref = new ServiceReferenceImpl().set("objectClass", "MyClass").set("name",
"x");
+		assertEquals(true, index.isApplicable(ref));
+		index.addedService(ref, new Object());
+		
+		ServiceEvent event = new ServiceEvent(1, ref);
+		index.serviceChanged(event);
+		assertEquals("[1]", listener.getChangeTypes());
+
+		ServiceReference irrelevantRef = new ServiceReferenceImpl().set("objectClass", "MyClass").set("name",
"x");
+		event = new ServiceEvent(1, irrelevantRef);
+		assertEquals("[1]", listener.getChangeTypes());
+		
+		index.removeServiceListener(listener);
+		event = new ServiceEvent(3, ref);
+		index.serviceChanged(event);
+		assertEquals("[1]", listener.getChangeTypes());
+		
+		index.addServiceListener(listener, "(&(objectClass=MyClass)(name=x)");
+		event = new ServiceEvent(3, ref);
+		index.serviceChanged(event);
+		assertEquals("[1, 3]", listener.getChangeTypes());
+		
+		// remove
+		index.removedService(ref, new Object());
+		List references = index.getAllServiceReferences("MyClass", "(name=x)");
+		assertEquals(0, references.size());
+	}
+}

Added: felix/sandbox/uiterlix/MTDMTest/test/nl/uiterlinden/mtdmtest/index/ServiceListenerImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/uiterlix/MTDMTest/test/nl/uiterlinden/mtdmtest/index/ServiceListenerImpl.java?rev=1487106&view=auto
==============================================================================
--- felix/sandbox/uiterlix/MTDMTest/test/nl/uiterlinden/mtdmtest/index/ServiceListenerImpl.java
(added)
+++ felix/sandbox/uiterlix/MTDMTest/test/nl/uiterlinden/mtdmtest/index/ServiceListenerImpl.java
Tue May 28 20:38:13 2013
@@ -0,0 +1,21 @@
+package nl.uiterlinden.mtdmtest.index;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+
+public class ServiceListenerImpl implements ServiceListener {
+
+	private List<Integer> changeTypes = new ArrayList<Integer>();
+	
+	@Override
+	public void serviceChanged(ServiceEvent event) {
+		changeTypes.add(event.getType());
+	}
+
+	public String getChangeTypes() {
+		return changeTypes.toString();
+	}
+}

Added: felix/sandbox/uiterlix/MTDMTest/test/nl/uiterlinden/mtdmtest/index/ServiceReferenceImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/uiterlix/MTDMTest/test/nl/uiterlinden/mtdmtest/index/ServiceReferenceImpl.java?rev=1487106&view=auto
==============================================================================
--- felix/sandbox/uiterlix/MTDMTest/test/nl/uiterlinden/mtdmtest/index/ServiceReferenceImpl.java
(added)
+++ felix/sandbox/uiterlix/MTDMTest/test/nl/uiterlinden/mtdmtest/index/ServiceReferenceImpl.java
Tue May 28 20:38:13 2013
@@ -0,0 +1,56 @@
+package nl.uiterlinden.mtdmtest.index;
+
+import java.util.Properties;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+
+public class ServiceReferenceImpl implements ServiceReference {
+	
+	Properties props = new Properties();
+	
+	public ServiceReferenceImpl() {
+		
+	}
+	
+	public ServiceReferenceImpl set(String key, String value) {
+		props.put(key.toLowerCase(), value);
+		return this;
+	}
+	
+	public ServiceReferenceImpl set(String key, String[] value) {
+		props.put(key.toLowerCase(), value);
+		return this;
+	}
+
+	@Override
+	public Object getProperty(String key) {
+		return props.get(key);
+	}
+
+	@Override
+	public String[] getPropertyKeys() {
+		return props.keySet().toArray(new String[]{});
+	}
+
+	@Override
+	public Bundle getBundle() {
+		return null;
+	}
+
+	@Override
+	public Bundle[] getUsingBundles() {
+		return null;
+	}
+
+	@Override
+	public boolean isAssignableTo(Bundle bundle, String className) {
+		return false;
+	}
+
+	@Override
+	public String toString() {
+		return "ServiceReferenceImpl [props=" + props + "]";
+	}
+
+}



Mime
View raw message