You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by lr...@apache.org on 2012/12/11 08:12:56 UTC

svn commit: r1420013 - /incubator/wink/trunk/wink-osgi/src/main/java/org/apache/wink/osgi/WinkRequestProcessor.java

Author: lresende
Date: Tue Dec 11 07:12:54 2012
New Revision: 1420013

URL: http://svn.apache.org/viewvc?rev=1420013&view=rev
Log:
WINK-375 - Applying patch from Reto Bachmann-Gmür to re-register previously unregistered service in a OSGi environment

Modified:
    incubator/wink/trunk/wink-osgi/src/main/java/org/apache/wink/osgi/WinkRequestProcessor.java

Modified: incubator/wink/trunk/wink-osgi/src/main/java/org/apache/wink/osgi/WinkRequestProcessor.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-osgi/src/main/java/org/apache/wink/osgi/WinkRequestProcessor.java?rev=1420013&r1=1420012&r2=1420013&view=diff
==============================================================================
--- incubator/wink/trunk/wink-osgi/src/main/java/org/apache/wink/osgi/WinkRequestProcessor.java (original)
+++ incubator/wink/trunk/wink-osgi/src/main/java/org/apache/wink/osgi/WinkRequestProcessor.java Tue Dec 11 07:12:54 2012
@@ -114,17 +114,22 @@ public class WinkRequestProcessor {
 	 *            The new JAX-RS component (root resource or provider) to bind.
 	 */
 	public void bindComponent(Object component) {
-		components.add(component);
 		if (requestProcessor != null) {
+			ensureNotOutdated();
 			registerComponent(component);
 		}
+		//has to be called after ensureUpdate as endureUpdate might cause reinitialization
+		//based on components
+		synchronized (this) {
+			components.add(component);
+		}
 	}
 	
 	/**
 	 * @param component
 	 *            The new JAX-RS component (root resource or provider) to bind.
 	 */
-	public void unbindComponent(Object component) {
+	public synchronized void unbindComponent(Object component) {
 		components.remove(component);
 		//since it seems not possible to remove from RequestProcessor
 		//we need to create a new one, we defer this to prevent
@@ -142,9 +147,11 @@ public class WinkRequestProcessor {
 	
 	private void ensureNotOutdated() {
 		if (requestProcessorOutdated) {
-			requestProcessorOutdated = false;
 			synchronized(this) {
-				init();
+				if (requestProcessorOutdated) {
+					init();
+					requestProcessorOutdated = false;
+				}
 			}
 		}
 	}
@@ -160,10 +167,8 @@ public class WinkRequestProcessor {
 	}
 
 	private void registerComponent(Object component) {
-		ensureNotOutdated();
 		Application application = new InnerApplication(component);
 		requestProcessor.getConfiguration().addApplication(application, false);
-		components.add(component);
 		//FIXME: fix this to comply with externalization requirements
 		//log.info("registered component {}", component);
 	}