本文整理汇总了Java中org.osgi.framework.BundleContext.getServiceReference方法的典型用法代码示例。如果您正苦于以下问题:Java BundleContext.getServiceReference方法的具体用法?Java BundleContext.getServiceReference怎么用?Java BundleContext.getServiceReference使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.osgi.framework.BundleContext
的用法示例。
在下文中一共展示了BundleContext.getServiceReference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
@Override
public void start(BundleContext context) throws Exception {
log.info("######################################################");
log.info("start");
log.info("######################################################");
Hashtable<String, String> props = new Hashtable<>();
props.put("osgi.http.whiteboard.servlet.pattern", "/*");
props.put("init.message", "Crazy filter!");
props.put("service.ranking", "1");
serviceRegistration = context.registerService(Filter.class.getName(), new CrazyFilter(), props);
final ServiceReference<?> httpRef = context.getServiceReference("org.osgi.service.http.HttpService");
httpService = (HttpService) context.getService(httpRef);
httpService.registerServlet("/foo", new FooServlet(), new Hashtable(), httpService.createDefaultHttpContext());
}
示例2: getOSGiBundle
import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
private Bundle getOSGiBundle(String symbolicName, BundleContext bcontext) {
ServiceReference<PackageAdmin> ref = bcontext.getServiceReference(PackageAdmin.class);
PackageAdmin packageAdmin = bcontext.getService(ref);
if (packageAdmin == null)
return null;
Bundle[] bundles = packageAdmin.getBundles(symbolicName, null);
if (bundles == null)
return null;
//Return the first bundle that is not installed or uninstalled
for (int i = 0; i < bundles.length; i++) {
if ((bundles[i].getState() & (Bundle.INSTALLED | Bundle.UNINSTALLED)) == 0) {
return bundles[i];
}
}
return null;
}
示例3: PermissionManager
import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
/**
* Constructs a new <code>PermissionManager</code> instance.
*
* @param bc
*/
private PermissionManager(BundleContext bc) {
ServiceReference ref = bc.getServiceReference(PermissionAdmin.class.getName());
if (ref != null) {
logger.trace("Found permission admin " + ref);
pa = (PermissionAdmin) bc.getService(ref);
bc.addBundleListener(this);
logger.trace("Default permissions are " + ObjectUtils.nullSafeToString(pa.getDefaultPermissions()));
logger.warn("Security turned ON");
}
else {
logger.warn("Security turned OFF");
pa = null;
}
}
示例4: initializeServiceRunnerInvocationMethods
import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
/**
* Determines through reflection the methods used for invoking the TestRunnerService.
*
* @throws Exception
*/
private void initializeServiceRunnerInvocationMethods() throws Exception {
// get JUnit test service reference
// this is a loose reference - update it if the JUnitTestActivator class is changed.
BundleContext ctx = getRuntimeBundleContext();
ServiceReference reference = ctx.getServiceReference(ACTIVATOR_REFERENCE);
Assert.notNull(reference, "no OSGi service reference found at " + ACTIVATOR_REFERENCE);
service = ctx.getService(reference);
Assert.notNull(service, "no service found for reference: " + reference);
serviceTrigger = service.getClass().getDeclaredMethod("executeTest", new Class[0]);
ReflectionUtils.makeAccessible(serviceTrigger);
Assert.notNull(serviceTrigger, "no executeTest() method found on: " + service.getClass());
}
示例5: dispose
import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
@Override
public void dispose() {
super.dispose();
BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
ServiceReference<IDebugService> serviceReference = (ServiceReference<IDebugService>) bundleContext.getServiceReference(IDebugService.class.getName());
if(serviceReference != null){
IDebugService debugService = (IDebugService)bundleContext.getService(serviceReference);
debugService.deleteDebugFiles();
}
Properties properties = ConfigFileReader.INSTANCE.getCommonConfigurations();
try {
killPortProcess(properties);
} catch (IOException e) {
logger.debug("Socket is not closed.");
}
}
示例6: getService
import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
/**
* Returns the reference to the implementation of the specified service.
*
* @param serviceClass service class
* @param <T> type of service
* @return service implementation
*/
public static <T> T getService(Class<T> serviceClass) {
BundleContext bc = FrameworkUtil.getBundle(serviceClass).getBundleContext();
if (bc != null) {
ServiceReference<T> reference = bc.getServiceReference(serviceClass);
if (reference != null) {
T impl = bc.getService(reference);
if (impl != null) {
return impl;
}
}
}
throw new ServiceNotFoundException("Service " + serviceClass.getName() + " not found");
}
示例7: testActivation
import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
public void testActivation() throws Exception {
ModuleSystem ms = Main.getModuleSystem();
mgr = ms.getManager();
mgr.mutexPrivileged().enterWriteAccess();
try {
m1 = mgr.createBundle(simpleModule, null, false, false, false, 10);
mgr.enable(m1);
} finally {
mgr.mutexPrivileged().exitWriteAccess();
}
Class<?> main = m1.getClassLoader().loadClass("org.activate.Main");
Object s = main.getField("start").get(null);
assertNull("Not started yet", s);
Framework f = NetigsoServicesTest.findFramework();
final BundleContext fc = f.getBundleContext();
fc.addFrameworkListener(this);
ServiceReference sr = fc.getServiceReference(StartLevel.class.getName());
assertNotNull("Start level service found", sr);
StartLevel level = (StartLevel) fc.getService(sr);
assertNotNull("Start level found", level);
level.setStartLevel(10);
waitLevelChanged();
s = main.getField("start").get(null);
assertNotNull("Bundle started, its context provided", s);
mgr.mutexPrivileged().enterWriteAccess();
try {
mgr.disable(m1);
Object e = main.getField("stop").get(null);
assertNotNull("Bundle stopped, its context provided", e);
} finally {
mgr.mutexPrivileged().exitWriteAccess();
}
}
示例8: testSAXParserAvailable
import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
public void testSAXParserAvailable() throws Exception {
Framework f = IntegrationTest.findFramework();
BundleContext bc = f.getBundleContext();
ServiceReference sr = bc.getServiceReference(SAXParserFactory.class.getName());
assertNotNull("SAX Service found", sr);
Object srvc = bc.getService(sr);
assertTrue("Instance of the right type: " + srvc, srvc instanceof SAXParserFactory);
}
示例9: acquireTransactionManager
import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
@Override
protected TransactionManager acquireTransactionManager() throws Exception {
BundleContext ctx = FrameworkUtil.getBundle(OSGiTSWrapper.class).getBundleContext();
if (ctx != null) {
ServiceReference ref = ctx.getServiceReference(TransactionManager.class.getName());
if (ref != null) {
return (TransactionManager) ctx.getService(ref);
}
}
return super.acquireTransactionManager();
}
示例10: log
import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
protected void log ( final int level, final String message )
{
final BundleContext context = this.context;
if ( context == null )
{
return;
}
final ServiceReference<LogService> ref = context.getServiceReference ( LogService.class );
if ( ref == null )
{
return;
}
final LogService service = context.getService ( ref );
if ( service == null )
{
return;
}
try
{
service.log ( level, message );
}
finally
{
context.ungetService ( ref );
}
}
示例11: start
import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
public void start(ComponentContext context) {
BundleContext bcontext = context.getBundleContext();
ServiceReference<IExpressionService> ref = bcontext.getServiceReference(IExpressionService.class);
if (ref == null) {
System.out.println("Starting "+ServerExpressionService.class.getSimpleName());
bcontext.registerService(IExpressionService.class, new ServerExpressionService(), null);
}
}
示例12: testDynamicEndProxy
import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
public void testDynamicEndProxy() throws Exception {
long time = 123456;
Date date = new Date(time);
ServiceRegistration reg = publishService(date);
BundleContext ctx = bundleContext;
try {
ServiceReference ref = ctx.getServiceReference(Date.class.getName());
assertNotNull(ref);
Date proxy = (Date) createProxy(Date.class, createCardinalityAdvice(Date.class));
assertEquals(time, proxy.getTime());
// take down service
reg.unregister();
// reference is invalid
assertNull(ref.getBundle());
try {
proxy.getTime();
fail("should have thrown exception");
}
catch (ServiceUnavailableException sue) {
// service failed
}
// rebind the service
reg = publishService(date);
// retest the service
assertEquals(time, proxy.getTime());
}
finally {
if (reg != null)
try {
reg.unregister();
}
catch (Exception ex) {
// ignore
}
}
}
示例13: testServices
import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
@Test
public void testServices() {
BundleContext bundleContext = teleporter.getService(BundleContext.class);
StringBuilder stringBuilder = new StringBuilder();
for (String service : services) {
ServiceReference sr = bundleContext.getServiceReference(service);
if (sr == null) {
stringBuilder.append(" ").append(service).append("\n");
}
}
if (stringBuilder.length() > 0) {
stringBuilder.insert(0, "Could not obtain a ServiceReference for the following services:\n");
fail(stringBuilder.toString());
}
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:16,代码来源:ServicesPresentTest.java
示例14: restartConfigModules
import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
private void restartConfigModules(final BundleContext bundleContext, final List<Entry<String,
ModuleIdentifier>> configModules) {
if (configModules.isEmpty()) {
return;
}
ServiceReference<ConfigSubsystemFacadeFactory> configFacadeFactoryRef = bundleContext
.getServiceReference(ConfigSubsystemFacadeFactory.class);
if (configFacadeFactoryRef == null) {
LOG.debug("ConfigSubsystemFacadeFactory service reference not found");
return;
}
ConfigSubsystemFacadeFactory configFacadeFactory = bundleContext.getService(configFacadeFactoryRef);
if (configFacadeFactory == null) {
LOG.debug("ConfigSubsystemFacadeFactory service not found");
return;
}
try (ConfigSubsystemFacade configFacade = configFacadeFactory.createFacade(
"BlueprintContainerRestartService")) {
restartConfigModules(configModules, configFacade);
} catch (ParserConfigurationException | DocumentedException | ValidationException
| ConflictingVersionException e) {
LOG.error("Error restarting config modules", e);
} finally {
bundleContext.ungetService(configFacadeFactoryRef);
}
}
示例15: getConfiguration
import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
/**
* Returns a map containing the Configuration Admin entry with given pid. Waits until a non-null (initialized)
* object is returned if initTimeout is bigger then 0.
*
* @param bundleContext
* @param pid
* @param initTimeout
* @return
* @throws IOException
*/
public static Map getConfiguration(BundleContext bundleContext, final String pid, long initTimeout)
throws IOException {
ServiceReference ref = bundleContext.getServiceReference(ConfigurationAdmin.class.getName());
if (ref != null) {
ConfigurationAdmin cm = (ConfigurationAdmin) bundleContext.getService(ref);
if (cm != null) {
Dictionary dict = cm.getConfiguration(pid).getProperties();
// if there are properties or no timeout, return as is
if (dict != null || initTimeout == 0) {
return new MapBasedDictionary(dict);
}
// no valid props, register a listener and start waiting
final Object monitor = new Object();
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(Constants.SERVICE_PID, pid);
ServiceRegistration reg =
bundleContext.registerService(ConfigurationListener.class.getName(),
new ConfigurationListener() {
public void configurationEvent(ConfigurationEvent event) {
if (ConfigurationEvent.CM_UPDATED == event.getType()
&& pid.equals(event.getPid())) {
synchronized (monitor) {
monitor.notify();
}
}
}
}, props);
try {
// try to get the configuration one more time (in case the update was fired before the service was
// registered)
dict = cm.getConfiguration(pid).getProperties();
if (dict != null) {
return new MapBasedDictionary(dict);
}
// start waiting
synchronized (monitor) {
try {
monitor.wait(initTimeout);
} catch (InterruptedException ie) {
// consider the timeout has passed
}
}
// return whatever is available (either we timed out or an update occured)
return new MapBasedDictionary(cm.getConfiguration(pid).getProperties());
} finally {
OsgiServiceUtils.unregisterService(reg);
}
}
}
return Collections.EMPTY_MAP;
}