use of org.osgi.util.tracker.ServiceTracker in project jetty.project by eclipse.
the class JettyBootstrapActivator method start.
/* ------------------------------------------------------------ */
/**
* Setup a new jetty Server, registers it as a service. Setup the Service
* tracker for the jetty ContextHandlers that are in charge of deploying the
* webapps. Setup the BundleListener that supports the extender pattern for
* the jetty ContextHandler.
*
* @param context the bundle context
*/
public void start(final BundleContext context) throws Exception {
INSTANCE = this;
// track other bundles and fragments attached to this bundle that we
// should activate.
_packageAdminServiceTracker = new PackageAdminServiceTracker(context);
// track jetty Server instances that we should support as deployment targets
_jettyServerServiceTracker = new ServiceTracker(context, context.createFilter("(objectclass=" + Server.class.getName() + ")"), new JettyServerServiceTracker());
_jettyServerServiceTracker.open();
// Create a default jetty instance right now.
Server defaultServer = DefaultJettyAtJettyHomeHelper.startJettyAtJettyHome(context);
}
use of org.osgi.util.tracker.ServiceTracker in project jersey by jersey.
the class Activator method start.
@Override
public synchronized void start(BundleContext bundleContext) throws Exception {
this.bc = bundleContext;
logger.info("STARTING HTTP SERVICE BUNDLE");
this.tracker = new ServiceTracker(this.bc, HttpService.class.getName(), null) {
@Override
public Object addingService(ServiceReference serviceRef) {
httpService = (HttpService) super.addingService(serviceRef);
registerServlets();
return httpService;
}
@Override
public void removedService(ServiceReference ref, Object service) {
if (httpService == service) {
unregisterServlets();
httpService = null;
}
super.removedService(ref, service);
}
};
this.tracker.open();
logger.info("HTTP SERVICE BUNDLE STARTED");
}
use of org.osgi.util.tracker.ServiceTracker in project aries by apache.
the class Activator method initServiceTracker.
private ServiceTracker initServiceTracker(BundleContext context, Class<?> type, ServiceTrackerCustomizer custom) {
ServiceTracker t = new ServiceTracker(context, type.getName(), custom);
t.open();
return t;
}
use of org.osgi.util.tracker.ServiceTracker in project aries by apache.
the class ConfigurationTests method testConfiguration.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testConfiguration() throws Exception {
Bundle tb3Bundle = installBundle("tb3.jar");
Configuration configurationA = null, configurationB = null;
try {
Filter filter = bundleContext.createFilter("(&(objectClass=" + CdiContainer.class.getName() + ")(service.bundleid=" + tb3Bundle.getBundleId() + "))");
ServiceTracker<CdiContainer, CdiContainer> containerTracker = new ServiceTracker<>(bundleContext, filter, null);
containerTracker.open();
containerTracker.waitForService(timeout);
ServiceReference<CdiContainer> serviceReference = containerTracker.getServiceReference();
assertNotNull(serviceReference);
assertEquals(CdiEvent.Type.WAITING_FOR_CONFIGURATIONS, serviceReference.getProperty(CdiConstants.CDI_CONTAINER_STATE));
configurationA = configurationAdmin.getConfiguration("configA", "?");
Dictionary<String, Object> properties = new Hashtable<>();
properties.put("ports", new int[] { 12, 4567 });
configurationA.update(properties);
configurationB = configurationAdmin.getConfiguration("configB", "?");
properties = new Hashtable<>();
properties.put("color", "green");
properties.put("ports", new int[] { 80 });
configurationB.update(properties);
containerTracker.close();
filter = bundleContext.createFilter("(&(objectClass=" + CdiContainer.class.getName() + ")(service.bundleid=" + tb3Bundle.getBundleId() + ")(" + CdiConstants.CDI_CONTAINER_STATE + "=CREATED))");
containerTracker = new ServiceTracker<>(bundleContext, filter, null);
containerTracker.open();
containerTracker.waitForService(timeout);
ServiceTracker<BeanService, BeanService> stA = new ServiceTracker<BeanService, BeanService>(bundleContext, bundleContext.createFilter("(&(objectClass=org.apache.aries.cdi.test.interfaces.BeanService)(bean=A))"), null);
stA.open(true);
BeanService<Callable<int[]>> beanService = stA.waitForService(timeout);
assertNotNull(beanService);
assertEquals("blue", beanService.doSomething());
assertArrayEquals(new int[] { 12, 4567 }, beanService.get().call());
ServiceTracker<BeanService, BeanService> stB = new ServiceTracker<BeanService, BeanService>(bundleContext, bundleContext.createFilter("(&(objectClass=org.apache.aries.cdi.test.interfaces.BeanService)(bean=B))"), null);
stB.open(true);
beanService = stB.waitForService(timeout);
assertNotNull(beanService);
assertEquals("green", beanService.doSomething());
assertArrayEquals(new int[] { 80 }, beanService.get().call());
} finally {
if (configurationA != null) {
try {
configurationA.delete();
} catch (Exception e) {
// ignore
}
}
if (configurationB != null) {
try {
configurationB.delete();
} catch (Exception e) {
// ignore
}
}
tb3Bundle.uninstall();
}
}
use of org.osgi.util.tracker.ServiceTracker in project aries by apache.
the class AbstractTestCase method getServiceTracker.
ServiceTracker<CdiContainer, CdiContainer> getServiceTracker(long bundleId) throws InvalidSyntaxException {
Filter filter = bundleContext.createFilter("(&(objectClass=" + CdiContainer.class.getName() + ")(service.bundleid=" + bundleId + ")(" + CdiConstants.CDI_CONTAINER_STATE + "=" + CdiEvent.Type.CREATED + "))");
ServiceTracker<CdiContainer, CdiContainer> serviceTracker = new ServiceTracker<>(bundleContext, filter, null);
serviceTracker.open();
return serviceTracker;
}
Aggregations