use of org.osgi.service.component.annotations.Activate in project sling by apache.
the class FSClassLoaderProvider method activate.
/**
* Activate this component. Create the root directory.
*
* @param componentContext
* @throws MalformedURLException
* @throws InvalidSyntaxException
* @throws MalformedObjectNameException
*/
@Activate
protected void activate(final ComponentContext componentContext) throws MalformedURLException, InvalidSyntaxException, MalformedObjectNameException {
// get the file root
this.root = new File(componentContext.getBundleContext().getDataFile(""), "classes");
this.root.mkdirs();
this.rootURL = this.root.toURI().toURL();
this.callerBundle = componentContext.getUsingBundle();
classLoaderWriterListeners.clear();
if (classLoaderWriterServiceListener != null) {
componentContext.getBundleContext().removeServiceListener(classLoaderWriterServiceListener);
classLoaderWriterServiceListener = null;
}
classLoaderWriterServiceListener = new ServiceListener() {
@Override
public void serviceChanged(ServiceEvent event) {
ServiceReference<ClassLoaderWriterListener> reference = (ServiceReference<ClassLoaderWriterListener>) event.getServiceReference();
if (event.getType() == ServiceEvent.MODIFIED || event.getType() == ServiceEvent.REGISTERED) {
classLoaderWriterListeners.put(getId(reference), reference);
} else {
classLoaderWriterListeners.remove(getId(reference));
}
}
private Long getId(ServiceReference<ClassLoaderWriterListener> reference) {
return (Long) reference.getProperty(Constants.SERVICE_ID);
}
};
componentContext.getBundleContext().addServiceListener(classLoaderWriterServiceListener, LISTENER_FILTER);
// handle the MBean Installation
if (mbeanRegistration != null) {
mbeanRegistration.unregister();
mbeanRegistration = null;
}
Hashtable<String, String> jmxProps = new Hashtable<String, String>();
jmxProps.put("type", "ClassLoader");
jmxProps.put("name", "FSClassLoader");
final Hashtable<String, Object> mbeanProps = new Hashtable<String, Object>();
mbeanProps.put(Constants.SERVICE_DESCRIPTION, "Apache Sling FSClassLoader Controller Service");
mbeanProps.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
mbeanProps.put("jmx.objectname", new ObjectName("org.apache.sling.classloader", jmxProps));
mbeanRegistration = componentContext.getBundleContext().registerService(FSClassLoaderMBean.class.getName(), new FSClassLoaderMBeanImpl(this, componentContext.getBundleContext()), mbeanProps);
}
use of org.osgi.service.component.annotations.Activate in project sling by apache.
the class PostOperationProxyProvider method activate.
// DS activation/deactivation
/**
* Activates the proxy provider component:
* <ol>
* <li>Keep BundleContext reference</li>
* <li>Start listening for SlingPostOperation services</li>
* <li>Register proxies for all existing SlingPostOperation services</li>
* </ol>
*/
@SuppressWarnings("unused")
@Activate
private void activate(final BundleContext bundleContext) {
this.bundleContext = bundleContext;
try {
bundleContext.addServiceListener(this, REFERENCE_FILTER);
final ServiceReference[] serviceReferences = bundleContext.getServiceReferences(SlingPostOperation.SERVICE_NAME, null);
if (serviceReferences != null) {
for (ServiceReference serviceReference : serviceReferences) {
register(serviceReference);
}
}
} catch (InvalidSyntaxException ise) {
// not expected for tested static filter
// TODO:log !!
}
}
use of org.osgi.service.component.annotations.Activate in project sling by apache.
the class OakMockSlingRepository method activate.
@Activate
protected void activate(BundleContext bundleContext) {
executor = Executors.newSingleThreadExecutor();
scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
if (bundleContext.getServiceReference(Executor.class) == null) {
bundleContext.registerService(Executor.class, executor, null);
}
Oak oak = new Oak().with(executor).with(scheduledExecutor);
Jcr jcr = new Jcr(oak).with(new ExtraSlingContent()).with(executor).with(scheduledExecutor);
this.repository = jcr.createRepository();
}
use of org.osgi.service.component.annotations.Activate in project carbon-apimgt by wso2.
the class BundleActivator method start.
@Activate
protected void start(BundleContext bundleContext) {
try {
// Set default timestamp to UTC
java.util.TimeZone.setDefault(java.util.TimeZone.getTimeZone("Etc/UTC"));
Context ctx = jndiContextManager.newInitialContext();
DataSource dataSourceAMDB = new DataSourceImpl((HikariDataSource) ctx.lookup("java:comp/env/jdbc/WSO2AMDB"));
DAOUtil.initialize(dataSourceAMDB);
boolean isAnalyticsEnabled = ServiceReferenceHolder.getInstance().getAPIMConfiguration().getAnalyticsConfigurations().isEnabled();
if (isAnalyticsEnabled) {
DataSource dataSourceStatDB = new DataSourceImpl((HikariDataSource) ctx.lookup("java:comp/env/jdbc/WSO2AMSTATSDB"));
DAOUtil.initializeAnalyticsDataSource(dataSourceStatDB);
}
WorkflowExtensionsConfigBuilder.build(configProvider);
ServiceDiscoveryConfigBuilder.build(configProvider);
ContainerBasedGatewayConfigBuilder.build(configProvider);
BrokerManager.start();
Broker broker = new BrokerImpl();
BrokerUtil.initialize(broker);
} catch (NamingException e) {
log.error("Error occurred while jndi lookup", e);
}
// deploying default policies
try {
ThrottlerUtil.addDefaultAdvancedThrottlePolicies();
if (log.isDebugEnabled()) {
log.debug("Checked default throttle policies successfully");
}
} catch (APIManagementException e) {
log.error("Error occurred while deploying default policies", e);
}
// securing files
try {
boolean fileEncryptionEnabled = ServiceReferenceHolder.getInstance().getAPIMConfiguration().getFileEncryptionConfigurations().isEnabled();
if (fileEncryptionEnabled) {
FileEncryptionUtility fileEncryptionUtility = FileEncryptionUtility.getInstance();
fileEncryptionUtility.init();
fileEncryptionUtility.encryptFiles();
}
} catch (APIManagementException e) {
log.error("Error occurred while encrypting files", e);
}
}
use of org.osgi.service.component.annotations.Activate in project karaf by apache.
the class ServiceComponentRuntimeMBeanImpl method activate.
/**
* Service component activation call back. Called when all dependencies are satisfied.
*
* @throws Exception If the activation fails.
*/
@Activate
public void activate(BundleContext context) throws Exception {
LOGGER.info("Activating the " + COMPONENT_LABEL);
Map<Object, String> mbeans = new HashMap<>();
mbeans.put(this, "org.apache.karaf:type=scr,name=${karaf.name}");
try {
lock.writeLock().lock();
this.context = context;
if (mBeanServer != null) {
mBeanServer.registerMBean(this, new ObjectName(OBJECT_NAME));
}
} catch (Exception e) {
LOGGER.error("Exception registering the SCR Management MBean: " + e.getLocalizedMessage(), e);
} finally {
lock.writeLock().unlock();
}
}
Aggregations