def testConstantGetReference(self): """ Tests the ipopo.constants.get_service_reference() method """ # Try without the bundle self.assertIsNone(constants.get_ipopo_svc_ref(self.context), "iPOPO service found while not installed.") # Install the iPOPO bundle ipopo_svc = install_ipopo(self.framework) # Test the method result ref, svc = constants.get_ipopo_svc_ref(self.context) self.assertIsNotNone(ref, "Invalid service reference") self.assertIs(svc, ipopo_svc, "Found a different service.") # Stop the iPOPO bundle ref.get_bundle().stop() # Ensure the service is not accessible anymore self.assertIsNone(constants.get_ipopo_svc_ref(self.context), "iPOPO service found while stopped.") # Uninstall the bundle ref.get_bundle().uninstall() # Ensure the service is not accessible anymore self.assertIsNone(constants.get_ipopo_svc_ref(self.context), "iPOPO service found while stopped.")
def _get_loader(context, loader_bundle): """ Retrieves/instantiates the loader service/component from the given bundle :param context: A bundle context :param loader_bundle: The loader implementation bundle object :return: The loader component/service :raise TypeError: No loader found :raise ValueError: A loader component already exists :raise Exception: An error occurred initializing the component """ # Get the loader component factory, if any loader_factory = getattr(loader_bundle.get_module(), cohorte.BUNDLE_ISOLATE_LOADER_FACTORY, None) if loader_factory: # Instantiate the component ipopo = get_ipopo_svc_ref(context)[1] _logger.debug("Instantiating component of type '%s'", loader_factory) return ipopo.instantiate(loader_factory, 'cohorte-isolate-loader') else: # Find the loader service svc_ref = context.get_service_reference(cohorte.SERVICE_ISOLATE_LOADER) if svc_ref: # Service found _logger.debug("Found an isolate loader service") return context.get_service(svc_ref) # No loader found raise TypeError('No isolate loader found')
def install_ipopo(framework): """ Installs and starts the iPOPO bundle. Returns the iPOPO service @param framework: A Pelix framework instance @return: The iPOPO service @raise Exception: The iPOPO service cannot be found """ # Install & start the bundle install_bundle(framework, "pelix.ipopo.core") # Get the service service = get_ipopo_svc_ref(framework.get_bundle_context()) if service is None: raise Exception("iPOPO Service not found") return service[1]
def __setup_components(self): """ Instantiates iPOPO components """ # Get the iPOPO service context = self._framework.get_bundle_context() ipopo = get_ipopo_svc_ref(context)[1] # Remote Shell ipopo.instantiate("ipopo-remote-shell-factory", "remote-shell", { "pelix.shell.address": "0.0.0.0", "pelix.shell.port": 9001 }) # EventAdmin (with 2 threads only) ipopo.instantiate("pelix-services-eventadmin-factory", "pelix-services-eventadmin", {"pool.threads": 2}) # HTTP Service ipopo.instantiate("pelix.http.service.basic.factory", "pelix.http.service.basic", {"pelix.http.port": 9000}) # Remote services ipopo.instantiate("pelix-remote-dispatcher-factory", "pelix-remote-dispatcher", {}) ipopo.instantiate("pelix-remote-dispatcher-servlet-factory", "pelix-remote-dispatcher-servlet", {}) ipopo.instantiate("pelix-remote-imports-registry-factory", "pelix-remote-imports-registry", {}) ipopo.instantiate("pelix-jsonrpc-exporter-factory", "pelix-jsonrpc-exporter", {}) ipopo.instantiate("pelix-jsonrpc-importer-factory", "pelix-jsonrpc-importer", {}) ipopo.instantiate("pelix-remote-discovery-multicast-factory", "pelix-remote-discovery-multicast", {}) # Compass ipopo.instantiate("compass-event-sender-factory", "compass-event-sender", {"clock.tick": .1})