Search in sources :

Example 71 with Activate

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

the class CeliLemmatizerEnhancementEngine 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);
    try {
        this.completeMorphoAnalysis = (Boolean) properties.get(MORPHOLOGICAL_ANALYSIS);
    } catch (Exception e) {
        this.completeMorphoAnalysis = false;
    }
    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) EngineException(org.apache.stanbol.enhancer.servicesapi.EngineException) SOAPException(javax.xml.soap.SOAPException) ConfigurationException(org.osgi.service.cm.ConfigurationException) InvalidContentException(org.apache.stanbol.enhancer.servicesapi.InvalidContentException) IOException(java.io.IOException) Activate(org.apache.felix.scr.annotations.Activate)

Example 72 with Activate

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

the class EntityhubDereferenceEngine method activate.

@Activate
@SuppressWarnings("unchecked")
protected void activate(ComponentContext ctx) throws ConfigurationException {
    Dictionary<String, Object> properties = ctx.getProperties();
    bundleContext = ctx.getBundleContext();
    log.info("> activate {}", getClass().getSimpleName());
    // get the metadata later set to the enhancement engine
    DereferenceEngineConfig engineConfig = new DereferenceEngineConfig(properties, prefixService);
    log.debug(" - engineName: {}", engineConfig.getEngineName());
    // parse the Entityhub Site used for dereferencing
    Object value = properties.get(SITE_ID);
    // init the EntitySource
    if (value == null) {
        // all referenced sites
        siteName = "*";
    } else {
        siteName = value.toString();
    }
    if (siteName.isEmpty()) {
        siteName = "*";
    }
    log.debug(" - siteName: {}", siteName);
    final boolean sharedPoolState;
    value = properties.get(SHARED_THREAD_POOL_STATE);
    if (value instanceof Boolean) {
        sharedPoolState = ((Boolean) value).booleanValue();
    } else if (value != null && !StringUtils.isBlank(value.toString())) {
        sharedPoolState = Boolean.parseBoolean(value.toString());
    } else {
        sharedPoolState = DEFAULT_SHARED_THREAD_POOL_STATE;
    }
    final ExecutorServiceProvider esProvider;
    log.debug(" - shared thread pool state: {}", sharedPoolState);
    if (sharedPoolState) {
        esProvider = new SharedExecutorServiceProvider(ctx.getBundleContext());
    } else {
        // we need to create our own ExecutorService
        value = properties.get(THREAD_POOL_SIZE);
        if (value instanceof Number) {
            this.threadPoolSize = ((Number) value).intValue();
        } else if (value != null) {
            try {
                this.threadPoolSize = Integer.parseInt(value.toString());
            } catch (NumberFormatException e) {
                throw new ConfigurationException(THREAD_POOL_SIZE, "Value '" + value + "'(type: " + value.getClass().getName() + ") can not be parsed " + "as Integer");
            }
        } else {
            this.threadPoolSize = DEFAULT_THREAD_POOL_SIZE;
        }
        if (threadPoolSize > 0) {
            String namePattern = getClass().getSimpleName() + "-" + engineConfig.getEngineName() + "-thread-%s";
            ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(namePattern).setDaemon(true).build();
            log.debug(" - create Threadpool(namePattern='{}' | size='{}')", namePattern, threadPoolSize);
            executorService = Executors.newFixedThreadPool(threadPoolSize, threadFactory);
        } else {
            log.debug(" - no thread pool configured (poolSize: {})", threadPoolSize);
            executorService = null;
        }
        esProvider = new StaticExecutorServiceProvider(executorService);
    }
    // init the tracking entity searcher
    trackedServiceCount = 0;
    if (Entityhub.ENTITYHUB_IDS.contains(siteName.toLowerCase())) {
        log.info("  ... init Entityhub dereferencer");
        entityDereferencer = new EntityhubDereferencer(bundleContext, this, esProvider);
    } else if (siteName.equals("*")) {
        log.info("  ... init dereferencer for all referenced sites");
        entityDereferencer = new SitesDereferencer(bundleContext, this, esProvider);
    } else {
        log.info(" ... init dereferencer for referenced site {}", siteName);
        entityDereferencer = new SiteDereferencer(bundleContext, siteName, this, esProvider);
    }
    // set the namespace prefix service to the dereferencer
    entityDereferencer.setNsPrefixService(prefixService);
    // now parse dereference field config
    entityDereferencer.setDereferencedFields(engineConfig.getDereferenceFields());
    entityDereferencer.setLdPath(engineConfig.getLdPathProgram());
    entityDereferenceEngine = new EntityDereferenceEngine(entityDereferencer, engineConfig, new // we want to use our own DereferenceContext impl
    DereferenceContextFactory() {

        @Override
        public DereferenceContext createContext(EntityDereferenceEngine engine, Map<String, Object> enhancementProperties) throws DereferenceConfigurationException {
            return new EntityhubDereferenceContext(engine, enhancementProperties);
        }
    });
    // NOTE: registration of this instance as OSGI service is done as soon as the
    // entityhub service backing the entityDereferencer is available.
    // finally start tracking
    entityDereferencer.open();
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) DereferenceContextFactory(org.apache.stanbol.enhancer.engines.dereference.DereferenceContextFactory) DereferenceEngineConfig(org.apache.stanbol.enhancer.engines.dereference.DereferenceEngineConfig) SharedExecutorServiceProvider(org.apache.stanbol.enhancer.engines.dereference.entityhub.shared.SharedExecutorServiceProvider) EntityDereferenceEngine(org.apache.stanbol.enhancer.engines.dereference.EntityDereferenceEngine) SharedExecutorServiceProvider(org.apache.stanbol.enhancer.engines.dereference.entityhub.shared.SharedExecutorServiceProvider) ConfigurationException(org.osgi.service.cm.ConfigurationException) DereferenceConfigurationException(org.apache.stanbol.enhancer.engines.dereference.DereferenceConfigurationException) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Map(java.util.Map) Activate(org.apache.felix.scr.annotations.Activate)

Example 73 with Activate

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

the class CeliClassificationEnhancementEngine method activate.

@Override
@Activate
protected void activate(ComponentContext ctx) throws IOException, ConfigurationException {
    super.activate(ctx);
    @SuppressWarnings("unchecked") 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);
    int conTimeout = Utils.getConnectionTimeout(properties, ctx.getBundleContext());
    this.client = new ClassificationClientHTTP(this.serviceURL, this.licenseKey, conTimeout);
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) URL(java.net.URL) Activate(org.apache.felix.scr.annotations.Activate)

Example 74 with Activate

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

the class EnhancementEnginesRootResource method activate.

@Activate
protected void activate(ComponentContext ctx) {
    final BundleContext bc = ctx.getBundleContext();
    engineTracker = new EnginesTracker(bc, Collections.<String>emptySet(), new ServiceTrackerCustomizer() {

        @Override
        public Object addingService(ServiceReference reference) {
            Object service = bc.getService(reference);
            if (service != null) {
                // rebuild the cache on the next call
                _enginesCache = null;
            }
            return service;
        }

        @Override
        public void modifiedService(ServiceReference reference, Object service) {
            // rebuild the cache on the next call
            _enginesCache = null;
        }

        @Override
        public void removedService(ServiceReference reference, Object service) {
            if (reference != null) {
                bc.ungetService(reference);
                // rebuild the cache on the next call
                _enginesCache = null;
            }
        }
    });
    engineTracker.open();
}
Also used : ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) EnginesTracker(org.apache.stanbol.enhancer.servicesapi.impl.EnginesTracker) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Activate(org.apache.felix.scr.annotations.Activate)

Example 75 with Activate

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

the class ChainsRootResource method activate.

@Activate
public void activate(ComponentContext ctx) {
    final BundleContext bc = ctx.getBundleContext();
    chainTracker = new ChainsTracker(ctx.getBundleContext(), Collections.<String>emptySet(), new ServiceTrackerCustomizer() {

        @Override
        public Object addingService(ServiceReference reference) {
            Object service = bc.getService(reference);
            if (service != null) {
                // rebuild the cache on the next call
                _chainCache = null;
            }
            return service;
        }

        @Override
        public void modifiedService(ServiceReference reference, Object service) {
            // rebuild the cache on the next call
            _chainCache = null;
        }

        @Override
        public void removedService(ServiceReference reference, Object service) {
            if (reference != null) {
                bc.ungetService(reference);
                // rebuild the cache on the next call
                _chainCache = null;
            }
        }
    });
    chainTracker.open();
}
Also used : ChainsTracker(org.apache.stanbol.enhancer.servicesapi.impl.ChainsTracker) ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) 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