use of org.apache.stanbol.enhancer.servicesapi.impl.EnginesTracker 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.stanbol.enhancer.servicesapi.impl.EnginesTracker in project stanbol by apache.
the class WeightedChain method activate.
@Override
protected void activate(ComponentContext ctx) throws ConfigurationException {
super.activate(ctx);
Object value = ctx.getProperties().get(PROPERTY_CHAIN);
Set<String> configuredChain = new HashSet<String>();
if (value instanceof String[]) {
configuredChain.addAll(Arrays.asList((String[]) value));
} else if (value instanceof Collection<?>) {
for (Object o : (Collection<?>) value) {
if (o instanceof String) {
configuredChain.add((String) o);
}
}
} else {
throw new ConfigurationException(PROPERTY_CHAIN, "The engines of a Weigted Chain MUST BE configured as a Array or " + "Collection of Strings (parsed: " + (value != null ? value.getClass() : "null") + ")");
}
//now parse the configured chain
try {
chain = Collections.unmodifiableMap(parseConfig(configuredChain));
} catch (IllegalArgumentException e) {
throw new ConfigurationException(PROPERTY_CHAIN, "Unable to parse Chain Configuraiton (message: '" + e.getMessage() + "')!", e);
}
if (chain.isEmpty()) {
throw new ConfigurationException(PROPERTY_CHAIN, "The configured chain MUST at least contain a single valid entry!");
}
//init the chain scoped enhancement properties
chainScopedEnhProps = new HashMap<String, Map<String, Object>>();
if (getChainProperties() != null) {
chainScopedEnhProps.put(null, getChainProperties());
}
for (Entry<String, Map<String, List<String>>> entry : chain.entrySet()) {
Map<String, Object> enhProp = ConfigUtils.getEnhancementProperties(entry.getValue());
if (enhProp != null) {
chainScopedEnhProps.put(entry.getKey(), enhProp);
}
}
//start tracking the engines of the configured chain
tracker = new EnginesTracker(ctx.getBundleContext(), chain.keySet(), this);
tracker.open();
}
Aggregations