Actions
There are two forms of capabilities: statistics and action ones. The statistic ones offer a set of predefined statistics that can be queried at will, while the action ones offer a set of actions that can be taken upon a managed object. Examples of actions could be: clear caches, get their config or modify a config setting.
CacheConfiguration<Long, String> cacheConfiguration =
CacheConfigurationBuilder.newCacheConfigurationBuilder(
Long.class, String.class, ResourcePoolsBuilder.heap(10))
.build();
CacheManager cacheManager = null;
try {
ManagementRegistryService managementRegistry =
new DefaultManagementRegistryService();
cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.withCache("aCache", cacheConfiguration)
.using(managementRegistry)
.build(true);
Cache<Long, String> aCache =
cacheManager.getCache("aCache", Long.class, String.class);
aCache.put(0L, "zero"); // 1
Context context =
StatsUtil.createContext(managementRegistry); // 2
managementRegistry.withCapability("ActionsCapability") // 3
.call("clear")
.on(context)
.build()
.execute();
Assert.assertThat(aCache.get(0L),
Matchers.is(Matchers.nullValue())); // 4
}
finally {
if(cacheManager != null) cacheManager.close();
}
1 | Put something in a cache. |
2 | Call the 'clear' action on the managed cache. Refer to the descriptors of the provider to get the exact list of action names and their required parameters. |
3 | Call the clear action on the cache. |
4 | Make sure that the cache is now empty. |