/** * Checks if the specified cache is configured in "stateless mode". * * @param cache The cache to check. * * @return {@code true} if the cache is configured in "stateless mode", * else {@code false}. */ public static boolean detectStatelessMode(final Cache cache) { final boolean isLocal = CacheMode.LOCAL.equals(cache.getCacheConfiguration().clustering().cacheMode()); final boolean isSizeOne = 1 == cache.getCacheConfiguration().eviction().size(); if (isLocal && isSizeOne) { return true; } return false; }
public MetadataManager(DefaultCacheManager cacheManager){ Configuration cacheConfiguration = cacheManager.getCacheConfiguration(Support.AVRO_METADATA_CACHE_NAME); if (cacheConfiguration == null) { ConfigurationBuilder cfg = new ConfigurationBuilder(); CacheMode cacheMode = cacheManager.getDefaultCacheConfiguration().clustering().cacheMode().equals(CacheMode.LOCAL) ? CacheMode.LOCAL : CacheMode.REPL_SYNC; cfg .transaction().lockingMode(LockingMode.PESSIMISTIC).syncCommitPhase(true).syncRollbackPhase(true) .persistence().addSingleFileStore().location(System.getProperty("java.io.tmpdir") + "/" + cacheManager.getNodeAddress()) // mandatory .locking().isolationLevel(IsolationLevel.READ_COMMITTED).useLockStriping(false) .clustering().cacheMode(cacheMode) .stateTransfer().fetchInMemoryState(true) .dataContainer().keyEquivalence(new ByteArrayEquivalence()); // for HotRod compatibility if (cacheMode.equals(CacheMode.REPL_SYNC)) cfg.clustering().stateTransfer().awaitInitialTransfer(true); cacheManager.defineConfiguration(Support.AVRO_METADATA_CACHE_NAME, cfg.build()); this.cacheManager = cacheManager; this.marshaller= Externalizer.getInstance(); this.knownSchemas = new ConcurrentHashMap<>(); knownSchemas.put(Request.getClassSchema().getFullName(), Request.getClassSchema()); knownSchemas.put(Response.getClassSchema().getFullName(), Response.getClassSchema()); } }
CacheMode cacheMode = h.applyConfigOnBuilderValue(CacheConfigurationConstants.CLUSTERING__CACHE_MODE, CacheMode.class, false); if ((cacheMode != null) && !CacheMode.LOCAL.equals(cacheMode)) { h.applyConfigOnBuilderValue(CacheConfigurationConstants.CLUSTERING__ASYNC__ASYNC_MARSHALLING, boolean.class,
protected void createCacheManagers() throws Throwable { ConfigurationBuilder c = new ConfigurationBuilder(); c.clustering().cacheMode(CacheMode.REPL_SYNC) .remoteTimeout(30000) .transaction().transactionMode(TransactionMode.TRANSACTIONAL) .invocationBatching().enable() .locking().lockAcquisitionTimeout(60000).useLockStriping(false); EmbeddedCacheManager container = TestCacheManagerFactory.createClusteredCacheManager(c); container.start(); registerCacheManager(container); container.defineConfiguration(TEST_CACHE, c.build()); container.startCaches(TEST_CACHE); Cache cache1 = container.getCache(TEST_CACHE); assert cache1.getCacheConfiguration().clustering().cacheMode().equals(CacheMode.REPL_SYNC); cache1.start(); container = TestCacheManagerFactory.createClusteredCacheManager(c); container.start(); registerCacheManager(container); container.defineConfiguration(TEST_CACHE, c.build()); container.startCaches(TEST_CACHE); Cache cache2 = container.getCache(TEST_CACHE); assert cache2.getCacheConfiguration().clustering().cacheMode().equals(CacheMode.REPL_SYNC); }