Search in sources :

Example 21 with Activate

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
}
Also used : DefaultCacheManager(org.infinispan.manager.DefaultCacheManager) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) WeakReference(java.lang.ref.WeakReference) File(java.io.File) Activate(org.apache.felix.scr.annotations.Activate)

Example 22 with Activate

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);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) WeakReference(java.lang.ref.WeakReference) CacheManager(net.sf.ehcache.CacheManager) File(java.io.File) MBeanServer(javax.management.MBeanServer) Activate(org.apache.felix.scr.annotations.Activate)

Example 23 with Activate

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);
}
Also used : URL(java.net.URL) Activate(org.apache.felix.scr.annotations.Activate)

Example 24 with Activate

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);
}
Also used : UserCredentialsDistributionTransportSecretMBean(org.apache.sling.distribution.monitor.impl.UserCredentialsDistributionTransportSecretMBean) Hashtable(java.util.Hashtable) UserCredentialsDistributionTransportSecretMBeanImpl(org.apache.sling.distribution.monitor.impl.UserCredentialsDistributionTransportSecretMBeanImpl) Activate(org.apache.felix.scr.annotations.Activate)

Example 25 with Activate

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);
}
Also used : DefaultDistributionLog(org.apache.sling.distribution.log.impl.DefaultDistributionLog) HttpConfiguration(org.apache.sling.distribution.transport.impl.HttpConfiguration) Activate(org.apache.felix.scr.annotations.Activate)

Aggregations

Activate (org.apache.felix.scr.annotations.Activate)153 ConfigurationException (org.osgi.service.cm.ConfigurationException)31 ServiceTracker (org.osgi.util.tracker.ServiceTracker)20 BundleContext (org.osgi.framework.BundleContext)19 File (java.io.File)15 OsgiWhiteboard (org.apache.jackrabbit.oak.osgi.OsgiWhiteboard)12 URL (java.net.URL)11 Hashtable (java.util.Hashtable)11 ServiceReference (org.osgi.framework.ServiceReference)11 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)9 HashSet (java.util.HashSet)8 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 Map (java.util.Map)6 Session (javax.jcr.Session)5 StandardMBean (javax.management.StandardMBean)5 Whiteboard (org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard)5 Filter (org.osgi.framework.Filter)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4