Fix FELIX-2581 White Board Pattern onActivate called before @Validate
The handler must wait until the instance is started before opening the tracker.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@996284 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/handler/whiteboard/pom.xml b/ipojo/handler/whiteboard/pom.xml
index 8628924..8ea52a8 100644
--- a/ipojo/handler/whiteboard/pom.xml
+++ b/ipojo/handler/whiteboard/pom.xml
@@ -29,19 +29,19 @@
<artifactId> org.apache.felix.ipojo.handler.whiteboard </artifactId>
<groupId>org.apache.felix</groupId>
<version>1.5.0-SNAPSHOT</version>
-
+
<description>
iPOJO extension to easily implement a white-board pattern (host).
</description>
<url>
http://felix.apache.org/site/white-board-pattern-handler.html
</url>
-
+
<dependencies>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.ipojo</artifactId>
- <version>${project.version}</version>
+ <version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
@@ -68,7 +68,7 @@
<Private-Package> org.apache.felix.ipojo.handler.wbp
</Private-Package>
<Bundle-Name>${project.name}</Bundle-Name>
- <Include-Resource>
+ <Include-Resource>
META-INF/LICENSE=LICENSE,
META-INF/NOTICE=NOTICE,
META-INF/DEPENDENCIES=DEPENDENCIES
diff --git a/ipojo/handler/whiteboard/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardManager.java b/ipojo/handler/whiteboard/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardManager.java
index 47c34aa..d5077a2 100644
--- a/ipojo/handler/whiteboard/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardManager.java
+++ b/ipojo/handler/whiteboard/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardManager.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -32,37 +32,37 @@
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public class WhiteBoardManager implements TrackerCustomizer {
-
+
/**
- * The monitored filter.
+ * The monitored filter.
*/
private Filter m_filter;
-
+
/**
- * The onArrival method.
+ * The onArrival method.
*/
private Callback m_onArrival;
-
+
/**
- * The onDeparture method.
+ * The onDeparture method.
*/
private Callback m_onDeparture;
-
+
/**
- * The onModify method.
+ * The onModify method.
*/
private Callback m_onModification;
-
+
/**
- * The service tracker.
+ * The service tracker.
*/
private Tracker m_tracker;
-
+
/**
- * The attached handler.
+ * The attached handler.
*/
private PrimitiveHandler m_handler;
-
+
/**
* Constructor.
* @param handler the attached handler
@@ -81,14 +81,17 @@
m_filter = filter;
m_tracker = new Tracker(handler.getInstanceManager().getContext(), m_filter, this);
}
-
+
+
+
/**
* Opens the tracker.
*/
public void start() {
+ // Calling several times open is no-effect.
m_tracker.open();
}
-
+
/**
* Closes the tracker.
*/
diff --git a/ipojo/handler/whiteboard/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardPatternHandler.java b/ipojo/handler/whiteboard/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardPatternHandler.java
index 0f3e3d7..778eae7 100644
--- a/ipojo/handler/whiteboard/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardPatternHandler.java
+++ b/ipojo/handler/whiteboard/src/main/java/org/apache/felix/ipojo/handler/wbp/WhiteBoardPatternHandler.java
@@ -1,4 +1,4 @@
-/*
+/*
* 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
@@ -22,6 +22,7 @@
import java.util.Dictionary;
import java.util.List;
+import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.ConfigurationException;
import org.apache.felix.ipojo.PrimitiveHandler;
import org.apache.felix.ipojo.metadata.Element;
@@ -33,19 +34,19 @@
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public class WhiteBoardPatternHandler extends PrimitiveHandler {
-
+
/**
* The handler namespace.
*/
public static final String NAMESPACE = "org.apache.felix.ipojo.whiteboard";
-
+
/**
- * The white board pattern to manage. By default just one.
+ * The white board pattern to manage. By default just one.
*/
private List m_managers = new ArrayList(1);
/**
- * Configure method. Parses the metadata to analyze white-board-pattern elements.
+ * Configure method. Parses the metadata to analyze white-board-pattern elements.
* @param elem the component type description
* @param dict the instance description
* @throws ConfigurationException if the description is not valid.
@@ -58,14 +59,14 @@
String onArrival = elems[i].getAttribute("onArrival");
String onDeparture = elems[i].getAttribute("onDeparture");
String onModification = elems[i].getAttribute("onModification");
-
+
if (filter == null) {
throw new ConfigurationException("The white board pattern element requires a filter attribute");
}
if (onArrival == null || onDeparture == null) {
throw new ConfigurationException("The white board pattern element requires the onArrival and onDeparture attributes");
}
-
+
try {
WhiteBoardManager wbm = new WhiteBoardManager(this, getInstanceManager().getContext().createFilter(filter), onArrival, onDeparture, onModification);
m_managers.add(wbm);
@@ -73,27 +74,38 @@
throw new ConfigurationException("The filter " + filter + " is invalid : " + e);
}
}
-
+
}
/**
- * Start method. Starts managers.
+ * Start method.
* @see org.apache.felix.ipojo.Handler#start()
*/
public void start() {
- for (int i = 0; i < m_managers.size(); i++) {
- ((WhiteBoardManager) m_managers.get(i)).start();
- }
}
+
+
/**
+ * Start managers if we're valid.
+ * @see org.apache.felix.ipojo.Handler#stateChanged(int)
+ */
+ public void stateChanged(int state) {
+ if (state == ComponentInstance.VALID) {
+ for (int i = 0; i < m_managers.size(); i++) {
+ ((WhiteBoardManager) m_managers.get(i)).start();
+ }
+ }
+ }
+
+ /**
* Stop method. Stops managers.
* @see org.apache.felix.ipojo.Handler#stop()
*/
public void stop() {
for (int i = 0; i < m_managers.size(); i++) {
((WhiteBoardManager) m_managers.get(i)).stop();
- }
+ }
}
}