Package org.apache.stanbol.enhancer.engines.dereference

Examples of org.apache.stanbol.enhancer.engines.dereference.DereferenceEngineConfig


    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);
        log.debug(" - engineName: {}", engineConfig.getEngineName());
        //parse the Entityhub Site used for dereferencing
        Object value = properties.get(SITE_ID);
        //init the EntitySource
        if (value == null) {
            siteName = "*"; //all referenced sites
        } 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);
        //NOTE: registration of this instance as OSGI service is done as soon as the
        //      entityhub service backing the entityDereferencer is available.
       
        //finally start tracking
View Full Code Here

TOP

Related Classes of org.apache.stanbol.enhancer.engines.dereference.DereferenceEngineConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.