#ignite-239: small refactoring.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/535aaf46 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/535aaf46 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/535aaf46 Branch: refs/heads/ignite-237 Commit: 535aaf464fde5e035b594297a57ab3de06257d1f Parents: 7aec19e Author: ivasilinets <ivasilin...@gridgain.com> Authored: Thu Feb 26 17:53:00 2015 +0300 Committer: ivasilinets <ivasilin...@gridgain.com> Committed: Thu Feb 26 17:53:00 2015 +0300 ---------------------------------------------------------------------- .../configuration/IgniteConfiguration.java | 163 +------ .../org/apache/ignite/internal/IgnitionEx.java | 477 ++++++++++++------- 2 files changed, 328 insertions(+), 312 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/535aaf46/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java index 037b7c8..bd24c4b 100644 --- a/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java +++ b/modules/core/src/main/java/org/apache/ignite/configuration/IgniteConfiguration.java @@ -26,19 +26,7 @@ import org.apache.ignite.lang.*; import org.apache.ignite.lifecycle.*; import org.apache.ignite.marshaller.*; import org.apache.ignite.plugin.*; -import org.apache.ignite.spi.checkpoint.noop.*; -import org.apache.ignite.spi.collision.noop.*; -import org.apache.ignite.spi.communication.tcp.*; -import org.apache.ignite.spi.deployment.local.*; -import org.apache.ignite.spi.discovery.tcp.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.*; -import org.apache.ignite.spi.eventstorage.memory.*; -import org.apache.ignite.spi.failover.always.*; import org.apache.ignite.spi.indexing.*; -import org.apache.ignite.spi.indexing.noop.*; -import org.apache.ignite.spi.loadbalancing.roundrobin.*; -import org.apache.ignite.spi.swapspace.file.*; -import org.apache.ignite.spi.swapspace.noop.*; import org.apache.ignite.streamer.*; import org.apache.ignite.plugin.segmentation.*; import org.apache.ignite.services.*; @@ -383,9 +371,6 @@ public class IgniteConfiguration { /** User's class loader. */ private ClassLoader classLdr; - /** */ - private static final String[] EMPTY_STR_ARR = new String[0]; - /** * Creates valid grid configuration with all default values. */ @@ -403,189 +388,75 @@ public class IgniteConfiguration { assert cfg != null; // SPIs. - discoSpi = cfg.getDiscoverySpi() != null ? cfg.getDiscoverySpi() : new TcpDiscoverySpi(); - - if (discoSpi instanceof TcpDiscoverySpi) { - TcpDiscoverySpi tcpDisco = (TcpDiscoverySpi)discoSpi; - - if (tcpDisco.getIpFinder() == null) - tcpDisco.setIpFinder(new TcpDiscoveryMulticastIpFinder()); - } - - commSpi = cfg.getCommunicationSpi() != null ? cfg.getCommunicationSpi() : new TcpCommunicationSpi(); - - deploySpi = cfg.getDeploymentSpi() != null ? cfg.getDeploymentSpi() : new LocalDeploymentSpi(); - - evtSpi = cfg.getEventStorageSpi() != null ? cfg.getEventStorageSpi() : new MemoryEventStorageSpi(); - - cpSpi = cfg.getCheckpointSpi() != null ? cfg.getCheckpointSpi() : new CheckpointSpi[] {new NoopCheckpointSpi()}; - - colSpi = cfg.getCollisionSpi() != null ? cfg.getCollisionSpi() : new NoopCollisionSpi(); - - failSpi = cfg.getFailoverSpi() != null ? cfg.getFailoverSpi() : new FailoverSpi[] {new AlwaysFailoverSpi()}; - - loadBalancingSpi = cfg.getLoadBalancingSpi() != null ? cfg.getLoadBalancingSpi() : - new LoadBalancingSpi[] {new RoundRobinLoadBalancingSpi()}; - - indexingSpi = cfg.getIndexingSpi() != null ? cfg.getIndexingSpi() : new NoopIndexingSpi(); - + discoSpi = cfg.getDiscoverySpi(); + commSpi = cfg.getCommunicationSpi(); + deploySpi = cfg.getDeploymentSpi(); + evtSpi = cfg.getEventStorageSpi(); + cpSpi = cfg.getCheckpointSpi(); + colSpi = cfg.getCollisionSpi(); + failSpi = cfg.getFailoverSpi(); + loadBalancingSpi = cfg.getLoadBalancingSpi(); + indexingSpi = cfg.getIndexingSpi(); swapSpaceSpi = cfg.getSwapSpaceSpi(); - if (swapSpaceSpi == null) { - boolean needSwap = false; - - CacheConfiguration[] caches = cfg.getCacheConfiguration(); - - if (caches != null) { - for (CacheConfiguration c : caches) { - if (c.isSwapEnabled()) { - needSwap = true; - - break; - } - } - } - - swapSpaceSpi = needSwap ? new FileSwapSpaceSpi() : new NoopSwapSpaceSpi(); - } - /* * Order alphabetically for maintenance purposes. */ addrRslvr = cfg.getAddressResolver(); - allResolversPassReq = cfg.isAllSegmentationResolversPassRequired(); - atomicCfg = cfg.getAtomicConfiguration(); - daemon = cfg.isDaemon(); - cacheCfg = cfg.getCacheConfiguration(); - cacheSanityCheckEnabled = cfg.isCacheSanityCheckEnabled(); - - connectorCfg = cfg.getConnectorConfiguration() != null ? - new ConnectorConfiguration(cfg.getConnectorConfiguration()) : null; - + connectorCfg = cfg.getConnectorConfiguration(); classLdr = cfg.getClassLoader(); - clockSyncFreq = cfg.getClockSyncFrequency(); - clockSyncSamples = cfg.getClockSyncSamples(); - deployMode = cfg.getDeploymentMode(); - discoStartupDelay = cfg.getDiscoveryStartupDelay(); - pubPoolSize = cfg.getPublicThreadPoolSize(); - ggHome = cfg.getIgniteHome(); - ggWork = cfg.getWorkDirectory(); - gridName = cfg.getGridName(); - - IgfsConfiguration[] igfsCfgs = cfg.getIgfsConfiguration(); - - if (igfsCfgs != null) { - IgfsConfiguration[] clone = igfsCfgs.clone(); - - for (int i = 0; i < igfsCfgs.length; i++) - clone[i] = new IgfsConfiguration(igfsCfgs[i]); - - igfsCfg = clone; - } - + igfsCfg = cfg.getIgfsConfiguration(); igfsPoolSize = cfg.getIgfsThreadPoolSize(); - hadoopCfg = cfg.getHadoopConfiguration(); - inclEvtTypes = cfg.getIncludeEventTypes(); - includeProps = cfg.getIncludeProperties(); - lifecycleBeans = cfg.getLifecycleBeans(); - locHost = cfg.getLocalHost(); - log = cfg.getGridLogger(); - lsnrs = cfg.getLocalEventListeners(); - marsh = cfg.getMarshaller(); - marshLocJobs = cfg.isMarshalLocalJobs(); - - mbeanSrv = cfg.getMBeanServer() != null ? cfg.getMBeanServer() : ManagementFactory.getPlatformMBeanServer(); - + mbeanSrv = cfg.getMBeanServer(); metricsHistSize = cfg.getMetricsHistorySize(); - metricsExpTime = cfg.getMetricsExpireTime(); - metricsLogFreq = cfg.getMetricsLogFrequency(); - metricsUpdateFreq = cfg.getMetricsUpdateFrequency(); - mgmtPoolSize = cfg.getManagementThreadPoolSize(); - netTimeout = cfg.getNetworkTimeout(); - - nodeId = cfg.getNodeId() != null ? cfg.getNodeId() : UUID.randomUUID(); - + nodeId = cfg.getNodeId(); p2pEnabled = cfg.isPeerClassLoadingEnabled(); - - p2pLocClsPathExcl = cfg.getPeerClassLoadingLocalClassPathExclude() != null ? - cfg.getPeerClassLoadingLocalClassPathExclude() : EMPTY_STR_ARR; - + p2pLocClsPathExcl = cfg.getPeerClassLoadingLocalClassPathExclude(); p2pMissedCacheSize = cfg.getPeerClassLoadingMissedResourcesCacheSize(); - p2pPoolSize = cfg.getPeerClassLoadingThreadPoolSize(); - pluginCfgs = cfg.getPluginConfigurations(); - qryCfg = cfg.getQueryConfiguration(); - segChkFreq = cfg.getSegmentCheckFrequency(); - segPlc = cfg.getSegmentationPolicy(); - segResolveAttempts = cfg.getSegmentationResolveAttempts(); - segResolvers = cfg.getSegmentationResolvers(); - sndRetryCnt = cfg.getNetworkSendRetryCount(); - sndRetryDelay = cfg.getNetworkSendRetryDelay(); - - StreamerConfiguration[] streamerCfgs = cfg.getStreamerConfiguration(); - - if (streamerCfgs != null) { - StreamerConfiguration[] clone = streamerCfgs.clone(); - - for (int i = 0; i < streamerCfgs.length; i++) - clone[i] = new StreamerConfiguration(streamerCfgs[i]); - - streamerCfg = clone; - } - + streamerCfg = cfg.getStreamerConfiguration(); svcCfgs = cfg.getServiceConfiguration(); - sysPoolSize = cfg.getSystemThreadPoolSize(); - timeSrvPortBase = cfg.getTimeServerPortBase(); - timeSrvPortRange = cfg.getTimeServerPortRange(); - - txCfg = cfg.getTransactionConfiguration() != null ? - new TransactionConfiguration(cfg.getTransactionConfiguration()) : null; - - if (cfg.getUserAttributes() == null) - userAttrs = Collections.emptyMap(); - else - userAttrs = cfg.getUserAttributes(); - + txCfg = cfg.getTransactionConfiguration(); + userAttrs = cfg.getUserAttributes(); waitForSegOnStart = cfg.isWaitForSegmentOnStart(); - warmupClos = cfg.getWarmupClosure(); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/535aaf46/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java index 01c0cec..f70836c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java @@ -34,13 +34,29 @@ import org.apache.ignite.marshaller.optimized.*; import org.apache.ignite.mxbean.*; import org.apache.ignite.plugin.segmentation.*; import org.apache.ignite.spi.*; +import org.apache.ignite.spi.checkpoint.*; +import org.apache.ignite.spi.checkpoint.noop.*; +import org.apache.ignite.spi.collision.noop.*; +import org.apache.ignite.spi.communication.tcp.*; +import org.apache.ignite.spi.deployment.local.*; import org.apache.ignite.spi.discovery.tcp.*; +import org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.*; +import org.apache.ignite.spi.eventstorage.memory.*; +import org.apache.ignite.spi.failover.*; +import org.apache.ignite.spi.failover.always.*; +import org.apache.ignite.spi.indexing.noop.*; +import org.apache.ignite.spi.loadbalancing.*; +import org.apache.ignite.spi.loadbalancing.roundrobin.*; +import org.apache.ignite.spi.swapspace.file.*; +import org.apache.ignite.spi.swapspace.noop.*; +import org.apache.ignite.streamer.*; import org.apache.ignite.thread.*; import org.jdk8.backport.*; import org.jetbrains.annotations.*; import javax.management.*; import java.io.*; +import java.lang.management.*; import java.lang.reflect.*; import java.net.*; import java.util.*; @@ -103,6 +119,9 @@ public class IgnitionEx { /** */ private static volatile boolean daemon; + /** */ + private static final String[] EMPTY_STR_ARR = new String[0]; + /** * Checks runtime version to be 1.7.x or 1.8.x. * This will load pretty much first so we must do these checks here. @@ -1278,17 +1297,6 @@ public class IgnitionEx { IgniteConfiguration cfg = startCtx.config() != null ? startCtx.config() : new IgniteConfiguration(); - String ggHome = cfg.getIgniteHome(); - - // Set Ignite home. - if (ggHome == null) - ggHome = U.getIgniteHome(); - else - // If user provided IGNITE_HOME - set it as a system property. - U.setIgniteHome(ggHome); - - U.setWorkDirectory(cfg.getWorkDirectory(), ggHome); - // Ensure invariant. // It's a bit dirty - but this is a result of late refactoring // and I don't want to reshuffle a lot of code. @@ -1298,60 +1306,18 @@ public class IgnitionEx { if (startCtx.configUrl() != null) System.setProperty(IGNITE_CONFIG_URL, startCtx.configUrl().toString()); - IgniteConfiguration myCfg = new IgniteConfiguration(cfg); - - IgniteLogger cfgLog = initLogger(cfg.getGridLogger(), myCfg.getNodeId()); + // Initialize factory's log. + IgniteLogger cfgLog = initLogger(cfg.getGridLogger(), cfg.getNodeId()); assert cfgLog != null; - cfgLog = new GridLoggerProxy(cfgLog, null, name, U.id8(myCfg.getNodeId())); + cfgLog = new GridLoggerProxy(cfgLog, null, name, U.id8(cfg.getNodeId())); - // Initialize factory's log. log = cfgLog.getLogger(G.class); - myCfg.setGridLogger(cfgLog); - - // Check Ignite home folder (after log is available). - if (ggHome != null) { - File ggHomeFile = new File(ggHome); - - if (!ggHomeFile.exists() || !ggHomeFile.isDirectory()) - throw new IgniteCheckedException("Invalid Ignite installation home folder: " + ggHome); - } - - myCfg.setIgniteHome(ggHome); - - // Local host. - String locHost = IgniteSystemProperties.getString(IGNITE_LOCAL_HOST); - - myCfg.setLocalHost(F.isEmpty(locHost) ? cfg.getLocalHost() : locHost); - - // Override daemon flag if it was set on the factory. - if (daemon) - myCfg.setDaemon(true); - - // Check for deployment mode override. - String depModeName = IgniteSystemProperties.getString(IGNITE_DEP_MODE_OVERRIDE); - - if (!F.isEmpty(depModeName)) { - if (!F.isEmpty(cfg.getCacheConfiguration())) { - U.quietAndInfo(log, "Skipping deployment mode override for caches (custom closure " + - "execution may not work for console Visor)"); - } - else { - try { - DeploymentMode depMode = DeploymentMode.valueOf(depModeName); + IgniteConfiguration myCfg = initializeDefaultConfiguration(cfg); - if (myCfg.getDeploymentMode() != depMode) - myCfg.setDeploymentMode(depMode); - } - catch (IllegalArgumentException e) { - throw new IgniteCheckedException("Failed to override deployment mode using system property " + - "(are there any misspellings?)" + - "[name=" + IGNITE_DEP_MODE_OVERRIDE + ", value=" + depModeName + ']', e); - } - } - } + myCfg.setGridLogger(cfgLog); if (myCfg.getConnectorConfiguration() != null) { restExecSvc = new IgniteThreadPoolExecutor( @@ -1363,38 +1329,6 @@ public class IgnitionEx { ); } - Marshaller marsh = cfg.getMarshaller(); - - if (marsh == null) { - if (!U.isHotSpot()) { - U.warn(log, "GridOptimizedMarshaller is not supported on this JVM " + - "(only Java HotSpot VMs are supported). Switching to standard JDK marshalling - " + - "object serialization performance will be significantly slower.", - "To enable fast marshalling upgrade to recent 1.6 or 1.7 HotSpot VM release."); - - marsh = new JdkMarshaller(); - } - else if (!OptimizedMarshaller.available()) { - U.warn(log, "GridOptimizedMarshaller is not supported on this JVM " + - "(only recent 1.6 and 1.7 versions HotSpot VMs are supported). " + - "To enable fast marshalling upgrade to recent 1.6 or 1.7 HotSpot VM release. " + - "Switching to standard JDK marshalling - " + - "object serialization performance will be significantly slower.", - "To enable fast marshalling upgrade to recent 1.6 or 1.7 HotSpot VM release."); - - marsh = new JdkMarshaller(); - } - else - marsh = new OptimizedMarshaller(); - } - else if (marsh instanceof OptimizedMarshaller && !U.isHotSpot()) { - U.warn(log, "Using GridOptimizedMarshaller on untested JVM (only Java HotSpot VMs were tested) - " + - "object serialization behavior could yield unexpected results.", - "Using GridOptimizedMarshaller on untested JVM."); - } - - myCfg.setMarshaller(marsh); - // Validate segmentation configuration. GridSegmentationPolicy segPlc = cfg.getSegmentationPolicy(); @@ -1418,82 +1352,6 @@ public class IgnitionEx { ensureMultiInstanceSupport(myCfg.getSwapSpaceSpi()); } - CacheConfiguration[] cacheCfgs = cfg.getCacheConfiguration(); - - final boolean hasHadoop = IgniteComponentType.HADOOP.inClassPath(); - - final boolean hasAtomics = cfg.getAtomicConfiguration() != null; - - final boolean clientDisco = myCfg.getDiscoverySpi() instanceof TcpClientDiscoverySpi; - - CacheConfiguration[] copies; - - if (cacheCfgs != null && cacheCfgs.length > 0) { - if (!U.discoOrdered(myCfg.getDiscoverySpi()) && !U.relaxDiscoveryOrdered()) - throw new IgniteCheckedException("Discovery SPI implementation does not support node ordering and " + - "cannot be used with cache (use SPI with @GridDiscoverySpiOrderSupport annotation, " + - "like GridTcpDiscoverySpi)"); - - for (CacheConfiguration ccfg : cacheCfgs) { - if (CU.isHadoopSystemCache(ccfg.getName())) - throw new IgniteCheckedException("Cache name cannot be \"" + CU.SYS_CACHE_HADOOP_MR + - "\" because it is reserved for internal purposes."); - - if (CU.isAtomicsCache(ccfg.getName())) - throw new IgniteCheckedException("Cache name cannot be \"" + CU.ATOMICS_CACHE_NAME + - "\" because it is reserved for internal purposes."); - - if (CU.isUtilityCache(ccfg.getName())) - throw new IgniteCheckedException("Cache name cannot start with \"" + CU.UTILITY_CACHE_NAME + - "\" because this prefix is reserved for internal purposes."); - } - - int addCacheCnt = 1; // Always add utility cache. - - if (hasHadoop) - addCacheCnt++; - - if (hasAtomics) - addCacheCnt++; - - copies = new CacheConfiguration[cacheCfgs.length + addCacheCnt]; - - int cloneIdx = 1; - - if (hasHadoop) - copies[cloneIdx++] = CU.hadoopSystemCache(); - - if (hasAtomics) - copies[cloneIdx++] = atomicsSystemCache(cfg.getAtomicConfiguration(), clientDisco); - - for (CacheConfiguration ccfg : cacheCfgs) - copies[cloneIdx++] = new CacheConfiguration(ccfg); - } - else { - int cacheCnt = 1; // Always add utility cache. - - if (hasHadoop) - cacheCnt++; - - if (hasAtomics) - cacheCnt++; - - copies = new CacheConfiguration[cacheCnt]; - - int cacheIdx = 1; - - if (hasHadoop) - copies[cacheIdx++] = CU.hadoopSystemCache(); - - if (hasAtomics) - copies[cacheIdx] = atomicsSystemCache(cfg.getAtomicConfiguration(), clientDisco); - } - - // Always add utility cache. - copies[0] = utilitySystemCache(clientDisco); - - myCfg.setCacheConfiguration(copies); - try { // Use reflection to avoid loading undesired classes. Class helperCls = Class.forName("org.apache.ignite.util.GridConfigurationHelper"); @@ -1636,6 +1494,293 @@ public class IgnitionEx { } /** + * @param cfg Ignite configuration copy to. + * @return New ignite configuration. + */ + private IgniteConfiguration initializeDefaultConfiguration(IgniteConfiguration cfg) + throws IgniteCheckedException { + IgniteConfiguration myCfg = new IgniteConfiguration(cfg); + initializeDefaultConfigurationParameters(myCfg); + return myCfg; + } + + /** + * Initialize default parameters. + */ + public void initializeDefaultConfigurationParameters(IgniteConfiguration cfg) throws IgniteCheckedException { + // Set Ignite home. + String ggHome = cfg.getIgniteHome(); + + if (ggHome == null) + ggHome = U.getIgniteHome(); + else + // If user provided IGNITE_HOME - set it as a system property. + U.setIgniteHome(ggHome); + + U.setWorkDirectory(cfg.getWorkDirectory(), ggHome); + + // Check Ignite home folder (after log is available). + if (ggHome != null) { + File ggHomeFile = new File(ggHome); + + if (!ggHomeFile.exists() || !ggHomeFile.isDirectory()) + throw new IgniteCheckedException("Invalid Ignite installation home folder: " + ggHome); + } + + cfg.setIgniteHome(ggHome); + + // Local host. + String locHost = IgniteSystemProperties.getString(IGNITE_LOCAL_HOST); + + cfg.setLocalHost(F.isEmpty(locHost) ? cfg.getLocalHost() : locHost); + + // Override daemon flag if it was set on the factory. + if (daemon) + cfg.setDaemon(true); + + Marshaller marsh = cfg.getMarshaller(); + + if (marsh == null) { + if (!U.isHotSpot()) { + U.warn(log, "GridOptimizedMarshaller is not supported on this JVM " + + "(only Java HotSpot VMs are supported). Switching to standard JDK marshalling - " + + "object serialization performance will be significantly slower.", + "To enable fast marshalling upgrade to recent 1.6 or 1.7 HotSpot VM release."); + + marsh = new JdkMarshaller(); + } + else if (!OptimizedMarshaller.available()) { + U.warn(log, "GridOptimizedMarshaller is not supported on this JVM " + + "(only recent 1.6 and 1.7 versions HotSpot VMs are supported). " + + "To enable fast marshalling upgrade to recent 1.6 or 1.7 HotSpot VM release. " + + "Switching to standard JDK marshalling - " + + "object serialization performance will be significantly slower.", + "To enable fast marshalling upgrade to recent 1.6 or 1.7 HotSpot VM release."); + + marsh = new JdkMarshaller(); + } + else + marsh = new OptimizedMarshaller(); + } + else if (marsh instanceof OptimizedMarshaller && !U.isHotSpot()) { + U.warn(log, "Using GridOptimizedMarshaller on untested JVM (only Java HotSpot VMs were tested) - " + + "object serialization behavior could yield unexpected results.", + "Using GridOptimizedMarshaller on untested JVM."); + } + + // Check for deployment mode override. + String depModeName = IgniteSystemProperties.getString(IGNITE_DEP_MODE_OVERRIDE); + + if (!F.isEmpty(depModeName)) { + if (!F.isEmpty(cfg.getCacheConfiguration())) { + U.quietAndInfo(log, "Skipping deployment mode override for caches (custom closure " + + "execution may not work for console Visor)"); + } + else { + try { + DeploymentMode depMode = DeploymentMode.valueOf(depModeName); + + if (cfg.getDeploymentMode() != depMode) + cfg.setDeploymentMode(depMode); + } + catch (IllegalArgumentException e) { + throw new IgniteCheckedException("Failed to override deployment mode using system property " + + "(are there any misspellings?)" + + "[name=" + IGNITE_DEP_MODE_OVERRIDE + ", value=" + depModeName + ']', e); + } + } + } + + cfg.setMarshaller(marsh); + + cfg.setConnectorConfiguration(cfg.getConnectorConfiguration() != null ? + new ConnectorConfiguration(cfg.getConnectorConfiguration()) : null); + + IgfsConfiguration[] igfsCfgs = cfg.getIgfsConfiguration(); + + if (igfsCfgs != null) { + IgfsConfiguration[] clone = igfsCfgs.clone(); + + for (int i = 0; i < igfsCfgs.length; i++) + clone[i] = new IgfsConfiguration(igfsCfgs[i]); + + cfg.setIgfsConfiguration(clone); + } + + if (cfg.getMBeanServer() == null) + cfg.setMBeanServer(ManagementFactory.getPlatformMBeanServer()); + + if (cfg.getNodeId() == null) + cfg.setNodeId(UUID.randomUUID()); + + if (cfg.getPeerClassLoadingLocalClassPathExclude() == null) + cfg.setPeerClassLoadingLocalClassPathExclude(EMPTY_STR_ARR); + + StreamerConfiguration[] streamerCfgs = cfg.getStreamerConfiguration(); + + if (streamerCfgs != null) { + StreamerConfiguration[] clone = streamerCfgs.clone(); + + for (int i = 0; i < streamerCfgs.length; i++) + clone[i] = new StreamerConfiguration(streamerCfgs[i]); + + cfg.setStreamerConfiguration(clone); + } + + cfg.setTransactionConfiguration(cfg.getTransactionConfiguration() != null ? + new TransactionConfiguration(cfg.getTransactionConfiguration()) : null); + + if (cfg.getUserAttributes() == null) { + Map<String, ?> emptyAttr = Collections.emptyMap(); + cfg.setUserAttributes(emptyAttr); + } + + initializeDefaultCacheConfiguration(cfg); + + initializeDefaultSpi(cfg); + } + + /** + * Initialize default cache configuration. + * + * @param cfg Ignite configuration. + */ + public void initializeDefaultCacheConfiguration(IgniteConfiguration cfg) throws IgniteCheckedException { + CacheConfiguration[] cacheCfgs = cfg.getCacheConfiguration(); + + final boolean hasHadoop = IgniteComponentType.HADOOP.inClassPath(); + + final boolean hasAtomics = cfg.getAtomicConfiguration() != null; + + final boolean clientDisco = cfg.getDiscoverySpi() instanceof TcpClientDiscoverySpi; + + CacheConfiguration[] copies; + + if (cacheCfgs != null && cacheCfgs.length > 0) { + if (!U.discoOrdered(cfg.getDiscoverySpi()) && !U.relaxDiscoveryOrdered()) + throw new IgniteCheckedException("Discovery SPI implementation does not support node ordering and " + + "cannot be used with cache (use SPI with @GridDiscoverySpiOrderSupport annotation, " + + "like GridTcpDiscoverySpi)"); + + for (CacheConfiguration ccfg : cacheCfgs) { + if (CU.isHadoopSystemCache(ccfg.getName())) + throw new IgniteCheckedException("Cache name cannot be \"" + CU.SYS_CACHE_HADOOP_MR + + "\" because it is reserved for internal purposes."); + + if (CU.isAtomicsCache(ccfg.getName())) + throw new IgniteCheckedException("Cache name cannot be \"" + CU.ATOMICS_CACHE_NAME + + "\" because it is reserved for internal purposes."); + + if (CU.isUtilityCache(ccfg.getName())) + throw new IgniteCheckedException("Cache name cannot start with \"" + CU.UTILITY_CACHE_NAME + + "\" because this prefix is reserved for internal purposes."); + } + + int addCacheCnt = 1; // Always add utility cache. + + if (hasHadoop) + addCacheCnt++; + + if (hasAtomics) + addCacheCnt++; + + copies = new CacheConfiguration[cacheCfgs.length + addCacheCnt]; + + int cloneIdx = 1; + + if (hasHadoop) + copies[cloneIdx++] = CU.hadoopSystemCache(); + + if (hasAtomics) + copies[cloneIdx++] = atomicsSystemCache(cfg.getAtomicConfiguration(), clientDisco); + + for (CacheConfiguration ccfg : cacheCfgs) + copies[cloneIdx++] = new CacheConfiguration(ccfg); + } + else { + int cacheCnt = 1; // Always add utility cache. + + if (hasHadoop) + cacheCnt++; + + if (hasAtomics) + cacheCnt++; + + copies = new CacheConfiguration[cacheCnt]; + + int cacheIdx = 1; + + if (hasHadoop) + copies[cacheIdx++] = CU.hadoopSystemCache(); + + if (hasAtomics) + copies[cacheIdx] = atomicsSystemCache(cfg.getAtomicConfiguration(), clientDisco); + } + + // Always add utility cache. + copies[0] = utilitySystemCache(clientDisco); + + cfg.setCacheConfiguration(copies); + } + + /** + * Initialize default values for spi. + * + * @param cfg Ignite configuration. + */ + private void initializeDefaultSpi(IgniteConfiguration cfg) { + if (cfg.getDiscoverySpi() == null) + cfg.setDiscoverySpi(new TcpDiscoverySpi()); + + if (cfg.getDiscoverySpi() instanceof TcpDiscoverySpi) { + TcpDiscoverySpi tcpDisco = (TcpDiscoverySpi)cfg.getDiscoverySpi(); + + if (tcpDisco.getIpFinder() == null) + tcpDisco.setIpFinder(new TcpDiscoveryMulticastIpFinder()); + } + + if (cfg.getCommunicationSpi() == null) + cfg.setCommunicationSpi(new TcpCommunicationSpi()); + + if (cfg.getDeploymentSpi() == null) + cfg.setDeploymentSpi(new LocalDeploymentSpi()); + + if (cfg.getEventStorageSpi() == null) + cfg.setEventStorageSpi(new MemoryEventStorageSpi()); + + if (cfg.getCheckpointSpi() == null) + cfg.setCheckpointSpi(new CheckpointSpi[] {new NoopCheckpointSpi()}); + + if (cfg.getCollisionSpi() == null) + cfg.setCollisionSpi(new NoopCollisionSpi()); + + if (cfg.getFailoverSpi() == null) + cfg.setFailoverSpi(new FailoverSpi[] {new AlwaysFailoverSpi()}); + + if (cfg.getLoadBalancingSpi() == null) + cfg.setLoadBalancingSpi(new LoadBalancingSpi[] {new RoundRobinLoadBalancingSpi()}); + + if (cfg.getIndexingSpi() == null) + cfg.setIndexingSpi(new NoopIndexingSpi()); + + if (cfg.getSwapSpaceSpi() == null) { + boolean needSwap = false; + + if (cfg.getCacheConfiguration() != null) { + for (CacheConfiguration c : cfg.getCacheConfiguration()) { + if (c.isSwapEnabled()) { + needSwap = true; + + break; + } + } + } + + cfg.setSwapSpaceSpi(needSwap ? new FileSwapSpaceSpi() : new NoopSwapSpaceSpi()); + } + } + + /** * @param cfgLog Configured logger. * @param nodeId Local node ID. * @return Initialized logger.