// Path: cache/src/main/java/com/steeleforge/aem/ironsites/cache/service/SimpleCacheService.java
// public interface SimpleCacheService {
//     /**
//      * Known cache names/keys
//      * 
//      * @return set of cache keys
//      */
//     public Set<String> getCaches();
//     
//     /**
//      * Access OSGi configured or application managed cache for name & options.
//      * 
//      * @param name cache key
//      * @param spec {@link <a href="http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/cache/CacheBuilderSpec.html">CacheBuilderSpec</a>}
//      * @param stats true if recording statistics is desired
//      * @return pre-existing or new cache
//      */
//     public Cache<Object, Object> getCache(String name, String spec, boolean stats);
//     
//     /**
//      * Access OSGi configured or application managed cache by name.
//      * 
//      * @param name cache key
//      * @return pre-existing or new cache
//      */
//     public Cache<Object, Object> getCache(String name);
//     
//     /**
//      * Cache by name as Map.
//      * 
//      * @param name cache key
//      * @return pre-existing/new cache or null
//      */
//     public Map<Object, Object> getCacheMap(String name);
//     
//     /**
//      * Access cache statistics by name.
//      * 
//      * @param name cache key
//      * @return cache statistics
//      * @see <a href="http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/cache/CacheStats.html">CacheStats</a>
//      */
//     public CacheStats getStats(String name);
//     
//     /**
//      * Invalidate and destroy cache by name.
//      * 
//      * @param name
//      */
//     public void clearCache(String name);
// }
// 
// Path: cache/src/main/java/com/steeleforge/aem/ironsites/cache/service/SimpleCacheServiceMBean.java
// @Description("SimpleCache MBean")
// public interface SimpleCacheServiceMBean {
//     @Description("Caches")
//     public Set<String> getCacheNames();
// 
//     @Description("Cache Size")
//     public long getCacheSize(String cache);
//     
//     @Description("Cache Access/Miss Statistics")
//     public CacheStats getCacheStats(String cache);
// 
//     @Description("Invalidate Cache")
//     public void clearCache(String cache);
// }


import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import com.adobe.granite.jmx.annotation.AnnotatedStandardMBean;
import com.google.common.cache.CacheStats;
import com.steeleforge.aem.ironsites.cache.service.SimpleCacheService;
import com.steeleforge.aem.ironsites.cache.service.SimpleCacheServiceMBean;
import java.util.Set;
import javax.management.DynamicMBean;
import javax.management.NotCompliantMBeanException;
/** 
 * This is free and unencumbered software released into the public domain.
 * 
 * Anyone is free to copy, modify, publish, use, compile, sell, or
 * distribute this software, either in source code form or as a compiled
 * binary, for any purpose, commercial or non-commercial, and by any
 * means.
 * 
 * In jurisdictions that recognize copyright laws, the author or authors
 * of this software dedicate any and all copyright interest in the
 * software to the public domain. We make this dedication for the benefit
 * of the public at large and to the detriment of our heirs and
 * successors. We intend this dedication to be an overt act of
 * relinquishment in perpetuity of all present and future rights to this
 * software under copyright law.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 * 
 * For more information, please refer to <http://unlicense.org/>
 */
package com.steeleforge.aem.ironsites.cache.service.impl;





@Service(value = DynamicMBean.class)
@Component(name = "SimpleCacheService JMX", immediate = true)
@Property(name = "jmx.objectname", value = "com.steeleforge.aem.ironsites.cache:type=SimpleCacheServiceMBean")
public class SimpleCacheServiceMBeanImpl extends AnnotatedStandardMBean implements SimpleCacheServiceMBean {

    @Reference
    private SimpleCacheService cacheService;

    public SimpleCacheServiceMBeanImpl() throws NotCompliantMBeanException {
        super(SimpleCacheServiceMBean.class);
    }

    @Override
    public Set<String> getCacheNames() {
        return cacheService.getCaches();
    }

    @Override
    public long getCacheSize(String cacheName) {
        return cacheService.getCache(cacheName).size();
    }

    @Override
    public CacheStats getCacheStats(String cacheName) {
        return cacheService.getStats(cacheName);
    }
    
    @Override
    public void clearCache(String cacheName) {
// Path: cache/src/main/java/com/steeleforge/aem/ironsites/cache/service/SimpleCacheService.java
// public interface SimpleCacheService {
//     /**
//      * Known cache names/keys
//      * 
//      * @return set of cache keys
//      */
//     public Set<String> getCaches();
//     
//     /**
//      * Access OSGi configured or application managed cache for name & options.
//      * 
//      * @param name cache key
//      * @param spec {@link <a href="http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/cache/CacheBuilderSpec.html">CacheBuilderSpec</a>}
//      * @param stats true if recording statistics is desired
//      * @return pre-existing or new cache
//      */
//     public Cache<Object, Object> getCache(String name, String spec, boolean stats);
//     
//     /**
//      * Access OSGi configured or application managed cache by name.
//      * 
//      * @param name cache key
//      * @return pre-existing or new cache
//      */
//     public Cache<Object, Object> getCache(String name);
//     
//     /**
//      * Cache by name as Map.
//      * 
//      * @param name cache key
//      * @return pre-existing/new cache or null
//      */
//     public Map<Object, Object> getCacheMap(String name);
//     
//     /**
//      * Access cache statistics by name.
//      * 
//      * @param name cache key
//      * @return cache statistics
//      * @see <a href="http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/cache/CacheStats.html">CacheStats</a>
//      */
//     public CacheStats getStats(String name);
//     
//     /**
//      * Invalidate and destroy cache by name.
//      * 
//      * @param name
//      */
//     public void clearCache(String name);
// }
// 
// Path: cache/src/main/java/com/steeleforge/aem/ironsites/cache/service/SimpleCacheServiceMBean.java
// @Description("SimpleCache MBean")
// public interface SimpleCacheServiceMBean {
//     @Description("Caches")
//     public Set<String> getCacheNames();
// 
//     @Description("Cache Size")
//     public long getCacheSize(String cache);
//     
//     @Description("Cache Access/Miss Statistics")
//     public CacheStats getCacheStats(String cache);
// 
//     @Description("Invalidate Cache")
//     public void clearCache(String cache);
// }


// Path: cache/src/main/java/com/steeleforge/aem/ironsites/cache/service/impl/SimpleCacheServiceMBeanImpl.java
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import com.adobe.granite.jmx.annotation.AnnotatedStandardMBean;
import com.google.common.cache.CacheStats;
import com.steeleforge.aem.ironsites.cache.service.SimpleCacheService;
import com.steeleforge.aem.ironsites.cache.service.SimpleCacheServiceMBean;
import java.util.Set;
import javax.management.DynamicMBean;
import javax.management.NotCompliantMBeanException;

/** 
 * This is free and unencumbered software released into the public domain.
 * 
 * Anyone is free to copy, modify, publish, use, compile, sell, or
 * distribute this software, either in source code form or as a compiled
 * binary, for any purpose, commercial or non-commercial, and by any
 * means.
 * 
 * In jurisdictions that recognize copyright laws, the author or authors
 * of this software dedicate any and all copyright interest in the
 * software to the public domain. We make this dedication for the benefit
 * of the public at large and to the detriment of our heirs and
 * successors. We intend this dedication to be an overt act of
 * relinquishment in perpetuity of all present and future rights to this
 * software under copyright law.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 * 
 * For more information, please refer to <http://unlicense.org/>
 */
package com.steeleforge.aem.ironsites.cache.service.impl;





@Service(value = DynamicMBean.class)
@Component(name = "SimpleCacheService JMX", immediate = true)
@Property(name = "jmx.objectname", value = "com.steeleforge.aem.ironsites.cache:type=SimpleCacheServiceMBean")
public class SimpleCacheServiceMBeanImpl extends AnnotatedStandardMBean implements SimpleCacheServiceMBean {

    @Reference
    private SimpleCacheService cacheService;

    public SimpleCacheServiceMBeanImpl() throws NotCompliantMBeanException {
        super(SimpleCacheServiceMBean.class);
    }

    @Override
    public Set<String> getCacheNames() {
        return cacheService.getCaches();
    }

    @Override
    public long getCacheSize(String cacheName) {
        return cacheService.getCache(cacheName).size();
    }

    @Override
    public CacheStats getCacheStats(String cacheName) {
        return cacheService.getStats(cacheName);
    }
    
    @Override
    public void clearCache(String cacheName) {
        cacheService.clearCache(cacheName);