]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - eclipse/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/spring/ApplicationContextTracker.java
Update license headers
[lgpl/argeo-commons.git] / eclipse / runtime / org.argeo.eclipse.ui / src / main / java / org / argeo / eclipse / spring / ApplicationContextTracker.java
index 805d11d8a580632bc71acc7eb72bc2e19f8e35fc..fcd42bab68c4af0c8d3d186a8f0b00f704b26875 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
- * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>\r
+ * Copyright (C) 2007-2012 Mathieu Baudier\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
@@ -13,7 +13,6 @@
  * See the License for the specific language governing permissions and\r
  * limitations under the License.\r
  */\r
-\r
 package org.argeo.eclipse.spring;\r
 \r
 import static java.text.MessageFormat.format;\r
@@ -30,6 +29,8 @@ import org.osgi.util.tracker.ServiceTracker;
 import org.springframework.context.ApplicationContext;\r
 \r
 /**\r
+ * Tracks Spring application context published as services.\r
+ * \r
  * @author Heiko Seeberger\r
  * @author Mathieu Baudier\r
  */\r
@@ -40,6 +41,11 @@ class ApplicationContextTracker {
        private static final String FILTER = "(&(objectClass=org.springframework.context.ApplicationContext)" //$NON-NLS-1$\r
                        + "(org.springframework.context.service.name={0}))"; //$NON-NLS-1$\r
 \r
+       public final static String APPLICATION_CONTEXT_TRACKER_TIMEOUT = "org.argeo.eclipse.spring.applicationContextTrackerTimeout";\r
+\r
+       private static Long defaultTimeout = Long.parseLong(System.getProperty(\r
+                       APPLICATION_CONTEXT_TRACKER_TIMEOUT, "30000"));\r
+\r
        private ServiceTracker applicationContextServiceTracker;\r
 \r
        /**\r
@@ -59,12 +65,18 @@ class ApplicationContextTracker {
                        applicationContextServiceTracker = new ServiceTracker(\r
                                        factoryBundleContext, FrameworkUtil.createFilter(filter),\r
                                        null);\r
-                       applicationContextServiceTracker.open();\r
+                       // applicationContextServiceTracker.open();\r
                } catch (final InvalidSyntaxException e) {\r
                        e.printStackTrace();\r
                }\r
        }\r
 \r
+       public void open() {\r
+               if (applicationContextServiceTracker != null) {\r
+                       applicationContextServiceTracker.open();\r
+               }\r
+       }\r
+\r
        public void close() {\r
                if (applicationContextServiceTracker != null) {\r
                        applicationContextServiceTracker.close();\r
@@ -76,7 +88,7 @@ class ApplicationContextTracker {
                if (applicationContextServiceTracker != null) {\r
                        try {\r
                                applicationContext = (ApplicationContext) applicationContextServiceTracker\r
-                                               .waitForService(5000);\r
+                                               .waitForService(defaultTimeout);\r
                        } catch (InterruptedException e) {\r
                                e.printStackTrace();\r
                        }\r
@@ -102,8 +114,9 @@ class ApplicationContextTracker {
                if (contributorBundle.getState() != Bundle.ACTIVE\r
                                && contributorBundle.getState() != Bundle.STARTING) {\r
                        try {\r
-                               log.info("Starting bundle: "\r
-                                               + contributorBundle.getSymbolicName());\r
+                               if (log.isTraceEnabled())\r
+                                       log.trace("Starting bundle: "\r
+                                                       + contributorBundle.getSymbolicName());\r
                                contributorBundle.start();\r
                        } catch (BundleException e) {\r
                                e.printStackTrace();\r
@@ -114,6 +127,7 @@ class ApplicationContextTracker {
                                contributorBundle, contributorBundle.getBundleContext());\r
                ApplicationContext applicationContext = null;\r
                try {\r
+                       applicationContextTracker.open();\r
                        applicationContext = applicationContextTracker\r
                                        .getApplicationContext();\r
                } finally {\r