Search in sources :

Example 46 with Activate

use of org.osgi.service.component.annotations.Activate in project smarthome by eclipse.

the class SampleExtensionService method activate.

@Activate
protected void activate() {
    types.add(new ExtensionType("binding", "Bindings"));
    types.add(new ExtensionType("ui", "User Interfaces"));
    types.add(new ExtensionType("persistence", "Persistence Services"));
    for (ExtensionType type : types) {
        for (int i = 0; i < 10; i++) {
            String id = type.getId() + Integer.toString(i);
            boolean installed = Math.random() > 0.5;
            String name = RandomStringUtils.randomAlphabetic(5);
            String label = name + " " + StringUtils.capitalize(type.getId());
            String typeId = type.getId();
            String version = "1.0";
            String link = (Math.random() < 0.5) ? null : "http://lmgtfy.com/?q=" + name;
            String description = createDescription();
            String imageLink = null;
            String backgroundColor = createRandomColor();
            Extension extension = new Extension(id, typeId, label, version, link, installed, description, backgroundColor, imageLink);
            extensions.put(extension.getId(), extension);
        }
    }
}
Also used : Extension(org.eclipse.smarthome.core.extension.Extension) ExtensionType(org.eclipse.smarthome.core.extension.ExtensionType) Activate(org.osgi.service.component.annotations.Activate)

Example 47 with Activate

use of org.osgi.service.component.annotations.Activate in project APM by Cognifide.

the class ActionMapperRegistryImpl method activate.

@Activate
public void activate(ComponentContext componentContext) {
    registry = new AnnotatedClassRegistry(componentContext.getBundleContext(), BUNDLE_HEADER, Mapper.class);
    registry.addChangeListener(this);
    registry.open();
}
Also used : Mapper(com.cognifide.apm.api.actions.annotations.Mapper) AnnotatedClassRegistry(com.cognifide.apm.core.actions.scanner.AnnotatedClassRegistry) Activate(org.osgi.service.component.annotations.Activate)

Example 48 with Activate

use of org.osgi.service.component.annotations.Activate in project sling by apache.

the class JobManagerImpl method activate.

/**
     * Activate this component.
     * @param props Configuration properties
     */
@Activate
protected void activate(final BundleContext ctx, final Map<String, Object> props) throws LoginException {
    this.jobScheduler = new org.apache.sling.event.impl.jobs.scheduling.JobSchedulerImpl(this.configuration, this.scheduler, this);
    this.maintenanceTask = new CleanUpTask(this.configuration, this.jobScheduler);
    final Dictionary<String, Object> regProps = new Hashtable<>();
    regProps.put(ResourceChangeListener.PATHS, this.configuration.getScheduledJobsPath(false));
    regProps.put(ResourceChangeListener.CHANGES, new String[] { ResourceChange.ChangeType.ADDED.name(), ResourceChange.ChangeType.CHANGED.name(), ResourceChange.ChangeType.REMOVED.name() });
    regProps.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
    regProps.put(Constants.SERVICE_DESCRIPTION, "Resource change listener for scheduled jobs");
    this.changeListenerReg = ctx.registerService(ResourceChangeListener.class, this.jobScheduler, regProps);
    logger.info("Apache Sling Job Manager started on instance {}", Environment.APPLICATION_ID);
}
Also used : Hashtable(java.util.Hashtable) ResourceChangeListener(org.apache.sling.api.resource.observation.ResourceChangeListener) CleanUpTask(org.apache.sling.event.impl.jobs.tasks.CleanUpTask) JobSchedulerImpl(org.apache.sling.event.impl.jobs.scheduling.JobSchedulerImpl) Activate(org.osgi.service.component.annotations.Activate)

Example 49 with Activate

use of org.osgi.service.component.annotations.Activate in project sling by apache.

the class SlingServletResolver method activate.

// ---------- SCR Integration ----------------------------------------------
/**
     * Activate this component.
     */
@Activate
protected void activate(final BundleContext context, final Config config) throws LoginException {
    final Collection<PendingServlet> refs;
    synchronized (this.pendingServlets) {
        refs = new ArrayList<>(pendingServlets);
        pendingServlets.clear();
        this.sharedScriptResolver = resourceResolverFactory.getServiceResourceResolver(Collections.singletonMap(ResourceResolverFactory.SUBSERVICE, (Object) "scripts"));
        this.searchPaths = this.sharedScriptResolver.getSearchPath();
        servletResourceProviderFactory = new ServletResourceProviderFactory(config.servletresolver_servletRoot(), this.searchPaths);
        // register servlets immediately from now on
        this.context = context;
    }
    createAllServlets(refs);
    // execution paths
    this.executionPaths = config.servletresolver_paths();
    if (this.executionPaths != null) {
        // we simply set the array to null
        if (this.executionPaths.length == 0) {
            this.executionPaths = null;
        } else {
            boolean hasRoot = false;
            for (int i = 0; i < this.executionPaths.length; i++) {
                final String path = this.executionPaths[i];
                if (path == null || path.length() == 0 || path.equals("/")) {
                    hasRoot = true;
                    break;
                }
            }
            if (hasRoot) {
                this.executionPaths = null;
            }
        }
    }
    this.defaultExtensions = config.servletresolver_defaultExtensions();
    // create cache - if a cache size is configured
    this.cacheSize = config.servletresolver_cacheSize();
    if (this.cacheSize > 5) {
        this.cache = new ConcurrentHashMap<>(cacheSize);
        this.logCacheSizeWarning = true;
    } else {
        this.cacheSize = 0;
    }
    // setup default servlet
    this.getDefaultServlet();
    // and finally register as event listener if we need to flush the cache
    if (this.cache != null) {
        final Dictionary<String, Object> props = new Hashtable<>();
        props.put("event.topics", new String[] { "javax/script/ScriptEngineFactory/*", "org/apache/sling/api/adapter/AdapterFactory/*", "org/apache/sling/scripting/core/BindingsValuesProvider/*" });
        props.put(ResourceChangeListener.PATHS, "/");
        props.put("service.description", "Apache Sling Servlet Resolver and Error Handler");
        props.put("service.vendor", "The Apache Software Foundation");
        this.eventHandlerReg = context.registerService(new String[] { ResourceChangeListener.class.getName(), EventHandler.class.getName() }, this, props);
    }
    this.plugin = new ServletResolverWebConsolePlugin(context);
    if (this.cacheSize > 0) {
        try {
            Dictionary<String, String> mbeanProps = new Hashtable<>();
            mbeanProps.put("jmx.objectname", "org.apache.sling:type=servletResolver,service=SlingServletResolverCache");
            ServletResolverCacheMBeanImpl mbean = new ServletResolverCacheMBeanImpl();
            mbeanRegistration = context.registerService(SlingServletResolverCacheMBean.class, mbean, mbeanProps);
        } catch (Throwable t) {
            LOGGER.debug("Unable to register mbean");
        }
    }
}
Also used : Hashtable(java.util.Hashtable) ServletResourceProviderFactory(org.apache.sling.servlets.resolver.internal.resource.ServletResourceProviderFactory) SlingServletResolverCacheMBean(org.apache.sling.servlets.resolver.jmx.SlingServletResolverCacheMBean) Activate(org.osgi.service.component.annotations.Activate)

Example 50 with Activate

use of org.osgi.service.component.annotations.Activate in project sling by apache.

the class ResourcePresenter method activate.

@Activate
public void activate(final ResourcePresenterConfiguration configuration, final BundleContext bundleContext) {
    logger.info("activating resource presenter for {}", configuration.path());
    path = configuration.path();
    this.bundleContext = bundleContext;
    try (final ResourceResolver resourceResolver = getServiceResourceResolver()) {
        final Resource resource = resourceResolver.getResource(path);
        if (resource != null) {
            registerResourcePresence();
        }
        registerResourceChangeListener();
    } catch (LoginException e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) LoginException(org.apache.sling.api.resource.LoginException) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

Activate (org.osgi.service.component.annotations.Activate)100 BundleContext (org.osgi.framework.BundleContext)13 File (java.io.File)8 OsgiWhiteboard (org.apache.jackrabbit.oak.osgi.OsgiWhiteboard)7 IOException (java.io.IOException)6 Hashtable (java.util.Hashtable)6 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)5 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)4 ArrayList (java.util.ArrayList)4 Properties (java.util.Properties)3 ServiceReference (org.osgi.framework.ServiceReference)3 PromiseFactory (org.osgi.util.promise.PromiseFactory)3 ServerStartupObserver (org.wso2.carbon.core.ServerStartupObserver)3 JsonObject (com.google.gson.JsonObject)2 Date (java.util.Date)2 Dictionary (java.util.Dictionary)2 ObjectName (javax.management.ObjectName)2 Whiteboard (org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard)2 WhiteboardExecutor (org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardExecutor)2 LoginException (org.apache.sling.api.resource.LoginException)2