* immediately committed in the cache.
*
*/
- NON_TRANSACTIONAL;
+ NON_TRANSACTIONAL,
+ /**
+ * Set on a cache that can transfer the updates asynchronously from the
+ * calling thread. The caller when doing put/clear/remove cannot expect
+ * that the operation has happened clusterwide
+ */
+ ASYNC,
+ /**
+ * Set on a cache that transfer the updates synchronously to the calling
+ * thread so when getting back the operation is supposed to have
+ * completed on all the cluster nodes. Slow but safe.
+ */
+ SYNC;
}
/**
*
* @return true if the role is the one of standby, else false
*/
+ @Deprecated
boolean amIStandby();
/**
*
* @return Address of the active controller
*/
+ @Deprecated
InetAddress getActiveAddress();
/**
*
* @param i Interface that will be called when the Role Change happens
*/
+ @Deprecated
void listenRoleChange(IListenRoleChange i)
throws ListenRoleChangeAddException;
*
* @param i Interface that will be called when the Role Change happens
*/
+ @Deprecated
void unlistenRoleChange(IListenRoleChange i);
}
import org.infinispan.Cache;
import org.infinispan.configuration.cache.Configuration;
+import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.configuration.global.GlobalConfigurationBuilder;
import org.infinispan.configuration.parsing.ConfigurationBuilderHolder;
import org.infinispan.configuration.parsing.ParserRegistry;
throw new CacheExistException();
}
- // Sanity check to avoid contrasting parameters
- if (cMode.containsAll(EnumSet.of(
- IClusterServices.cacheMode.NON_TRANSACTIONAL,
+ // Sanity check to avoid contrasting parameters between transactional
+ // and not
+ if (cMode.containsAll(EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL,
IClusterServices.cacheMode.TRANSACTIONAL))) {
throw new CacheConfigException();
}
- if (cMode.contains(IClusterServices.cacheMode.NON_TRANSACTIONAL)) {
- c = manager.getCache(realCacheName);
- return c;
- } else if (cMode.contains(IClusterServices.cacheMode.TRANSACTIONAL)) {
- Configuration rc = manager
- .getCacheConfiguration("transactional-type");
- manager.defineConfiguration(realCacheName, rc);
- c = manager.getCache(realCacheName);
- return c;
+ // Sanity check to avoid contrasting parameters between sync and async
+ if (cMode.containsAll(EnumSet.of(IClusterServices.cacheMode.SYNC, IClusterServices.cacheMode.ASYNC))) {
+ throw new CacheConfigException();
}
- return null;
+
+ Configuration fromTemplateConfig = null;
+ /*
+ * Fetch transactional/non-transactional templates
+ */
+ // Check if transactional
+ if (cMode.contains(IClusterServices.cacheMode.TRANSACTIONAL)) {
+ fromTemplateConfig = manager.getCacheConfiguration("transactional-type");
+ } else if (cMode.contains(IClusterServices.cacheMode.NON_TRANSACTIONAL)) {
+ fromTemplateConfig = manager.getDefaultCacheConfiguration();
+ }
+
+ // If none set the transactional property then just return null
+ if (fromTemplateConfig == null) {
+ return null;
+ }
+
+ ConfigurationBuilder builder = new ConfigurationBuilder();
+ builder.read(fromTemplateConfig);
+ /*
+ * Now evaluate async/sync
+ */
+ if (cMode.contains(IClusterServices.cacheMode.ASYNC)) {
+ builder.clustering()
+ .cacheMode(fromTemplateConfig.clustering()
+ .cacheMode()
+ .toAsync());
+ } else if (cMode.contains(IClusterServices.cacheMode.SYNC)) {
+ builder.clustering()
+ .cacheMode(fromTemplateConfig.clustering()
+ .cacheMode()
+ .toSync());
+ }
+
+ manager.defineConfiguration(realCacheName, builder.build());
+ c = manager.getCache(realCacheName);
+ return c;
}
@Override
Assert.assertTrue(true);
}
- // Create second cache properly this time, as non_transactional
+ // Create second cache NON_TRANSACTIONAL but with both ASYNC and SYNC,
+ // expect to complain
cacheModeSet.remove(cacheMode.TRANSACTIONAL);
+ cacheModeSet.add(cacheMode.SYNC);
+ cacheModeSet.add(cacheMode.ASYNC);
+ try {
+ c2 = (CacheImpl<String, Integer>) cm.createCache("Container1", "Cache2", cacheModeSet);
+ } catch (CacheExistException cee) {
+ Assert.assertTrue(false);
+ } catch (CacheConfigException cce) {
+ Assert.assertTrue(true);
+ }
+
+ // Create second cache properly this time, as non_transactional and
+ // ASYNC
+ cacheModeSet.remove(cacheMode.SYNC);
try {
c2 = (CacheImpl<String, Integer>) cm.createCache("Container1",
"Cache2", cacheModeSet);
EnumSet.of(IClusterServices.cacheMode.TRANSACTIONAL));
clusterContainerService.createCache(WORKSTATUSCACHE,
- EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL, IClusterServices.cacheMode.ASYNC));
clusterContainerService.createCache(WORKORDERCACHE,
- EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
+ EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL, IClusterServices.cacheMode.ASYNC));
} catch (CacheConfigException cce) {
log.error("CacheConfigException");