void activate()

in src/main/java/org/apache/sling/distribution/agent/impl/AbstractDistributionAgentFactory.java [73:145]


    void activate(BundleContext context, Map<String, Object> config) {
        log.info("activating with config {}", OsgiUtils.osgiPropertyMapToString(config));

        // inject configuration
        Dictionary<String, Object> props = new Hashtable<String, Object>();

        boolean enabled = PropertiesUtil.toBoolean(config.get(ENABLED), true);
        String triggersTarget = SettingsUtils.removeEmptyEntry(PropertiesUtil.toString(config.get(TRIGGERS_TARGET), null));
        triggersEnabled = triggersTarget != null && triggersTarget.trim().length() > 0;
        agentName = PropertiesUtil.toString(config.get(NAME), null);


        if (enabled && agentName != null) {

            for (Map.Entry<String, Object> entry : config.entrySet()) {
                // skip service and component related properties
                if (entry.getKey().startsWith("service.") || entry.getKey().startsWith("component.")) {
                    continue;
                }

                props.put(entry.getKey(), entry.getValue());

            }

            if (componentReg == null) {

                DefaultDistributionLog distributionLog = null;
                try {

                    String logLevel = PropertiesUtil.toString(config.get(LOG_LEVEL), DefaultDistributionLog.LogLevel.INFO.name());
                    DefaultDistributionLog.LogLevel level = DefaultDistributionLog.LogLevel.valueOf(logLevel.trim().toUpperCase());
                    if (level == null) {
                        level = DefaultDistributionLog.LogLevel.INFO;
                    }


                    distributionLog = new DefaultDistributionLog(DistributionComponentKind.AGENT, agentName, SimpleDistributionAgent.class, level);

                    agent = createAgent(agentName, context, config, distributionLog);
                } catch (Throwable t) {
                    if (distributionLog != null) {
                        distributionLog.error("Cannot create agent", t);
                    }
                    log.error("Cannot create agent {}", OsgiUtils.osgiPropertyMapToString(config), t);
                }


                if (agent != null) {

                    // register agent service
                    componentReg = context.registerService(DistributionAgent.class, agent, props);
                    agent.enable();


                    if (triggersEnabled) {
                        for (DistributionTrigger trigger : triggers) {
                            agent.enableTrigger(trigger);
                        }
                    }

                    Dictionary<String, String> mbeanProps = new Hashtable<String, String>();
                    mbeanProps.put("jmx.objectname", "org.apache.sling.distribution:type=agent,id=" + ObjectName.quote(agentName));

                    DistributionAgentMBeanType mbean = createMBeanAgent(agent, config);
                    mbeanServiceRegistration = context.registerService(distributionAgentMBeanType, mbean, mbeanProps);

                }

                log.info("activated agent {}", agentName);

            }
        }
    }