Search in sources :

Example 6 with Activate

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

the class SightlyScriptEngineFactory method activate.

@Activate
protected void activate() {
    InputStream is;
    boolean newVersion = true;
    String versionInfo = null;
    String newVersionString = sightlyEngineConfiguration.getEngineVersion();
    try {
        is = classLoaderWriter.getInputStream(SIGHTLY_CONFIG_FILE);
        if (is != null) {
            versionInfo = IOUtils.toString(is, "UTF-8");
            if (newVersionString.equals(versionInfo)) {
                newVersion = false;
            } else {
                LOGGER.info("Detected stale classes generated by Apache Sling Scripting HTL engine version {}.", versionInfo);
            }
            IOUtils.closeQuietly(is);
        }
    } catch (IOException e) {
    // do nothing; if we didn't find any previous version information we're considering our version to be new
    }
    if (newVersion) {
        OutputStream os = classLoaderWriter.getOutputStream(SIGHTLY_CONFIG_FILE);
        try {
            IOUtils.write(sightlyEngineConfiguration.getEngineVersion(), os, "UTF-8");
        } catch (IOException e) {
        // ignore
        } finally {
            IOUtils.closeQuietly(os);
        }
        String scratchFolder = sightlyEngineConfiguration.getScratchFolder();
        boolean scratchFolderDeleted = classLoaderWriter.delete(scratchFolder);
        if (scratchFolderDeleted) {
            if (StringUtils.isNotEmpty(versionInfo)) {
                LOGGER.info("Deleted stale classes generated by Apache Sling Scripting HTL engine version {}.", versionInfo);
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) Activate(org.osgi.service.component.annotations.Activate)

Example 7 with Activate

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

the class SettingsSupport method activate.

/**
     * Start the component.
     * @param bc Bundle context
     */
@Activate
protected void activate(final BundleContext bc) {
    this.settingsListener = new Listener(bc);
    this.settingsListener.start();
}
Also used : ServiceListener(org.osgi.framework.ServiceListener) Activate(org.osgi.service.component.annotations.Activate)

Example 8 with Activate

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

the class FsResourceProvider method activate.

// ---------- SCR Integration
@Activate
protected void activate(BundleContext bundleContext, final Config config) {
    fsMode = config.provider_fs_mode();
    String providerRoot = config.provider_root();
    if (StringUtils.isBlank(providerRoot)) {
        throw new IllegalArgumentException("provider.root property must be set");
    }
    String providerFileName = config.provider_file();
    if (StringUtils.isBlank(providerFileName)) {
        throw new IllegalArgumentException("provider.file property must be set");
    }
    this.providerRoot = providerRoot;
    this.providerFile = getProviderFile(providerFileName, bundleContext);
    this.overlayParentResourceProvider = false;
    InitialContentImportOptions options = new InitialContentImportOptions(config.provider_initial_content_import_options());
    File filterXmlFile = null;
    List<String> contentFileSuffixes = new ArrayList<>();
    if (fsMode == FsMode.FILEVAULT_XML) {
        contentFileSuffixes.add("/" + DOT_CONTENT_XML);
        if (StringUtils.isNotBlank(config.provider_filevault_filterxml_path())) {
            filterXmlFile = new File(config.provider_filevault_filterxml_path());
        }
    } else if (fsMode == FsMode.FILES_FOLDERS) {
        overlayParentResourceProvider = true;
    } else if (fsMode == FsMode.INITIAL_CONTENT) {
        overlayParentResourceProvider = !options.isOverwrite();
        if (!options.getIgnoreImportProviders().contains(ContentType.JSON.getExtension())) {
            contentFileSuffixes.add(ContentFileTypes.JSON_SUFFIX);
        }
        if (!options.getIgnoreImportProviders().contains(ContentType.JCR_XML.getExtension())) {
            contentFileSuffixes.add(ContentFileTypes.JCR_XML_SUFFIX);
        }
        if (!options.getIgnoreImportProviders().contains(ContentType.XML.getExtension())) {
            contentFileSuffixes.add(ContentFileTypes.XML_SUFFIX);
        }
    }
    ContentFileExtensions contentFileExtensions = new ContentFileExtensions(contentFileSuffixes);
    this.contentFileCache = new ContentFileCache(config.provider_cache_size());
    if (fsMode == FsMode.FILEVAULT_XML) {
        this.fileVaultMapper = new FileVaultResourceMapper(this.providerFile, filterXmlFile, this.contentFileCache);
    } else {
        this.fileMapper = new FileResourceMapper(this.providerRoot, this.providerFile, contentFileExtensions, this.contentFileCache);
        this.contentFileMapper = new ContentFileResourceMapper(this.providerRoot, this.providerFile, contentFileExtensions, this.contentFileCache);
    }
    // start background monitor if check interval is higher than 100
    if (config.provider_checkinterval() > 100) {
        this.monitor = new FileMonitor(this, config.provider_checkinterval(), fsMode, contentFileExtensions, this.contentFileCache);
    }
}
Also used : ContentFileResourceMapper(org.apache.sling.fsprovider.internal.mapper.ContentFileResourceMapper) ArrayList(java.util.ArrayList) FileVaultResourceMapper(org.apache.sling.fsprovider.internal.mapper.FileVaultResourceMapper) ContentFileCache(org.apache.sling.fsprovider.internal.parser.ContentFileCache) FileResourceMapper(org.apache.sling.fsprovider.internal.mapper.FileResourceMapper) ContentFileResourceMapper(org.apache.sling.fsprovider.internal.mapper.ContentFileResourceMapper) File(java.io.File) Activate(org.osgi.service.component.annotations.Activate)

Example 9 with Activate

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

the class OakSlingRepositoryManager method activate.

@Activate
private void activate(final OakSlingRepositoryManagerConfiguration configuration, final ComponentContext componentContext) {
    this.configuration = configuration;
    this.componentContext = componentContext;
    final BundleContext bundleContext = componentContext.getBundleContext();
    final String defaultWorkspace = configuration.defaultWorkspace();
    final boolean disableLoginAdministrative = !configuration.admin_login_enabled();
    if (configuration.oak_observation_limitCommitRate()) {
        commitRateLimiter = new CommitRateLimiter();
    }
    this.threadPool = threadPoolManager.get("oak-observation");
    this.nodeAggregatorRegistration = bundleContext.registerService(NodeAggregator.class.getName(), getNodeAggregator(), null);
    super.start(bundleContext, new Config(defaultWorkspace, disableLoginAdministrative));
}
Also used : CommitRateLimiter(org.apache.jackrabbit.oak.plugins.observation.CommitRateLimiter) BundleContext(org.osgi.framework.BundleContext) Activate(org.osgi.service.component.annotations.Activate)

Example 10 with Activate

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

the class JcrResourceProvider method activate.

@Activate
protected void activate(final ComponentContext context) throws RepositoryException {
    SlingRepository repository = context.locateService(REPOSITORY_REFERNENCE_NAME, this.repositoryReference);
    if (repository == null) {
        // concurrent unregistration of SlingRepository service
        // don't care, this component is going to be deactivated
        // so we just stop working
        logger.warn("activate: Activation failed because SlingRepository may have been unregistered concurrently");
        return;
    }
    this.repository = repository;
    this.stateFactory = new JcrProviderStateFactory(repositoryReference, repository, classLoaderManagerReference);
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

Activate (org.osgi.service.component.annotations.Activate)78 BundleContext (org.osgi.framework.BundleContext)12 OsgiWhiteboard (org.apache.jackrabbit.oak.osgi.OsgiWhiteboard)7 IOException (java.io.IOException)6 Hashtable (java.util.Hashtable)6 File (java.io.File)5 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)5 ArrayList (java.util.ArrayList)4 Properties (java.util.Properties)3 Whiteboard (org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard)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 Dictionary (java.util.Dictionary)2 ObjectName (javax.management.ObjectName)2 WhiteboardExecutor (org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardExecutor)2 LoginException (org.apache.sling.api.resource.LoginException)2 ServiceListener (org.osgi.framework.ServiceListener)2 ServiceTracker (org.osgi.util.tracker.ServiceTracker)2