@ Override public synchronized void registerInternalCache ( String name , Configuration configuration , EnumSet < Flag > flags ) { boolean configPresent = cacheManager . getCacheConfiguration ( name ) != null ; // check if it already has been defined. Currently we don't support existing user-defined configuration. if ( ( flags . contains ( Flag . EXCLUSIVE ) || ! internalCaches . containsKey ( name ) ) && configPresent ) { throw log . existingConfigForInternalCache ( name ) ; } // Don't redefine if ( configPresent ) { return ; } ConfigurationBuilder builder = new ConfigurationBuilder ( ) . read ( configuration ) ; builder . jmxStatistics ( ) . disable ( ) ; // Internal caches must not be included in stats counts GlobalConfiguration globalConfiguration = cacheManager . getCacheManagerConfiguration ( ) ; if ( flags . contains ( Flag . GLOBAL ) && globalConfiguration . isClustered ( ) ) { // TODO: choose a merge policy builder . clustering ( ) . cacheMode ( CacheMode . REPL_SYNC ) . stateTransfer ( ) . fetchInMemoryState ( true ) . awaitInitialTransfer ( true ) ; } if ( flags . contains ( Flag . PERSISTENT ) && globalConfiguration . globalState ( ) . enabled ( ) ) { builder . persistence ( ) . addSingleFileStore ( ) . location ( globalConfiguration . globalState ( ) . persistentLocation ( ) ) . purgeOnStartup ( false ) . preload ( true ) . fetchPersistentState ( true ) ; } SecurityActions . defineConfiguration ( cacheManager , name , builder . build ( ) ) ; internalCaches . put ( name , flags ) ; if ( ! flags . contains ( Flag . USER ) ) { privateCaches . add ( name ) ; } }
Synchronized to prevent users from registering the same configuration at the same time