Search in sources :

Example 61 with Activate

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

the class JobSubsystem method activate.

@Activate
public synchronized void activate() {
    jobStorage = new InMemoryJobStorage();
    messageSender = new OutboundJobUpdateListener(topicManager, queueManager);
    manager = new JobManagerImpl(jobStorage, messageSender);
}
Also used : InMemoryJobStorage(org.apache.sling.jobs.impl.storage.InMemoryJobStorage) Activate(org.osgi.service.component.annotations.Activate)

Example 62 with Activate

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

the class SlingMainServlet method activate.

// ---------- Property Setter for SCR --------------------------------------
@Activate
protected void activate(final BundleContext bundleContext, final Map<String, Object> componentConfig, final Config config) {
    final String[] props = config.sling_additional_response_headers();
    if (props != null) {
        final ArrayList<StaticResponseHeader> mappings = new ArrayList<>(props.length);
        for (final String prop : props) {
            if (prop != null && prop.trim().length() > 0) {
                try {
                    final StaticResponseHeader mapping = new StaticResponseHeader(prop.trim());
                    mappings.add(mapping);
                } catch (final IllegalArgumentException iae) {
                    log.info("configure: Ignoring '{}': {}", prop, iae.getMessage());
                }
            }
        }
        RequestData.setAdditionalResponseHeaders(mappings);
    }
    configuredServerInfo = config.sling_serverinfo();
    // setup server info
    setProductInfo(bundleContext);
    // prepare the servlet configuration from the component config
    final Hashtable<String, Object> configuration = new Hashtable<>(componentConfig);
    // ensure the servlet name
    if (!(configuration.get("servlet-name") instanceof String)) {
        configuration.put("servlet-name", this.productInfo);
    }
    // configure method filter
    allowTrace = config.sling_trace_allow();
    // configure the request limits
    RequestData.setMaxIncludeCounter(config.sling_max_inclusions());
    RequestData.setMaxCallCounter(config.sling_max_calls());
    RequestData.setSlingMainServlet(this);
    // Warn about the obsolete parameter encoding configuration
    if (componentConfig.get(DEPRECATED_ENCODING_PROPERTY) != null) {
        log.warn("Please configure the default request parameter encoding using " + "the 'org.apache.sling.engine.parameters' configuration PID; the property " + DEPRECATED_ENCODING_PROPERTY + "=" + componentConfig.get(DEPRECATED_ENCODING_PROPERTY) + " is obsolete and ignored");
    }
    // register the servlet context
    final Dictionary<String, String> contextProperties = new Hashtable<>();
    contextProperties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, SERVLET_CONTEXT_NAME);
    contextProperties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, SLING_ROOT);
    contextProperties.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Engine Servlet Context Helper");
    contextProperties.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
    this.contextRegistration = bundleContext.registerService(ServletContextHelper.class, this.slingHttpContext, contextProperties);
    // register the servlet
    final Dictionary<String, String> servletConfig = toStringConfig(configuration);
    servletConfig.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT, "(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=" + SERVLET_CONTEXT_NAME + ")");
    servletConfig.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, SLING_ROOT);
    servletConfig.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Engine Main Servlet");
    servletConfig.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
    this.servletRegistration = bundleContext.registerService(Servlet.class, this, servletConfig);
    log.info("{} ready to serve requests", this.getServerInfo());
    // now that the sling main servlet is registered with the HttpService
    // and initialized we can register the servlet context
    slingServletContext = new SlingServletContext(bundleContext, this);
    // register render filters already registered after registration with
    // the HttpService as filter initialization may cause the servlet
    // context to be required (see SLING-42)
    filterManager = new ServletFilterManager(bundleContext, slingServletContext);
    filterManager.open();
    requestProcessor.setFilterManager(filterManager);
    // initialize requestListenerManager
    requestListenerManager = new RequestListenerManager(bundleContext, slingServletContext);
    // Setup configuration printer
    this.printerRegistration = WebConsoleConfigPrinter.register(bundleContext, filterManager);
    // setup the request info recorder
    try {
        int maxRequests = config.sling_max_record_requests();
        String[] patterns = config.sling_store_pattern_requests();
        if (patterns == null)
            patterns = new String[0];
        List<Pattern> compiledPatterns = new ArrayList<>(patterns.length);
        for (String pattern : patterns) {
            if (pattern != null && pattern.trim().length() > 0) {
                compiledPatterns.add(Pattern.compile(pattern));
            }
        }
        RequestHistoryConsolePlugin.initPlugin(bundleContext, maxRequests, compiledPatterns);
    } catch (Throwable t) {
        log.debug("Unable to register web console request recorder plugin.", t);
    }
    try {
        Dictionary<String, String> mbeanProps = new Hashtable<>();
        mbeanProps.put("jmx.objectname", "org.apache.sling:type=engine,service=RequestProcessor");
        RequestProcessorMBeanImpl mbean = new RequestProcessorMBeanImpl();
        requestProcessorMBeanRegistration = bundleContext.registerService(RequestProcessorMBean.class, mbean, mbeanProps);
        requestProcessor.setMBean(mbean);
    } catch (Throwable t) {
        log.debug("Unable to register mbean");
    }
    // provide the SlingRequestProcessor service
    Hashtable<String, String> srpProps = new Hashtable<>();
    srpProps.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
    srpProps.put(Constants.SERVICE_DESCRIPTION, "Sling Request Processor");
    requestProcessorRegistration = bundleContext.registerService(SlingRequestProcessor.class, requestProcessor, srpProps);
}
Also used : Pattern(java.util.regex.Pattern) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) SlingRequestProcessor(org.apache.sling.engine.SlingRequestProcessor) SlingServletContext(org.apache.sling.engine.impl.helper.SlingServletContext) ServletContextHelper(org.osgi.service.http.context.ServletContextHelper) RequestProcessorMBean(org.apache.sling.engine.jmx.RequestProcessorMBean) RequestListenerManager(org.apache.sling.engine.impl.helper.RequestListenerManager) ServletFilterManager(org.apache.sling.engine.impl.filter.ServletFilterManager) Servlet(javax.servlet.Servlet) GenericServlet(javax.servlet.GenericServlet) Activate(org.osgi.service.component.annotations.Activate)

Example 63 with Activate

use of org.osgi.service.component.annotations.Activate in project com-liferay-apio-architect by liferay.

the class ApioApplicationRegistrar method activate.

@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);
    PersonModel.compute();
    BlogPostingModel.compute();
    BlogPostingCommentModel.compute();
}
Also used : Hashtable(java.util.Hashtable) Application(javax.ws.rs.core.Application) Activate(org.osgi.service.component.annotations.Activate)

Example 64 with Activate

use of org.osgi.service.component.annotations.Activate in project jackrabbit-oak by apache.

the class SecondaryStoreCacheService method activate.

@Activate
private void activate(BundleContext context, Configuration config) {
    bundleContext = context;
    whiteboard = new OsgiWhiteboard(context);
    String[] includedPaths = config.includedPaths();
    // TODO Support for exclude is not possible as once a NodeState is loaded from secondary
    // store it assumes that complete subtree is in same store. With exclude it would need to
    // check for each child access and route to primary
    pathFilter = new PathFilter(asList(includedPaths), Collections.<String>emptyList());
    SecondaryStoreBuilder builder = new SecondaryStoreBuilder(secondaryStoreProvider.getNodeStore()).differ(differ).metaPropNames(DocumentNodeStore.META_PROP_NAMES).statisticsProvider(statisticsProvider).pathFilter(pathFilter);
    SecondaryStoreCache cache = builder.buildCache();
    SecondaryStoreObserver observer = builder.buildObserver(cache);
    registerObserver(observer, config);
    regs.add(bundleContext.registerService(DocumentNodeStateCache.class.getName(), cache, null));
// TODO Need to see OSGi dynamics. Its possible that DocumentNodeStore works after the cache
// gets deregistered but the SegmentNodeState instances might still be in use and that would cause
// failure
}
Also used : PathFilter(org.apache.jackrabbit.oak.spi.filter.PathFilter) OsgiWhiteboard(org.apache.jackrabbit.oak.osgi.OsgiWhiteboard) Activate(org.osgi.service.component.annotations.Activate)

Example 65 with Activate

use of org.osgi.service.component.annotations.Activate in project jackrabbit-oak by apache.

the class IndexerMBeanImpl method activate.

// ~---------------------------------------< OSGi >
@Activate
private void activate(BundleContext context) {
    Whiteboard wb = new OsgiWhiteboard(context);
    editorProvider.start(wb);
    mbeanReg = registerMBean(wb, IndexerMBean.class, this, IndexerMBean.TYPE, "Indexer operations related MBean");
    providerTracker = wb.track(IndexImporterProvider.class);
}
Also used : OsgiWhiteboard(org.apache.jackrabbit.oak.osgi.OsgiWhiteboard) IndexerMBean(org.apache.jackrabbit.oak.api.jmx.IndexerMBean) IndexImporterProvider(org.apache.jackrabbit.oak.plugins.index.importer.IndexImporterProvider) Whiteboard(org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard) OsgiWhiteboard(org.apache.jackrabbit.oak.osgi.OsgiWhiteboard) 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