org.osgi.util.tracker.BundleTracker Java Examples

The following examples show how to use org.osgi.util.tracker.BundleTracker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlDocumentBundleTracker.java    From smarthome with Eclipse Public License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public final synchronized void open() {
    final OpenState openState = withLock(lockOpenState.writeLock(), () -> {
        if (this.openState == OpenState.CREATED) {
            this.openState = OpenState.OPENED;
        }
        return this.openState;
    });
    if (openState != OpenState.OPENED) {
        logger.warn("Open XML document bundle tracker forbidden (state: {})", openState);
        return;
    }

    relevantBundlesTracker = new BundleTracker(context,
            Bundle.RESOLVED | Bundle.STARTING | Bundle.STOPPING | Bundle.ACTIVE, null) {
        @Override
        public Object addingBundle(Bundle bundle, BundleEvent event) {
            return withLock(lockOpenState.readLock(),
                    () -> openState == OpenState.OPENED && isBundleRelevant(bundle) ? bundle : null);
        }
    };
    relevantBundlesTracker.open();

    super.open();
}
 
Example #2
Source File: DispatcherServletInitializer.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
public void start () throws ServletException, NamespaceException
{
    final BundleContext bundleContext = FrameworkUtil.getBundle ( DispatcherServletInitializer.class ).getBundleContext ();
    this.context = Dispatcher.createContext ( bundleContext );

    this.errorHandler = new ErrorHandlerTracker ();

    Dictionary<String, String> initparams = new Hashtable<> ();

    final MultipartConfigElement multipart = Servlets.createMultiPartConfiguration ( PROP_PREFIX_MP );
    final DispatcherServlet servlet = new DispatcherServlet ();
    servlet.setErrorHandler ( this.errorHandler );
    this.webContainer.registerServlet ( servlet, "dispatcher", new String[] { "/" }, initparams, 1, false, multipart, this.context );

    this.proxyFilter = new FilterTracker ( bundleContext );
    this.webContainer.registerFilter ( this.proxyFilter, new String[] { "/*" }, null, null, this.context );

    initparams = new Hashtable<> ();
    initparams.put ( "filter-mapping-dispatcher", "request" );
    this.webContainer.registerFilter ( new BundleFilter (), new String[] { "/bundle/*" }, null, initparams, this.context );

    this.jspTracker = new BundleTracker<> ( bundleContext, Bundle.INSTALLED | Bundle.ACTIVE, new JspBundleCustomizer ( this.webContainer, this.context ) );
    this.jspTracker.open ();
}
 
Example #3
Source File: ModelPackageBundleListener.java    From sling-org-apache-sling-models-impl with Apache License 2.0 5 votes vote down vote up
public ModelPackageBundleListener(BundleContext bundleContext,
                                  ModelAdapterFactory factory,
                                  AdapterImplementations adapterImplementations,
                                  BindingsValuesProvidersByContext bindingsValuesProvidersByContext,
                                  SlingModelsScriptEngineFactory scriptEngineFactory) {
    this.bundleContext = bundleContext;
    this.factory = factory;
    this.adapterImplementations = adapterImplementations;
    this.bindingsValuesProvidersByContext = bindingsValuesProvidersByContext;
    this.scriptEngineFactory = scriptEngineFactory;
    this.bundleTracker = new BundleTracker<>(bundleContext, Bundle.ACTIVE, this);
    this.bundleTracker.open();
}
 
Example #4
Source File: WebJarController.java    From wisdom with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the controller serving resources embedded in WebJars.
 *
 * @param context the bundle context
 * @param path    the path (relative to the configuration's base dir) in which exploded webjars are
 */
public WebJarController(@Context BundleContext context, @Property(value = "assets/libs",
        name = "path") String path) {
    directory = new File(configuration.getBaseDir(), path); //NOSONAR Injected field
    tracker = new BundleTracker<>(context, Bundle.ACTIVE, this);
    deployer = new WebJarDeployer(context, this);
}
 
Example #5
Source File: ServiceManagerExtender.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void init() throws Exception {
    if (started != null && started.equals(Boolean.TRUE)) {
        throw new IllegalStateException("ServiceManager is already initialized");
    }
    final DiscoveryRegistry registry = new DiscoveryRegistry();
    SystemInstance.get().setComponent(DiscoveryRegistry.class, registry);

    started = Boolean.FALSE;
    stopped = false;
    final ServerServiceTracker t = new ServerServiceTracker();
    tracker = new BundleTracker(bundleContext, Bundle.ACTIVE | Bundle.STOPPING, t);
    tracker.open();
}
 
Example #6
Source File: OsgiMessageInterpolator.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public OsgiMessageInterpolator ( final BundleContext context )
{
    this.tracker = new BundleTracker<> ( context, Bundle.ACTIVE | Bundle.RESOLVED, new BundleTrackerCustomizer<Resolver> () {

        @Override
        public Resolver addingBundle ( final Bundle bundle, final BundleEvent event )
        {
            if ( bundle.getResource ( "META-INF/ValidationMessages.properties" ) != null )
            {
                return new Resolver ( bundle );
            }
            return null;
        }

        @Override
        public void modifiedBundle ( final Bundle bundle, final BundleEvent event, final Resolver resolver )
        {
        }

        @Override
        public void removedBundle ( final Bundle bundle, final BundleEvent event, final Resolver resolver )
        {
            resolver.dispose ();
        }
    } );
    this.tracker.open ();
}
 
Example #7
Source File: TagLibTracker.java    From packagedrone with Eclipse Public License 1.0 5 votes vote down vote up
public TagLibTracker ( final BundleContext context, String mappedPrefix )
{
    this.systemTlds.add ( "org.apache.taglibs.standard-impl" );

    if ( mappedPrefix == null )
    {
        mappedPrefix = "/WEB-INF/";
    }
    this.mappedPrefix = mappedPrefix;

    this.bundleTracker = new BundleTracker<> ( context, Bundle.RESOLVED | Bundle.ACTIVE, this.customizer );
    this.bundleTracker.open ();
}
 
Example #8
Source File: XmlDocumentBundleTracker.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public final synchronized void open() {
    final OpenState openState = withLock(lockOpenState.writeLock(), () -> {
        if (this.openState == OpenState.CREATED) {
            this.openState = OpenState.OPENED;
        }
        return this.openState;
    });
    if (openState != OpenState.OPENED) {
        logger.warn("Open XML document bundle tracker forbidden (state: {})", openState);
        return;
    }

    relevantBundlesTracker = new BundleTracker(context,
            Bundle.RESOLVED | Bundle.STARTING | Bundle.STOPPING | Bundle.ACTIVE, null) {
        @Override
        public @Nullable Object addingBundle(@NonNullByDefault({}) Bundle bundle,
                @NonNullByDefault({}) BundleEvent event) {
            return withLock(lockOpenState.readLock(),
                    () -> openState == OpenState.OPENED && isBundleRelevant(bundle) ? bundle : null);
        }
    };
    relevantBundlesTracker.open();

    super.open();
}
 
Example #9
Source File: XmlDocumentBundleTracker.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
private Set<Bundle> getRelevantBundles() {
    BundleTracker<?> bundleTracker = relevantBundlesTracker;
    if (bundleTracker == null || bundleTracker.getBundles() == null) {
        return Collections.emptySet();
    }
    return (Set<Bundle>) Arrays.stream(bundleTracker.getBundles()).collect(Collectors.toSet());
}
 
Example #10
Source File: TagDirTracker.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public TagDirTracker ( final BundleContext context )
{
    this.bundleTracker = new BundleTracker<> ( context, Bundle.RESOLVED | Bundle.ACTIVE, this.customizer );
    this.bundleTracker.open ();
}
 
Example #11
Source File: ResourceTracker.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public ResourceTracker ( final BundleContext context )
{
    this.tracker = new BundleTracker<> ( context, Bundle.ACTIVE | Bundle.INSTALLED, this.customizer );
    this.tracker.open ();
}
 
Example #12
Source File: AutomationResourceBundlesTracker.java    From smarthome with Eclipse Public License 2.0 4 votes vote down vote up
@Activate
protected void activate(BundleContext bc) {
    bTracker = new BundleTracker<Bundle>(bc, ~Bundle.UNINSTALLED, this);
    bTracker.open();
}
 
Example #13
Source File: AutomationResourceBundlesTracker.java    From openhab-core with Eclipse Public License 2.0 4 votes vote down vote up
@Activate
protected void activate(BundleContext bc) {
    bTracker = new BundleTracker<>(bc, ~Bundle.UNINSTALLED, this);
    bTracker.open();
}
 
Example #14
Source File: Extender.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
public Extender(BundleContext context) {
    Extender.context = context;
    this.engineServiceTracker = new ServiceTracker(context, ProcessEngine.class.getName(), this);
    this.bundleTracker = new BundleTracker(context, Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE, this);
}
 
Example #15
Source File: BrowserWatchController.java    From wisdom with Apache License 2.0 4 votes vote down vote up
@Validate
public void listenServices() {
	tracker = new BundleTracker<BundleInfos>(context, Bundle.ACTIVE, this);
	tracker.open();
	context.addServiceListener(this);
}
 
Example #16
Source File: Extender.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public Extender(BundleContext context) {
  Extender.context = context;
  this.engineServiceTracker = new ServiceTracker(context, ProcessEngine.class.getName(), this);
  this.bundleTracker = new BundleTracker(context, Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE, this);
}
 
Example #17
Source File: TemplateTracker.java    From wisdom with Apache License 2.0 4 votes vote down vote up
@Validate
public void start() {
    LOGGER.debug("Starting Thymeleaf template tracker");
    tracker = new BundleTracker<>(context, Bundle.ACTIVE, this);
    tracker.open();
}
 
Example #18
Source File: InternationalizationServiceSingleton.java    From wisdom with Apache License 2.0 4 votes vote down vote up
@Validate
public void start() {
    tracker = new BundleTracker<>(context, Bundle.ACTIVE, this);
    tracker.open();
}