felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1567961 - in /felix/sandbox/marrs/dependencymanager-prototype/dm: src/dm/Dependency.java src/dm/impl/DependencyImpl.java test/test/ComponentTest.java
Date Thu, 13 Feb 2014 15:56:34 GMT
Author: marrs
Date: Thu Feb 13 15:56:33 2014
New Revision: 1567961

URL: http://svn.apache.org/r1567961
Log:
Added support for the 'change' callback.

Modified:
    felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/Dependency.java
    felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/impl/DependencyImpl.java
    felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ComponentTest.java

Modified: felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/Dependency.java
URL: http://svn.apache.org/viewvc/felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/Dependency.java?rev=1567961&r1=1567960&r2=1567961&view=diff
==============================================================================
--- felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/Dependency.java (original)
+++ felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/Dependency.java Thu Feb 13 15:56:33
2014
@@ -24,6 +24,7 @@ public interface Dependency {
 	public boolean isInstanceBound();
 	public void setInstanceBound(boolean instanceBound);
 	public void setCallbacks(String add, String remove);
+	public void setCallbacks(String add, String change, String remove);
 	
 	public void invokeAdd();
 	public void invokeRemove();

Modified: felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/impl/DependencyImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/impl/DependencyImpl.java?rev=1567961&r1=1567960&r2=1567961&view=diff
==============================================================================
--- felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/impl/DependencyImpl.java (original)
+++ felix/sandbox/marrs/dependencymanager-prototype/dm/src/dm/impl/DependencyImpl.java Thu
Feb 13 15:56:33 2014
@@ -12,6 +12,7 @@ public class DependencyImpl implements D
 	private boolean m_available;
 	private boolean m_instanceBound;
 	private String m_add;
+	private String m_change;
 	private String m_remove;
 	// TODO when we start injecting the "highest" one, this needs to be sorted at
 	// some point in time (note that we could choose to only do that if the dependency is
@@ -66,6 +67,9 @@ public class DependencyImpl implements D
 	protected void changeDependency(Event e) {
 		m_dependencies.remove(e);
 		m_dependencies.add(e);
+		if (m_component.isAvailable()) {
+			invokeChange(e);
+		}
 		m_component.handleChange();
 	}
 
@@ -115,6 +119,13 @@ public class DependencyImpl implements D
 	
 	public void setCallbacks(String add, String remove) {
 		m_add = add;
+		m_change = null;
+		m_remove = remove;
+	}
+	
+	public void setCallbacks(String add, String change, String remove) {
+		m_add = add;
+		m_change = change;
 		m_remove = remove;
 	}
 	
@@ -124,6 +135,12 @@ public class DependencyImpl implements D
 		}
 	}
 	
+	public void invokeChange() {
+		for (Event e : m_dependencies) {
+			invokeChange(e);
+		}
+	}
+	
 	public void invokeRemove() {
 		for (Event e : m_dependencies) {
 			invokeRemove(e);
@@ -140,6 +157,10 @@ public class DependencyImpl implements D
 		m_component.invokeCallbackMethod(getInstances(), m_add, new Class[][] {{}}, new Object[][]
{{}});
 	}
 	
+	public void invokeChange(Event e) {
+		m_component.invokeCallbackMethod(getInstances(), m_change, new Class[][] {{}}, new Object[][]
{{}});
+	}
+	
 	public void invokeRemove(Event e) {
 		// specific for this type of dependency
 		m_component.invokeCallbackMethod(getInstances(), m_remove, new Class[][] {{}}, new Object[][]
{{}});

Modified: felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ComponentTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ComponentTest.java?rev=1567961&r1=1567960&r2=1567961&view=diff
==============================================================================
--- felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ComponentTest.java (original)
+++ felix/sandbox/marrs/dependencymanager-prototype/dm/test/test/ComponentTest.java Thu Feb
13 15:56:33 2014
@@ -380,4 +380,41 @@ public class ComponentTest {
 		e.step(16);
 		Assert.assertEquals("component stopped, should be unavailable again", false, c.isAvailable());
 	}
+	
+	@Test
+	public void createComponentAddDependencyMakeAvailableChangeAndUnavailableWithCallbacks()
{
+		final Ensure e = new Ensure();
+		Component c = new ComponentImpl();
+		c.setImplementation(new Object() {
+			public void add() {
+				e.step(1);
+			}
+			public void change() {
+				e.step(3);
+			}
+			public void remove() {
+				e.step(5);
+			}
+		});
+		Dependency d1 = new DependencyImpl();
+		d1.setCallbacks("add", "change", "remove");
+		// add the dependency to the component
+		c.add(d1);
+		// start the component
+		c.start();
+		// make the dependency available, we expect the add callback
+		// to be invoked here
+		d1.add(new EventImpl());
+		e.step(2);
+		// change the dependency
+		d1.change(new EventImpl());
+		e.step(4);
+		// remove the dependency, should trigger the remove callback
+		d1.remove(new EventImpl());
+		e.step(6);
+		c.stop();
+		c.remove(d1);
+		Assert.assertEquals("component stopped, should be unavailable again", false, c.isAvailable());
+	}
+
 }



Mime
View raw message