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