當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。