/** * Function that is called when configuration of the dependencies is required. * * @param c dependency manager Component object, used for configuring the dependencies exported * and imported * @param imp Implementation class that is being configured, needed as long as the same routine * can configure multiple implementations */ @Override public void configureGlobalInstance(Component c, Object imp) { if (imp.equals(GlobalResourceManager.class)) { // Export the services. String[] classes = { IVTNGlobal.class.getName(), IVTNResourceManager.class.getName(), ICoordinatorChangeAware.class.getName(), }; c.setInterface(classes, null); // Create service dependencies. c.add( createServiceDependency() .setService(IClusterGlobalServices.class) .setCallbacks("setClusterGlobalService", "unsetClusterGlobalService") .setRequired(true)); } }
/** Function called by the dependency manager when all the required dependencies are satisfied */ void init(Component c) { Dictionary<?, ?> props = c.getServiceProperties(); if (props != null) { this.containerName = (String) props.get("containerName"); logger.debug("Running containerName: {}", this.containerName); } else { // In the Global instance case the containerName is empty this.containerName = ""; } startUp(); }
@Override public void build(MetaData srvMeta, List<MetaData> depsMeta, Bundle b, DependencyManager dm) throws Exception { int stateMask = srvMeta.getInt(Params.stateMask, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.ACTIVE); String filter = srvMeta.getString(Params.filter, null); Class<?> adapterImplClass = b.loadClass(srvMeta.getString(Params.impl)); String[] provides = srvMeta.getStrings(Params.provides, null); Dictionary<String, Object> properties = srvMeta.getDictionary(Params.properties, null); boolean propagate = "true".equals(srvMeta.getString(Params.propagate, "false")); Component c = dm.createBundleAdapterService(stateMask, filter, propagate); c.setInterface(provides, properties); String factoryMethod = srvMeta.getString(Params.factoryMethod, null); if (factoryMethod == null) { c.setImplementation(adapterImplClass); } else { c.setFactory(adapterImplClass, factoryMethod); } setCommonServiceParams(c, srvMeta); c.setComposition(srvMeta.getString(Params.composition, null)); ServiceLifecycleHandler lfcleHandler = new ServiceLifecycleHandler(c, b, dm, srvMeta, depsMeta); // The dependencies will be plugged by our lifecycle handler. c.setCallbacks(lfcleHandler, "init", "start", "stop", "destroy"); // Adds dependencies (except named dependencies, which are managed by the lifecycle handler). addUnamedDependencies(b, dm, c, srvMeta, depsMeta); dm.add(c); }
/** * Called when this class is registered as OSGi service. * * @param aComponent the bundle context to use, cannot be <code>null</code>. */ protected void init(final Component aComponent) { final String pmFilter = String.format("(%s=%s)", Constants.SERVICE_PID, DeviceProfileManager.SERVICE_PID); aComponent // .add( this.dependencyManager .createServiceDependency() // .setService(ManagedServiceFactory.class, pmFilter) // .setAutoConfig("deviceProfileManagerServiceFactory") // .setInstanceBound(true) // .setRequired(true)) // .add( this.dependencyManager .createServiceDependency() // .setService(ConnectorService.class) // .setAutoConfig("connectorService") // .setInstanceBound(true) // .setRequired(true) // ); }
/** * Function that is called when configuration of the dependencies is required. * * @param c dependency manager Component object, used for configuring the dependencies exported * and imported * @param imp Implementation class that is being configured, needed as long as the same routine * can configure multiple implementations * @param containerName The containerName being configured, this allow also optional per-container * different behavior if needed, usually should not be the case though. */ @Override public void configureInstance(Component c, Object imp, String containerName) { if (imp.equals(VTNManagerImpl.class)) { Dictionary<String, Object> props = new Hashtable<String, Object>(); Set<String> propSet = new HashSet<String>(); propSet.add(VTNManagerImpl.CACHE_EVENT); propSet.add(VTNManagerImpl.CACHE_MAC); props.put("cachenames", propSet); props.put("salListenerName", "vtnmanager"); // Export the services. ArrayList<String> list = new ArrayList<String>(); list.add(IVTNManager.class.getName()); list.add(ICacheUpdateAware.class.getName()); list.add(IConfigurationContainerAware.class.getName()); list.add(IHostFinder.class.getName()); if (containerName.equals(GlobalConstants.DEFAULT.toString())) { // Register dependency to MD-SAL VTN Manager provider. c.add( createServiceDependency() .setService(VTNManagerProvider.class) .setCallbacks("setVTNProvider", "unsetVTNProvider") .setRequired(true)); } // Export IVTNFlowDebugger only if "vtn.debug" system property // is defined as "true". String debug = System.getProperty("vtn.debug"); if (debug != null && Boolean.parseBoolean(debug)) { list.add(IVTNFlowDebugger.class.getName()); } c.setInterface(list.toArray(new String[list.size()]), props); // Create service dependencies. c.add( createServiceDependency() .setService(IVTNResourceManager.class) .setCallbacks("setResourceManager", "unsetResourceManager") .setRequired(true)); c.add( createContainerServiceDependency(containerName) .setService(IVTNManagerAware.class) .setCallbacks("addVTNManagerAware", "removeVTNManagerAware") .setRequired(false)); c.add( createContainerServiceDependency(containerName) .setService(IVTNModeListener.class) .setCallbacks("addVTNModeListener", "removeVTNModeListener") .setRequired(false)); c.add( createContainerServiceDependency(containerName) .setService(IClusterContainerServices.class) .setCallbacks("setClusterContainerService", "unsetClusterContainerService") .setRequired(true)); // VTN manager can run without any host listener. c.add( createContainerServiceDependency(containerName) .setService(IfHostListener.class) .setCallbacks("addHostListener", "removeHostListener") .setRequired(false)); } }