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