Java Code Examples for javax.cache.configuration.MutableConfiguration#setManagementEnabled()

The following examples show how to use javax.cache.configuration.MutableConfiguration#setManagementEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigStatsManagementActivationTest.java    From ehcache3 with Apache License 2.0 6 votes vote down vote up
@Test
public void testManagementDisabledOverriddenFromTemplate() throws Exception {
  CacheManager cacheManager = provider.getCacheManager(getClass().getResource("/ehcache-107-mbeans-template-config.xml")
          .toURI(),
      provider.getDefaultClassLoader());

  MutableConfiguration<Long, String> configuration = new MutableConfiguration<>();
  configuration.setTypes(Long.class, String.class);
  configuration.setManagementEnabled(false);
  configuration.setStatisticsEnabled(false);

  Cache<Long, String> cache = cacheManager.createCache("enables-mbeans", configuration);

  @SuppressWarnings("unchecked")
  Eh107Configuration<Long, String> eh107Configuration = cache.getConfiguration(Eh107Configuration.class);
  assertThat(eh107Configuration.isManagementEnabled(), is(true));
  assertThat(eh107Configuration.isStatisticsEnabled(), is(true));

  assertThat(isMbeanRegistered("enables-mbeans", MBEAN_MANAGEMENT_TYPE), is(true));
  assertThat(isMbeanRegistered("enables-mbeans", MBEAN_STATISTICS_TYPE), is(true));
}
 
Example 2
Source File: ConfigStatsManagementActivationTest.java    From ehcache3 with Apache License 2.0 6 votes vote down vote up
@Test
public void testManagementEnabledOverriddenFromTemplate() throws Exception {
  CacheManager cacheManager = provider.getCacheManager(getClass().getResource("/ehcache-107-mbeans-template-config.xml")
          .toURI(),
      provider.getDefaultClassLoader());

  MutableConfiguration<Long, String> configuration = new MutableConfiguration<>();
  configuration.setTypes(Long.class, String.class);
  configuration.setManagementEnabled(true);
  configuration.setStatisticsEnabled(true);

  Cache<Long, String> cache = cacheManager.createCache("disables-mbeans", configuration);

  @SuppressWarnings("unchecked")
  Eh107Configuration<Long, String> eh107Configuration = cache.getConfiguration(Eh107Configuration.class);
  assertThat(eh107Configuration.isManagementEnabled(), is(false));
  assertThat(eh107Configuration.isStatisticsEnabled(), is(false));

  assertThat(isMbeanRegistered("disables-mbeans", MBEAN_MANAGEMENT_TYPE), is(false));
  assertThat(isMbeanRegistered("disables-mbeans", MBEAN_STATISTICS_TYPE), is(false));
}
 
Example 3
Source File: ConfigStatsManagementActivationTest.java    From ehcache3 with Apache License 2.0 6 votes vote down vote up
@Test
public void basicJsr107StillWorks() throws Exception {
  CacheManager cacheManager = provider.getCacheManager();

  MutableConfiguration<Long, String> configuration = new MutableConfiguration<>();
  configuration.setTypes(Long.class, String.class);
  configuration.setManagementEnabled(true);
  configuration.setStatisticsEnabled(true);

  Cache<Long, String> cache = cacheManager.createCache("cache", configuration);
  @SuppressWarnings("unchecked")
  Eh107Configuration<Long, String> eh107Configuration = cache.getConfiguration(Eh107Configuration.class);

  assertThat(eh107Configuration.isManagementEnabled(), is(true));
  assertThat(eh107Configuration.isStatisticsEnabled(), is(true));

  assertThat(isMbeanRegistered("cache", MBEAN_MANAGEMENT_TYPE), is(true));
  assertThat(isMbeanRegistered("cache", MBEAN_STATISTICS_TYPE), is(true));
}
 
Example 4
Source File: CacheManagerManagementTest.java    From cache2k with Apache License 2.0 6 votes vote down vote up
@Test
public void testCacheManagementOffThenOnThenOff() throws Exception {
  MutableConfiguration configuration = new MutableConfiguration();
  configuration.setManagementEnabled(false);
  cacheManager.createCache("cache1", configuration);
  cacheManager.createCache("cache2", configuration);
  Set<? extends ObjectName> names = mBeanServer.queryNames(new ObjectName("javax.cache:*"), null);
  Assert.assertTrue(names.size() == 0);

  configuration.setManagementEnabled(true);
  cacheManager.createCache("cache3", configuration);
  cacheManager.createCache("cache4", configuration);
  assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(2));

  cacheManager.enableManagement("cache3", false);
  assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(1));


  cacheManager.enableManagement("cache3", true);
  assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), hasSize(2));
}
 
Example 5
Source File: CachingPrincipalAttributesRepository.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
/**
 * Prep cache configuration.
 *
 * @param expiryDuration the expiry duration
 * @return the mutable configuration
 */
protected static MutableConfiguration<String, Map<String, Object>> createCacheConfiguration(final Duration expiryDuration) {
    final MutableConfiguration<String, Map<String, Object>> config = new MutableConfiguration<>();
    config.setStatisticsEnabled(true);
    config.setManagementEnabled(true);
    config.setStoreByValue(true);
    config.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(expiryDuration));
    return config;
}
 
Example 6
Source File: TestCollector.java    From javamelody with Apache License 2.0 5 votes vote down vote up
/** Test.
 * @throws SchedulerException e */
@Test
public void testToString() throws SchedulerException {
	final Collector collector = createCollectorWithOneCounter();
	assertToStringNotEmpty("collector", collector);
	assertToStringNotEmpty("java", new JavaInformations(null, false));
	assertToStringNotEmpty("thread",
			new ThreadInformations(Thread.currentThread(),
					Arrays.asList(Thread.currentThread().getStackTrace()), 100, 1000, false,
					Parameters.getHostAddress()));
	assertToStringNotEmpty("session", new SessionInformations(new SessionTestImpl(true), true));
	assertToStringNotEmpty("memory", new MemoryInformations());
	CacheManager.getInstance().addCache("testToString");
	try {
		assertToStringNotEmpty("cache", new CacheInformations(
				CacheManager.getInstance().getEhcache("testToString"), false));
	} finally {
		CacheManager.getInstance().shutdown();
	}
	final MutableConfiguration<Object, Object> conf = new MutableConfiguration<Object, Object>();
	conf.setManagementEnabled(true);
	conf.setStatisticsEnabled(true);
	Caching.getCachingProvider().getCacheManager().createCache("cache", conf);
	try {
		assertToStringNotEmpty("cache", new JCacheInformations("cache"));
	} finally {
		Caching.getCachingProvider().getCacheManager().close();
	}
	final Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
	final JobDetail job = new JobDetail("job", null, JobTestImpl.class);
	assertToStringNotEmpty("job", new JobInformations(job, null, scheduler));
	assertToStringNotEmpty("connectionInfos", new ConnectionInformations());
}
 
Example 7
Source File: OpenJPAJCacheDataCacheManager.java    From commons-jcs with Apache License 2.0 5 votes vote down vote up
Cache<Object, Object> getOrCreateCache(final String prefix, final String entity)
{
    final String internalName = prefix + entity;
    Cache<Object, Object> cache = cacheManager.getCache(internalName);
    if (cache == null)
    {
        final Properties properties = cacheManager.getProperties();
        final MutableConfiguration<Object, Object> configuration = new MutableConfiguration<Object, Object>()
                .setStoreByValue("true".equalsIgnoreCase(properties.getProperty("jcache.store-by-value", "false")));

        configuration.setReadThrough("true".equals(properties.getProperty("jcache.read-through", "false")));
        configuration.setWriteThrough("true".equals(properties.getProperty("jcache.write-through", "false")));
        if (configuration.isReadThrough())
        {
            configuration.setCacheLoaderFactory(new FactoryBuilder.ClassFactory<CacheLoader<Object, Object>>(properties.getProperty("jcache.cache-loader-factory")));
        }
        if (configuration.isWriteThrough())
        {
            configuration.setCacheWriterFactory(new FactoryBuilder.ClassFactory<CacheWriter<Object, Object>>(properties.getProperty("jcache.cache-writer-factory")));
        }
        final String expirtyPolicy = properties.getProperty("jcache.expiry-policy-factory");
        if (expirtyPolicy != null)
        {
            configuration.setExpiryPolicyFactory(new FactoryBuilder.ClassFactory<ExpiryPolicy>(expirtyPolicy));
        }
        else
        {
            configuration.setExpiryPolicyFactory(new FactoryBuilder.SingletonFactory<ExpiryPolicy>(new CreatedExpiryPolicy(Duration.FIVE_MINUTES)));
        }
        configuration.setManagementEnabled("true".equals(properties.getProperty("jcache.management-enabled", "false")));
        configuration.setStatisticsEnabled("true".equals(properties.getProperty("jcache.statistics-enabled", "false")));

        cache = cacheManager.createCache(internalName, configuration);
    }
    return cache;
}
 
Example 8
Source File: JCacheAdapter.java    From cache2k with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <C extends Configuration<K, V>> C getConfiguration(Class<C> _class) {
  if (CompleteConfiguration.class.isAssignableFrom(_class)) {
    MutableConfiguration<K, V> cfg = new MutableConfiguration<K, V>();
    cfg.setTypes(keyType, valueType);
    cfg.setStatisticsEnabled(jmxStatisticsEnabled);
    cfg.setManagementEnabled(jmxEnabled);
    cfg.setStoreByValue(storeByValue);
    Collection<CacheEntryListenerConfiguration<K,V>> _listenerConfigurations = eventHandling.getAllListenerConfigurations();
    for (CacheEntryListenerConfiguration<K,V> _listenerConfig : _listenerConfigurations) {
      cfg.addCacheEntryListenerConfiguration(_listenerConfig);
    }
    return (C) cfg;
  }
  return (C) new Configuration<K, V>() {
    @Override
    public Class<K> getKeyType() {
      return keyType;
    }

    @Override
    public Class<V> getValueType() {
      return valueType;
    }

    @Override
    public boolean isStoreByValue() {
      return storeByValue;
    }
  };
}
 
Example 9
Source File: TestMonitoringFilter.java    From javamelody with Apache License 2.0 4 votes vote down vote up
/** Test.
 * @throws ServletException e
 * @throws IOException e */
@Test
public void testDoMonitoringWithParts() throws ServletException, IOException {
	final Map<HttpParameter, String> parameters = new HashMap<HttpParameter, String>();

	parameters.put(HttpParameter.PART, HttpPart.CURRENT_REQUESTS.getName());
	monitoring(parameters);
	parameters.put(HttpParameter.PART, HttpPart.THREADS.getName());
	monitoring(parameters);
	parameters.put(HttpParameter.PART, HttpPart.THREADS_DUMP.getName());
	monitoring(parameters);
	final File hsErrPidFile = new File("./hs_err_pid12345.log");
	try {
		hsErrPidFile.createNewFile();
		parameters.put(HttpParameter.PART, HttpPart.CRASHES.getName());
		monitoring(parameters, false);
		parameters.put(HttpParameter.PATH, hsErrPidFile.getAbsolutePath().replace('\\', '/'));
		monitoring(parameters, false);
		parameters.put(HttpParameter.PATH, "unknown");
		monitoring(parameters, false);
		parameters.remove(HttpParameter.PATH);
	} finally {
		hsErrPidFile.delete();
	}
	parameters.put(HttpParameter.PART, HttpPart.CACHE_KEYS.getName());
	final String cacheName = getClass().getName();
	CacheManager.getInstance().addCache(cacheName);
	parameters.put(HttpParameter.CACHE_ID, cacheName);
	monitoring(parameters);
	CacheManager.getInstance().getCache(cacheName).put(new Element("1", "value"));
	monitoring(parameters);
	parameters.put(HttpParameter.FORMAT, "htmlbody");
	monitoring(parameters);
	setProperty(Parameter.SYSTEM_ACTIONS_ENABLED, "false");
	monitoring(parameters);
	CacheManager.getInstance().removeCache(cacheName);
	parameters.remove(HttpParameter.CACHE_ID);
	parameters.remove(HttpParameter.FORMAT);
	setProperty(Parameter.SYSTEM_ACTIONS_ENABLED, TRUE);

	parameters.put(HttpParameter.PART, HttpPart.JCACHE_KEYS.getName());
	final MutableConfiguration<Object, Object> conf = new MutableConfiguration<Object, Object>();
	conf.setManagementEnabled(true);
	conf.setStatisticsEnabled(true);
	Caching.getCachingProvider().getCacheManager().createCache(cacheName, conf);
	Caching.getCachingProvider().getCacheManager().createCache(cacheName + "2", conf);
	parameters.put(HttpParameter.CACHE_ID, cacheName);
	monitoring(parameters);
	Caching.getCachingProvider().getCacheManager().getCache(cacheName).put("1", "value");
	monitoring(parameters);
	parameters.put(HttpParameter.FORMAT, "htmlbody");
	monitoring(parameters);
	setProperty(Parameter.SYSTEM_ACTIONS_ENABLED, "false");
	monitoring(parameters);
	Caching.getCachingProvider().getCacheManager().destroyCache(cacheName);
	parameters.remove(HttpParameter.CACHE_ID);
	parameters.remove(HttpParameter.FORMAT);
	setProperty(Parameter.SYSTEM_ACTIONS_ENABLED, TRUE);

	parameters.put(HttpParameter.PART, HttpPart.JNLP.getName());
	monitoring(parameters);
	setProperty(Parameter.JAVAMELODY_SWING_URL, "http://dummy");
	monitoring(parameters);
	parameters.put(HttpParameter.PART, HttpPart.DEPENDENCIES.getName());
	monitoring(parameters);
	parameters.put(HttpParameter.PART, HttpPart.COUNTER_SUMMARY_PER_CLASS.getName());
	parameters.put(HttpParameter.COUNTER, "services");
	monitoring(parameters);
	parameters.put(HttpParameter.GRAPH, "unknown service");
	monitoring(parameters);
	parameters.remove(HttpParameter.COUNTER);

	doMonitoringWithGraphPart();

	doMonitoringWithSourcePart();

	doMonitoringWithUnknownPart();
}
 
Example 10
Source File: TestAction.java    From javamelody with Apache License 2.0 4 votes vote down vote up
private void caches(final Collector collector, final String counterName, final String sessionId,
		final String threadId, final String jobId, final String cacheId) throws IOException {
	if (CacheManager.getInstance().getCache(cacheId) == null) {
		CacheManager.getInstance().addCache(cacheId);
	}
	assertNotNull("message CLEAR_CACHES", Action.CLEAR_CACHES.execute(collector, null, null,
			counterName, sessionId, threadId, jobId, cacheId));
	assertNotNull("message CLEAR_CACHE", Action.CLEAR_CACHE.execute(collector, null, null,
			counterName, sessionId, threadId, jobId, cacheId));
	assertNotNull("message CLEAR_CACHE", Action.CLEAR_CACHE.execute(collector, null, null,
			counterName, sessionId, threadId, jobId, "inconnu"));
	assertNotNull("message CLEAR_CACHE", Action.CLEAR_CACHE_KEY.execute(collector, null, null,
			counterName, sessionId, threadId, jobId, cacheId, "inconnue"));
	CacheManager.getInstance().getCache(cacheId).put(new Element("1", "value"));
	CacheManager.getInstance().getCache(cacheId).put(new Element("2", "value"));
	CacheManager.getInstance().getCache(cacheId).put(new Element(Integer.valueOf(3), "value"));
	assertNotNull("message CLEAR_CACHE", Action.CLEAR_CACHE_KEY.execute(collector, null, null,
			counterName, sessionId, threadId, jobId, "inconnu", "inconnue"));
	assertNotNull("message CLEAR_CACHE", Action.CLEAR_CACHE_KEY.execute(collector, null, null,
			counterName, sessionId, threadId, jobId, cacheId, "inconnue"));
	assertNotNull("message CLEAR_CACHE", Action.CLEAR_CACHE_KEY.execute(collector, null, null,
			counterName, sessionId, threadId, jobId, cacheId, "1"));
	assertNotNull("message CLEAR_CACHE", Action.CLEAR_CACHE_KEY.execute(collector, null, null,
			counterName, sessionId, threadId, jobId, cacheId, "3"));
	CacheManager.getInstance().removeCache(cacheId);

	final javax.cache.CacheManager jcacheManager = Caching.getCachingProvider()
			.getCacheManager();
	if (jcacheManager.getCache(cacheId) == null) {
		final MutableConfiguration<Object, Object> conf = new MutableConfiguration<Object, Object>();
		conf.setManagementEnabled(true);
		conf.setStatisticsEnabled(true);
		jcacheManager.createCache(cacheId, conf);
	}
	assertNotNull("message CLEAR_CACHES", Action.CLEAR_JCACHES.execute(collector, null, null,
			counterName, sessionId, threadId, jobId, cacheId));
	assertNotNull("message CLEAR_CACHE", Action.CLEAR_JCACHE.execute(collector, null, null,
			counterName, sessionId, threadId, jobId, cacheId));
	assertNotNull("message CLEAR_CACHE", Action.CLEAR_JCACHE.execute(collector, null, null,
			counterName, sessionId, threadId, jobId, "inconnu"));
	assertNotNull("message CLEAR_CACHE", Action.CLEAR_JCACHE_KEY.execute(collector, null, null,
			counterName, sessionId, threadId, jobId, "inconnu", "inconnue"));
	assertNotNull("message CLEAR_CACHE", Action.CLEAR_JCACHE_KEY.execute(collector, null, null,
			counterName, sessionId, threadId, jobId, cacheId, "inconnue"));
	jcacheManager.getCache(cacheId).put("1", "value");
	jcacheManager.getCache(cacheId).put("2", "value");
	jcacheManager.getCache(cacheId).put(Integer.valueOf(3), "value");
	assertNotNull("message CLEAR_CACHE", Action.CLEAR_JCACHE_KEY.execute(collector, null, null,
			counterName, sessionId, threadId, jobId, cacheId, "inconnue"));
	assertNotNull("message CLEAR_CACHE", Action.CLEAR_JCACHE_KEY.execute(collector, null, null,
			counterName, sessionId, threadId, jobId, cacheId, "1"));
	assertNotNull("message CLEAR_CACHE", Action.CLEAR_JCACHE_KEY.execute(collector, null, null,
			counterName, sessionId, threadId, jobId, cacheId, "3"));
	jcacheManager.destroyCache(cacheId);
}
 
Example 11
Source File: JCacheFilter.java    From commons-jcs with Apache License 2.0 4 votes vote down vote up
@Override
public void init(final FilterConfig filterConfig) throws ServletException
{
    final ClassLoader classLoader = filterConfig.getServletContext().getClassLoader();
    provider = Caching.getCachingProvider(classLoader);

    String uri = filterConfig.getInitParameter("configuration");
    if (uri == null)
    {
        uri = provider.getDefaultURI().toString();
    }
    final Properties properties = new Properties();
    for (final String key : list(filterConfig.getInitParameterNames()))
    {
        final String value = filterConfig.getInitParameter(key);
        if (value != null)
        {
            properties.put(key, value);
        }
    }
    manager = provider.getCacheManager(URI.create(uri), classLoader, properties);

    String cacheName = filterConfig.getInitParameter("cache-name");
    if (cacheName == null)
    {
        cacheName = JCacheFilter.class.getName();
    }
    cache = manager.getCache(cacheName);
    if (cache == null)
    {
        final MutableConfiguration<PageKey, Page> configuration = new MutableConfiguration<PageKey, Page>()
                .setStoreByValue(false);
        configuration.setReadThrough("true".equals(properties.getProperty("read-through", "false")));
        configuration.setWriteThrough("true".equals(properties.getProperty("write-through", "false")));
        if (configuration.isReadThrough())
        {
            configuration.setCacheLoaderFactory(new FactoryBuilder.ClassFactory<CacheLoader<PageKey, Page>>(properties.getProperty("cache-loader-factory")));
        }
        if (configuration.isWriteThrough())
        {
            configuration.setCacheWriterFactory(new FactoryBuilder.ClassFactory<CacheWriter<? super PageKey, ? super Page>>(properties.getProperty("cache-writer-factory")));
        }
        final String expirtyPolicy = properties.getProperty("expiry-policy-factory");
        if (expirtyPolicy != null)
        {
            configuration.setExpiryPolicyFactory(new FactoryBuilder.ClassFactory<ExpiryPolicy>(expirtyPolicy));
        }
        configuration.setManagementEnabled("true".equals(properties.getProperty("management-enabled", "false")));
        configuration.setStatisticsEnabled("true".equals(properties.getProperty("statistics-enabled", "false")));
        cache = manager.createCache(cacheName, configuration);
    }
}