下面列出了junit.framework.TestListener#org.osgi.util.tracker.BundleTracker 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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 ();
}
@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();
}
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();
}
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());
}
@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();
}
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 ();
}
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 ();
}
@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();
}
/**
* 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);
}
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);
}
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);
}
@Activate
protected void activate(BundleContext bc) {
bTracker = new BundleTracker<>(bc, ~Bundle.UNINSTALLED, this);
bTracker.open();
}
public TagDirTracker ( final BundleContext context )
{
this.bundleTracker = new BundleTracker<> ( context, Bundle.RESOLVED | Bundle.ACTIVE, this.customizer );
this.bundleTracker.open ();
}
public ResourceTracker ( final BundleContext context )
{
this.tracker = new BundleTracker<> ( context, Bundle.ACTIVE | Bundle.INSTALLED, this.customizer );
this.tracker.open ();
}
@Activate
protected void activate(BundleContext bc) {
bTracker = new BundleTracker<Bundle>(bc, ~Bundle.UNINSTALLED, this);
bTracker.open();
}
@Validate
public void listenServices() {
tracker = new BundleTracker<BundleInfos>(context, Bundle.ACTIVE, this);
tracker.open();
context.addServiceListener(this);
}
@Validate
public void start() {
LOGGER.debug("Starting Thymeleaf template tracker");
tracker = new BundleTracker<>(context, Bundle.ACTIVE, this);
tracker.open();
}
@Validate
public void start() {
tracker = new BundleTracker<>(context, Bundle.ACTIVE, this);
tracker.open();
}