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);
}
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();
}
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);
}
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();
}
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();
}
Aggregations