Search in sources :

Example 66 with Activate

use of org.apache.felix.scr.annotations.Activate in project stanbol by apache.

the class ManagedSiteComponent method activate.

/**
 * Activates this {@link ManagedSiteComponent}. This might be overridden to
 * perform additional configuration. In such cases super should be called
 * before the additional configuration steps.
 * @param context
 * @throws ConfigurationException
 * @throws YardException
 * @throws InvalidSyntaxException
 */
@Activate
protected void activate(final ComponentContext context) throws ConfigurationException, YardException, InvalidSyntaxException {
    this.bundleContext = context.getBundleContext();
    // NOTE that the constructor also validation of the parsed configuration
    this.siteConfiguration = new ManagedSiteConfigurationImpl(context.getProperties());
    if (PROHIBITED_SITE_IDS.contains(siteConfiguration.getId().toLowerCase())) {
        throw new ConfigurationException(SiteConfiguration.ID, String.format("The ID '%s' of this Referenced Site is one of the following " + "prohibited IDs: {} (case insensitive)", siteConfiguration.getId(), PROHIBITED_SITE_IDS));
    }
    log.info(" > initialise Managed Site {}", siteConfiguration.getId());
    SiteUtils.extractSiteMetadata(siteConfiguration, InMemoryValueFactory.getInstance());
    // Initialise the Yard
    final String yardId = siteConfiguration.getYardId();
    String yardFilterString = String.format("(&(%s=%s)(%s=%s))", Constants.OBJECTCLASS, Yard.class.getName(), Yard.ID, yardId);
    Filter yardFilter = bundleContext.createFilter(yardFilterString);
    yardTracker = new ServiceTracker(bundleContext, yardFilter, new ServiceTrackerCustomizer() {

        @Override
        public void removedService(ServiceReference reference, Object service) {
            synchronized (yardReferenceLock) {
                if (reference.equals(yardReference)) {
                    deactivateManagedSite();
                    yardReference = null;
                }
                bundleContext.ungetService(reference);
            }
        }

        @Override
        public void modifiedService(ServiceReference reference, Object service) {
        }

        @Override
        public Object addingService(ServiceReference reference) {
            Yard yard = (Yard) bundleContext.getService(reference);
            synchronized (yardReferenceLock) {
                if (yardReference == null) {
                    if (yard != null) {
                        activateManagedSite(yard);
                        yardReference = reference;
                    } else {
                        log.warn("Unable to addService for ServiceReference because" + "unable to obtain referenced Yard via the BundleContext!");
                    }
                } else {
                    log.warn("Tracking two Yard instances with the Yard ID '{}' " + "configured for ManagedSite '{}'", yardId, siteConfiguration.getId());
                    log.warn("used  : {}", yardReference.getProperty(Constants.SERVICE_PID));
                    log.warn("unused: {}", reference.getProperty(Constants.SERVICE_PID));
                }
            }
            return yard;
        }
    });
    yardTracker.open();
// will be moved to a Solr specific implementation
// //chaeck if we are allowed to init an yard with the provided id
// boolean allowInit = false;
// if(configAdmin!= null){
// Configuration[] configs;
// try {
// String yardIdFilter = String.format("(%s=%s)",
// Yard.ID,yardId);
// configs = configAdmin.listConfigurations(yardIdFilter);
// if(configs == null || configs.length < 1){
// allowInit = true;
// }
// } catch (IOException e) {
// log.warn("Unable to access ManagedService configurations ",e);
// }
// } else if (yardTracker.getService() == null){
// log.warn("Unable to check for Yard configuration of ManagedSite {} "
// + "Because the ConfigurationAdmin service is not available");
// log.warn(" -> unable to create YardConfiguration");
// }
// if(allowInit){
// //TODO: This has SolrYard specific code - this needs to be refactored
// String factoryPid = "org.apache.stanbol.entityhub.yard.solr.impl.SolrYard";
// try {
// Configuration config = configAdmin.createFactoryConfiguration(factoryPid,null);
// //configure the required properties
// Dictionary<String,Object> yardConfig = new Hashtable<String,Object>();
// yardConfig.put(Yard.ID, siteConfiguration.getYardId());
// yardConfig.put(Yard.NAME, siteConfiguration.getYardId());
// yardConfig.put(Yard.DESCRIPTION, "Yard for the ManagedSite "+siteConfiguration.getId());
// yardConfig.put("org.apache.stanbol.entityhub.yard.solr.solrUri", siteConfiguration.getId());
// yardConfig.put("org.apache.stanbol.entityhub.yard.solr.useDefaultConfig", true);
// config.update(yardConfig); //this create the solrYard
// } catch (IOException e) {
// log.warn("Unable to create SolrYard configuration for MnagedSite "+siteConfiguration.getId(),e);
// }
// }
}
Also used : Yard(org.apache.stanbol.entityhub.servicesapi.yard.Yard) ConfigurationException(org.osgi.service.cm.ConfigurationException) Filter(org.osgi.framework.Filter) ServiceTracker(org.osgi.util.tracker.ServiceTracker) ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) ServiceReference(org.osgi.framework.ServiceReference) Activate(org.apache.felix.scr.annotations.Activate)

Example 67 with Activate

use of org.apache.felix.scr.annotations.Activate in project stanbol by apache.

the class SolrIndexInstaller method activate.

@Activate
protected void activate(ComponentContext context) {
    bc = context.getBundleContext();
    serverTracker = new ServiceTracker(bc, ManagedSolrServer.class.getName(), new ServiceTrackerCustomizer() {

        /**
         * The servers managed by this instance
         */
        private SortedMap<ServiceReference, ManagedSolrServer> servers = new TreeMap<ServiceReference, ManagedSolrServer>();

        @Override
        public void removedService(ServiceReference reference, Object service) {
            lock.writeLock().lock();
            try {
                servers.remove(reference);
                updateRegistration(servers);
            } finally {
                lock.writeLock().unlock();
            }
        }

        @Override
        public void modifiedService(ServiceReference reference, Object service) {
            lock.writeLock().lock();
            try {
                servers.put(reference, (ManagedSolrServer) service);
                updateRegistration(servers);
            } finally {
                lock.writeLock().unlock();
            }
        }

        @Override
        public Object addingService(ServiceReference reference) {
            ManagedSolrServer server = (ManagedSolrServer) bc.getService(reference);
            if (server != null) {
                lock.writeLock().lock();
                try {
                    servers.put(reference, server);
                    updateRegistration(servers);
                } finally {
                    lock.writeLock().unlock();
                }
            }
            return server;
        }
    });
    serverTracker.open();
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) SortedMap(java.util.SortedMap) ManagedSolrServer(org.apache.stanbol.commons.solr.managed.ManagedSolrServer) ServiceReference(org.osgi.framework.ServiceReference) Activate(org.apache.felix.scr.annotations.Activate)

Example 68 with Activate

use of org.apache.felix.scr.annotations.Activate in project stanbol by apache.

the class ModelwriterRegistryImpl method activate.

@Activate
protected void activate(ComponentContext ctx) {
    modelTracker = new ModelWriterTracker(ctx.getBundleContext());
    modelTracker.open();
}
Also used : ModelWriterTracker(org.apache.stanbol.entityhub.web.writer.ModelWriterTracker) Activate(org.apache.felix.scr.annotations.Activate)

Example 69 with Activate

use of org.apache.felix.scr.annotations.Activate in project stanbol by apache.

the class CeliAnalyzedTextSentimentAnalysisEngine method activate.

@Override
@Activate
protected void activate(ComponentContext ctx) throws IOException, ConfigurationException {
    super.activate(ctx);
    Dictionary<String, Object> properties = ctx.getProperties();
    this.licenseKey = Utils.getLicenseKey(properties, ctx.getBundleContext());
    String url = (String) properties.get(SERVICE_URL);
    if (url == null || url.isEmpty()) {
        throw new ConfigurationException(SERVICE_URL, String.format("%s : please configure the URL of the CELI Web Service (e.g. by" + "using the 'Configuration' tab of the Apache Felix Web Console).", getClass().getSimpleName()));
    }
    this.serviceURL = new URL(url);
    // parse the parsed language configuration
    languageConfig.setConfiguration(properties);
    int connectionTimeout = Utils.getConnectionTimeout(properties, ctx.getBundleContext());
    this.client = new SentimentAnalysisServiceClientHttp(this.serviceURL, this.licenseKey, connectionTimeout);
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) URL(java.net.URL) Activate(org.apache.felix.scr.annotations.Activate)

Example 70 with Activate

use of org.apache.felix.scr.annotations.Activate in project stanbol by apache.

the class CeliAnalyzedTextLemmatizerEngine method activate.

@Override
@Activate
protected void activate(ComponentContext ctx) throws IOException, ConfigurationException {
    super.activate(ctx);
    Dictionary<String, Object> properties = ctx.getProperties();
    this.licenseKey = Utils.getLicenseKey(properties, ctx.getBundleContext());
    String url = (String) properties.get(SERVICE_URL);
    if (url == null || url.isEmpty()) {
        throw new ConfigurationException(SERVICE_URL, String.format("%s : please configure the URL of the CELI Web Service (e.g. by" + "using the 'Configuration' tab of the Apache Felix Web Console).", getClass().getSimpleName()));
    }
    this.serviceURL = new URL(url);
    // parse the parsed language configuration
    languageConfig.setConfiguration(properties);
    int conTimeout = Utils.getConnectionTimeout(properties, ctx.getBundleContext());
    this.client = new LemmatizerClientHTTP(this.serviceURL, this.licenseKey, conTimeout);
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) URL(java.net.URL) Activate(org.apache.felix.scr.annotations.Activate)

Aggregations

Activate (org.apache.felix.scr.annotations.Activate)153 ConfigurationException (org.osgi.service.cm.ConfigurationException)31 ServiceTracker (org.osgi.util.tracker.ServiceTracker)20 BundleContext (org.osgi.framework.BundleContext)19 File (java.io.File)15 OsgiWhiteboard (org.apache.jackrabbit.oak.osgi.OsgiWhiteboard)12 URL (java.net.URL)11 Hashtable (java.util.Hashtable)11 ServiceReference (org.osgi.framework.ServiceReference)11 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)9 HashSet (java.util.HashSet)8 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 Map (java.util.Map)6 Session (javax.jcr.Session)5 StandardMBean (javax.management.StandardMBean)5 Whiteboard (org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard)5 Filter (org.osgi.framework.Filter)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4