当前位置: 首页>>代码示例>>Java>>正文


Java BundleContext.getService方法代码示例

本文整理汇总了Java中org.osgi.framework.BundleContext.getService方法的典型用法代码示例。如果您正苦于以下问题:Java BundleContext.getService方法的具体用法?Java BundleContext.getService怎么用?Java BundleContext.getService使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.osgi.framework.BundleContext的用法示例。


在下文中一共展示了BundleContext.getService方法的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());
}
 
开发者ID:L7R7,项目名称:magic-bundle,代码行数:18,代码来源:Activator.java

示例2: start

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
@Override
public void start(BundleContext context) throws Exception {
    randomNumberServiceTracker = new ServiceTracker<>(context, RandomNumberGenerator.class.getName(), null);
    randomNumberServiceTracker.open();
    serviceReference = randomNumberServiceTracker.getServiceReference();
    if (serviceReference != null) {
        final RandomNumberGenerator service = context.getService(serviceReference);
        if (service != null) {
            log.info("############ tracked random: {} with service {}", service.generateNumber(), service);
        } else {
            log.info("############# no tracked random because service is null");
        }
    } else {
        log.info("############# no tracked random because serviceReference is null");
    }

}
 
开发者ID:L7R7,项目名称:magic-bundle,代码行数:18,代码来源:Activator.java

示例3: addingService

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
@Override
@SuppressWarnings("IllegalCatch")
public FeaturesService addingService(final ServiceReference<FeaturesService> reference) {
    BundleContext bc = reference.getBundle().getBundleContext();
    final FeaturesService featureService = bc.getService(reference);
    final Optional<XmlFileStorageAdapter> currentPersister = XmlFileStorageAdapter.getInstance();

    if (XmlFileStorageAdapter.getInstance().isPresent()) {
        final Set<String> installedFeatureIds = Sets.newHashSet();
        try {
            for (final Feature installedFeature : featureService.listInstalledFeatures()) {
                installedFeatureIds.add(installedFeature.getId());
            }
        } catch (final Exception e) {
            LOG.error("Error listing installed features", e);
        }

        currentPersister.get().setFeaturesService(() -> installedFeatureIds);
    }
    ConfigFeaturesListener configFeaturesListener = new ConfigFeaturesListener(configPusher, featureService);
    registration = bc.registerService(FeaturesListener.class.getCanonicalName(), configFeaturesListener, null);
    return featureService;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:24,代码来源:FeatureServiceCustomizer.java

示例4: emit

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
@Override
protected void emit(
	ServiceReference<NestedCollectionRouter> serviceReference,
	Emitter<String> emitter) {

	Bundle bundle = FrameworkUtil.getBundle(
		NestedCollectionRouterManagerImpl.class);

	BundleContext bundleContext = bundle.getBundleContext();

	CustomServiceReferenceMapper<NestedCollectionRouter>
		customServiceReferenceMapper = new CustomServiceReferenceMapper<>(
			bundleContext, NestedCollectionRouter.class);

	NestedCollectionRouter nestedCollectionRouter =
		bundleContext.getService(serviceReference);

	Class<?> genericClass = getGenericClassFromPropertyOrElse(
		serviceReference, PARENT_MODEL_CLASS,
		() -> getTypeParamOrFail(
			nestedCollectionRouter, NestedCollectionRouter.class, 1));

	customServiceReferenceMapper.map(
		serviceReference,
		key -> emitter.emit(key + "-" + genericClass.getName()));
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:27,代码来源:NestedCollectionRouterManagerImpl.java

示例5: activate

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
@Activate
public void activate(BundleContext bundleContext) {
	Application application = bundleContext.getService(_serviceReference);

	Dictionary<String, Object> properties = new Hashtable<>();

	String[] propertyKeys = _serviceReference.getPropertyKeys();

	for (String key : propertyKeys) {
		Object value = _serviceReference.getProperty(key);

		properties.put(key, value);
	}

	properties.put("osgi.jaxrs.application.base", "/");
	properties.put("osgi.jaxrs.name", ".default");

	_serviceRegistration = bundleContext.registerService(
		Application.class, application, properties);
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:21,代码来源:ApioApplicationRegistrar.java

示例6: 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;
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:21,代码来源:BaseIntegrationTest.java

示例7: 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());
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:22,代码来源:AbstractOsgiTests.java

示例8: 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.");
}
  }
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:17,代码来源:ApplicationWorkbenchWindowAdvisor.java

示例9: 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");
}
 
开发者ID:shlee89,项目名称:athena,代码行数:21,代码来源:DefaultServiceDirectory.java

示例10: start

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
@Override
public void start(BundleContext context) throws Exception {
    randomNumberServiceTracker = new ServiceTracker<>(context, RandomNumberGenerator.class.getName(), new ServiceTrackerCustomizer<RandomNumberGenerator, RandomNumberGenerator>() {
        @Override
        public RandomNumberGenerator addingService(ServiceReference<RandomNumberGenerator> reference) {
            log.info(">>>>>>>>>>>> customizer#addingService");
            setServiceReference(reference);
            RandomNumberGenerator service = context.getService(reference);
            consumeService(service);
            return service;
        }

        @Override
        public void modifiedService(ServiceReference<RandomNumberGenerator> reference, RandomNumberGenerator service) {
            log.info(">>>>>>>>>>>> customizer#modifiedService");
            unsetServiceReference(context);
        }

        @Override
        public void removedService(ServiceReference<RandomNumberGenerator> reference, RandomNumberGenerator service) {
            log.info(">>>>>>>>>>>> customizer#removedService");
            unsetServiceReference(context);
        }
    });
    randomNumberServiceTracker.open();

    final ServiceReference<RandomNumberGenerator> reference = randomNumberServiceTracker.getServiceReference();
    if (reference != null) {
        consumeService(context.getService(reference));
    }

}
 
开发者ID:L7R7,项目名称:magic-bundle,代码行数:33,代码来源:Activator.java

示例11: getProperties

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
/**
 * Creates a {@code ServiceTracker} that will register its managed services
 * as the classes provided in the {@code classes} parameter.
 *
 * @param  bundleContext the bundle context
 * @param  clazz the managed class
 * @param  classes the list of classes with which the service will be
 *         registered
 * @param  biConsumer function that can be used to alter the properties
 *         dictionary
 * @return the service tracker
 * @review
 */
public static <T> ServiceTracker<T, ServiceRegistration<?>>
	createServiceTracker(
		BundleContext bundleContext, Class<T> clazz, String[] classes,
		BiConsumer<Dictionary<String, Object>, T> biConsumer) {

	return new ServiceTracker<>(
		bundleContext, clazz,
		(ServiceRegistrationServiceTrackerCustomizer<T>)
			serviceReference -> {
				Dictionary<String, Object> properties = getProperties(
					serviceReference);

				T t = null;

				try {
					t = bundleContext.getService(serviceReference);
				}
				catch (Exception e) {
					return null;
				}

				biConsumer.accept(properties, t);

				return bundleContext.registerService(
					classes, t, properties);
			});
}
 
开发者ID:liferay,项目名称:com-liferay-apio-architect,代码行数:41,代码来源:ManagerUtil.java

示例12: 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);
        
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:NetigsoHasSAXParserTest.java

示例13: addingService

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object addingService(ServiceReference reference) {
    String unitName = (String)reference.getProperty(JPA_UNIT_NAME);
    if (unitName == null) {
        return null;
    }
    BundleContext puContext = reference.getBundle().getBundleContext();
    TrackedEmf tracked = new TrackedEmf();
    tracked.emf = (EntityManagerFactory)puContext.getService(reference);
    tracked.emSupplier = new EMSupplierImpl(unitName, tracked.emf, coordinator);
    tracked.emSupplierReg = puContext.registerService(EmSupplier.class, tracked.emSupplier,
                                                     getEmSupplierProps(unitName));

    EntityManager emProxy = createProxy(tracked.emSupplier);
    tracked.emProxyReg = puContext.registerService(EntityManager.class, emProxy,
                                                     getEmSupplierProps(unitName));
    
    if (getTransactionType(tracked.emf) == PersistenceUnitTransactionType.RESOURCE_LOCAL) {
        JpaTemplate txManager = new ResourceLocalJpaTemplate(tracked.emSupplier, coordinator);
        tracked.rlTxManagerReg = puContext.registerService(JpaTemplate.class, txManager,
                                                      rlTxManProps(unitName));
    } else {
        tracked.tmTracker = new TMTracker(puContext, tracked.emSupplier, unitName, coordinator);
        tracked.tmTracker.open();
    }
    return tracked;
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:29,代码来源:EMFTracker.java

示例14: 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();
}
 
开发者ID:apache,项目名称:aries-jpa,代码行数:15,代码来源:OSGiTSWrapper.java

示例15: 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);
    }

}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:31,代码来源:BlueprintContainerRestartServiceImpl.java


注:本文中的org.osgi.framework.BundleContext.getService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。