* @see org.jboss.ejb3.cache.infinispan.CacheSource#getCache(org.jboss.ejb3.stateful.StatefulContainer)
*/
@Override
public <K, V> Cache<K, V> getCache(StatefulContainer ejbContainer)
{
CacheConfig cacheConfig = ejbContainer.getAnnotation(CacheConfig.class);
String containerName = StringPropertyReplacer.replaceProperties(cacheConfig.name());
String templateCacheName = null;
if ((containerName == null) || containerName.isEmpty())
{
containerName = CacheConfig.DEFAULT_CLUSTERED_OBJECT_NAME;
}
else
{
String[] parts = containerName.split("/");
if (parts.length == 2)
{
containerName = parts[0];
templateCacheName = parts[1];
}
}
String cacheName = ejbContainer.getDeploymentPropertyListString();
EmbeddedCacheManager container = this.registry.getCacheContainer(containerName);
Configuration configuration = container.defineConfiguration(cacheName, templateCacheName, new Configuration());
/*
for (CacheProperty cacheProperty: cacheConfig.properties())
{
String name = cacheProperty.name();
if (!name.startsWith(PREFIX))
{
log.debug(String.format("Ignoring cache property \"%s\" for bean %s", name, cacheName));
continue;
}
String property = name.substring(PREFIX.length());
String value = cacheProperty.value();
if (property.equals(MODE))
{
try
{
configuration.setCacheMode(CacheMode.valueOf(value.toUpperCase(Locale.ENGLISH)));
}
catch (IllegalArgumentException e)
{
throw new IllegalArgumentException(String.format("\"%s\" is not a valid \"%s\" for bean %s Valid modes: %s", value, name, cacheName, CacheMode.values()), e);
}
}
else if (property.equals(OWNERS))
{
try
{
configuration.setNumOwners(Integer.valueOf(value));
}
catch (NumberFormatException e)
{
throw new IllegalArgumentException(String.format("\"%s\" is not a valid \"%s\" for bean %s Integer expected.", value, name, cacheName), e);
}
}
else
{
log.info(String.format("Ignoring unrecognized cache property \"%s\" for bean %s", name, value));
}
}
*/
configuration.setEvictionMaxEntries(cacheConfig.maxSize());
if (configuration.getCacheMode().isDistributed())
{
configuration.setL1CacheEnabled(true);
configuration.setL1Lifespan(TimeUnit.SECONDS.toMillis(cacheConfig.idleTimeoutSeconds()));
}
return container.getCache(cacheName);
}