use of org.apache.felix.scr.annotations.Activate in project sling by apache.
the class CacheManagerServiceImpl method activate.
@Activate
public void activate(Map<String, Object> properties) throws FileNotFoundException, IOException {
String config = toString(properties.get(CACHE_CONFIG), DEFAULT_CACHE_CONFIG);
File configFile = new File(config);
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
if (configFile.exists()) {
LOGGER.info("Configuring Cache from {} ", configFile.getAbsolutePath());
InputStream in = null;
try {
in = processConfig(new FileInputStream(configFile), properties);
cacheManager = new DefaultCacheManager(in);
} finally {
if (in != null) {
in.close();
}
}
} else {
LOGGER.info("Configuring Cache from Classpath Default {} ", CONFIG_PATH);
InputStream in = processConfig(this.getClass().getClassLoader().getResourceAsStream(CONFIG_PATH), properties);
if (in == null) {
throw new IOException("Unable to open config at classpath location " + CONFIG_PATH);
}
cacheManager = new DefaultCacheManager(in);
in.close();
}
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
final WeakReference<CacheManagerServiceImpl> ref = new WeakReference<CacheManagerServiceImpl>(this);
/*
* Add in a shutdown hook, for safety
*/
Runtime.getRuntime().addShutdownHook(new Thread() {
/*
* (non-Javadoc)
*
* @see java.lang.Thread#run()
*/
@Override
public void run() {
try {
CacheManagerServiceImpl cm = ref.get();
if (cm != null) {
cm.deactivate();
}
} catch (Throwable t) {
LOGGER.debug(t.getMessage(), t);
}
}
});
// JMX Registration is performed by configuration
}
use of org.apache.felix.scr.annotations.Activate in project sling by apache.
the class CacheManagerServiceImpl method activate.
@Activate
public void activate(Map<String, Object> properties) throws FileNotFoundException, IOException {
String config = toString(properties.get(CACHE_CONFIG), DEFAULT_CACHE_CONFIG);
File configFile = new File(config);
if (configFile.exists()) {
LOGGER.info("Configuring Cache from {} ", configFile.getAbsolutePath());
InputStream in = null;
try {
in = processConfig(new FileInputStream(configFile), properties);
cacheManager = new CacheManager(in);
} finally {
if (in != null) {
in.close();
}
}
} else {
LOGGER.info("Configuring Cache from Classpath Default {} ", CONFIG_PATH);
InputStream in = processConfig(this.getClass().getClassLoader().getResourceAsStream(CONFIG_PATH), properties);
if (in == null) {
throw new IOException("Unable to open config at classpath location " + CONFIG_PATH);
}
cacheManager = new CacheManager(in);
in.close();
}
final WeakReference<CacheManagerServiceImpl> ref = new WeakReference<CacheManagerServiceImpl>(this);
/*
* Add in a shutdown hook, for safety
*/
Runtime.getRuntime().addShutdownHook(new Thread() {
/*
* (non-Javadoc)
*
* @see java.lang.Thread#run()
*/
@Override
public void run() {
try {
CacheManagerServiceImpl cm = ref.get();
if (cm != null) {
cm.deactivate();
}
} catch (Throwable t) {
LOGGER.debug(t.getMessage(), t);
}
}
});
// register the cache manager with JMX
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ManagementService.registerMBeans(cacheManager, mBeanServer, true, true, true, true);
}
use of org.apache.felix.scr.annotations.Activate in project sling by apache.
the class JsiGenerator method activate.
@Activate
public void activate(ComponentContext ctx) {
URL url = ctx.getBundleContext().getBundle().getResource(TEMPLATE_FILENAME);
if (url == null) {
LOG.error("File " + TEMPLATE_FILENAME + " not found in bundle.");
return;
}
readTemplateFromUrl(url);
}
use of org.apache.felix.scr.annotations.Activate in project sling by apache.
the class UserCredentialsDistributionTransportSecretProvider method activate.
@Activate
protected void activate(BundleContext context, Map<String, Object> config) {
username = PropertiesUtil.toString(config.get(USERNAME), "").trim();
password = PropertiesUtil.toString(config.get(PASSWORD), "").trim();
String id = String.valueOf(username.hashCode());
Dictionary<String, String> mbeanProps = new Hashtable<String, String>();
mbeanProps.put("jmx.objectname", "org.apache.sling.distribution:type=transport,id=" + ObjectName.quote(id));
UserCredentialsDistributionTransportSecretMBean mbean = new UserCredentialsDistributionTransportSecretMBeanImpl(username);
mbeanServiceRegistration = context.registerService(UserCredentialsDistributionTransportSecretMBean.class.getName(), mbean, mbeanProps);
}
use of org.apache.felix.scr.annotations.Activate in project sling by apache.
the class RemoteDistributionPackageExporterFactory method activate.
@Activate
protected void activate(Map<String, Object> config) throws Exception {
log.info("activating remote exporter with pb {} and dtsp {}", packageBuilder, transportSecretProvider);
String[] endpoints = PropertiesUtil.toStringArray(config.get(ENDPOINTS), new String[0]);
endpoints = SettingsUtils.removeEmptyEntries(endpoints);
int pollItems = PropertiesUtil.toInteger(config.get(PULL_ITEMS), Integer.MAX_VALUE);
String exporterName = PropertiesUtil.toString(config.get(NAME), null);
DefaultDistributionLog distributionLog = new DefaultDistributionLog(DistributionComponentKind.EXPORTER, exporterName, RemoteDistributionPackageExporter.class, DefaultDistributionLog.LogLevel.ERROR);
// default to 10s, we can expose it if needed
HttpConfiguration httpConfiguration = new HttpConfiguration(10000);
exporter = new RemoteDistributionPackageExporter(distributionLog, packageBuilder, transportSecretProvider, endpoints, pollItems, httpConfiguration);
}
Aggregations