You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by se...@apache.org on 2015/06/23 16:15:56 UTC
[2/2] incubator-ignite git commit: # IGNITE-843 Implement cache
configuration generator for java
# IGNITE-843 Implement cache configuration generator for java
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/b3abf11d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/b3abf11d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/b3abf11d
Branch: refs/heads/ignite-843
Commit: b3abf11da810b68e1049dc1d6760eea35161f710
Parents: efeabe9
Author: sevdokimov <se...@jetbrains.com>
Authored: Tue Jun 23 17:15:43 2015 +0300
Committer: sevdokimov <se...@jetbrains.com>
Committed: Tue Jun 23 17:15:43 2015 +0300
----------------------------------------------------------------------
modules/webconfig/nodejs/utils/generatorJava.js | 151 ++++++++++++++++++-
modules/webconfig/nodejs/utils/generatorXml.js | 9 ++
2 files changed, 158 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b3abf11d/modules/webconfig/nodejs/utils/generatorJava.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/utils/generatorJava.js b/modules/webconfig/nodejs/utils/generatorJava.js
index a9af1b5..7cf66ef 100644
--- a/modules/webconfig/nodejs/utils/generatorJava.js
+++ b/modules/webconfig/nodejs/utils/generatorJava.js
@@ -202,6 +202,150 @@ exports.generateClusterConfiguration = function(cluster) {
return res.join('');
};
+var evictionPolicies = {
+ 'LRU': {shortClassName: 'LruEvictionPolicy', fields: {batchSize: null, maxMemorySize: null}},
+ 'RND': {shortClassName: 'RandomEvictionPolicy', fields: {batchSize: null}},
+ 'FIFO': {shortClassName: 'FifoEvictionPolicy', fields: {batchSize: null}},
+ 'SORTED': {shortClassName: 'SortedEvictionPolicy', fields: {batchSize: null}}
+};
+
+exports.generateCacheConfiguration = function(cacheCfg, varName, res) {
+ if (!res)
+ res = generatorUtils.builder();
+
+ res.line('CacheConfiguration ' + varName + ' = new CacheConfiguration();');
+
+ res.needEmptyLine = true;
+
+ if (cacheCfg.mode) {
+ res.emptyLineIfNeeded();
+
+ res.line(varName + '.setCacheMode(CacheMode.' + cacheCfg.mode + ');');
+ }
+
+ addProperty(res, cacheCfg, varName, 'atomicityMode', 'CacheAtomicityMode');
+ addProperty(res, cacheCfg, varName, 'backups');
+
+ res.needEmptyLine = true;
+
+ addProperty(res, cacheCfg, varName, 'memoryMode', 'CacheMemoryMode');
+ addProperty(res, cacheCfg, varName, 'offHeapMaxMemory');
+ addProperty(res, cacheCfg, varName, 'swapEnabled');
+
+ res.needEmptyLine = true;
+
+ if (cacheCfg.evictionPolicy) {
+ var e = evictionPolicies[cacheCfg.evictionPolicy.kind];
+
+ addBeanWithProperties(res, cacheCfg.evictionPolicy[cacheCfg.evictionPolicy.kind.toUpperCase()], varName,
+ 'evictionPolicy', 'evictionPolicy', e.shortClassName, e.fields, true);
+ }
+
+ res.needEmptyLine = true;
+
+ addBeanWithProperties(res, cacheCfg.nearConfiguration, varName, 'nearConfiguration', 'nearConfiguration',
+ 'NearCacheConfiguration', {nearStartSize: null, atomicSequenceReserveSize: null}, true);
+
+ if (cacheCfg.nearConfiguration && cacheCfg.nearConfiguration.nearEvictionPolicy) {
+ res.line('nearConfiguration.setNearEvictionPolicy(new '
+ + evictionPolicies[cacheCfg.nearConfiguration.nearEvictionPolicy].shortClassName + '());');
+ }
+
+ res.needEmptyLine = true;
+
+ addProperty(res, cacheCfg, varName, 'sqlEscapeAll');
+ addProperty(res, cacheCfg, varName, 'sqlOnheapRowCacheSize');
+ addProperty(res, cacheCfg, varName, 'longQueryWarningTimeout');
+
+ if (cacheCfg.indexedTypes && cacheCfg.indexedTypes.length > 0) {
+ res.emptyLineIfNeeded();
+
+ res.append(varName + '.setIndexedTypes(');
+
+ for (var i = 0; i < cacheCfg.indexedTypes.length; i++) {
+ if (i > 0)
+ res.append(', ');
+
+ var pair = cacheCfg.indexedTypes[i];
+
+ res.append(toJavaCode(pair.keyClass, 'class')).append(', ').append(toJavaCode(pair.valueClass, 'class'))
+ }
+
+ res.line(');');
+ }
+
+ addMultiparamProperty(res, cacheCfg, varName, 'sqlFunctionClasses', 'class');
+
+ res.needEmptyLine = true;
+
+ addProperty(res, cacheCfg, varName, 'rebalanceMode', 'CacheRebalanceMode');
+ addProperty(res, cacheCfg, varName, 'rebalanceThreadPoolSize');
+ addProperty(res, cacheCfg, varName, 'rebalanceBatchSize');
+ addProperty(res, cacheCfg, varName, 'rebalanceOrder');
+ addProperty(res, cacheCfg, varName, 'rebalanceDelay');
+ addProperty(res, cacheCfg, varName, 'rebalanceTimeout');
+ addProperty(res, cacheCfg, varName, 'rebalanceThrottle');
+
+ res.needEmptyLine = true;
+
+ if (cacheCfg.store) {
+ switch (cacheCfg.store.kind) {
+ case 'CacheJdbcPojoStoreFactory':
+ addBeanWithProperties(res, cacheCfg.store[cacheCfg.store.kind], varName, 'cacheStoreFactory',
+ 'cacheStoreFactory', 'CacheJdbcPojoStoreFactory', {
+ dataSourceBean: null,
+ dialect: null
+ }, true);
+
+ break;
+
+ case 'CacheJdbcBlobStoreFactory':
+ addBeanWithProperties(res, cacheCfg.store[cacheCfg.store.kind], varName, 'cacheStoreFactory',
+ 'cacheStoreFactory', 'CacheJdbcBlobStoreFactory', {
+ multicastGroup: null,
+ multicastPort: null,
+ responseWaitTime: null,
+ addressRequestAttempts: null,
+ localAddress: null
+ }, true);
+
+ break;
+
+ case 'CacheHibernateBlobStoreFactory':
+ addBeanWithProperties(res, cacheCfg.store[cacheCfg.store.kind], varName, 'cacheStoreFactory',
+ 'cacheStoreFactory', 'CacheHibernateBlobStoreFactory', {
+ hibernateProperties: 'list'
+ }, true);
+
+ break;
+ }
+ }
+
+ res.needEmptyLine = true;
+
+ addProperty(res, cacheCfg, varName, 'invalidate');
+ addProperty(res, cacheCfg, varName, 'defaultLockTimeout');
+ addProperty(res, cacheCfg, varName, 'transactionManagerLookupClassName');
+
+ res.needEmptyLine = true;
+
+ addProperty(res, cacheCfg, varName, 'writeBehindEnabled');
+ addProperty(res, cacheCfg, varName, 'writeBehindBatchSize');
+ addProperty(res, cacheCfg, varName, 'writeBehindFlushSize');
+ addProperty(res, cacheCfg, varName, 'writeBehindFlushFrequency');
+ addProperty(res, cacheCfg, varName, 'writeBehindFlushThreadCount');
+
+ res.needEmptyLine = true;
+
+ addProperty(res, cacheCfg, varName, 'statisticsEnabled');
+ addProperty(res, cacheCfg, varName, 'managementEnabled');
+ addProperty(res, cacheCfg, varName, 'readFromBackup');
+ addProperty(res, cacheCfg, varName, 'copyOnRead');
+ addProperty(res, cacheCfg, varName, 'maxConcurrentAsyncOperations');
+
+ return res;
+};
+
function toJavaCode(val, type) {
if (val == null)
return 'null';
@@ -209,6 +353,9 @@ function toJavaCode(val, type) {
if (type == 'f')
return val + 'f';
+ if (type == 'class')
+ return val + '.class';
+
if (type)
return type + '.' + val;
@@ -254,7 +401,7 @@ function addListProperty(res, obj, objVariableName, propName, enumType) {
}
}
-function addMultiparamProperty(res, obj, objVariableName, propName, enumType) {
+function addMultiparamProperty(res, obj, objVariableName, propName, type) {
var val = obj[propName];
if (val && val.length > 0) {
@@ -266,7 +413,7 @@ function addMultiparamProperty(res, obj, objVariableName, propName, enumType) {
if (i > 0)
res.append(', ');
- res.append(toJavaCode(val[i], enumType));
+ res.append(toJavaCode(val[i], type));
}
res.line(');');
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b3abf11d/modules/webconfig/nodejs/utils/generatorXml.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/utils/generatorXml.js b/modules/webconfig/nodejs/utils/generatorXml.js
index 2a07a5f..9aaccff 100644
--- a/modules/webconfig/nodejs/utils/generatorXml.js
+++ b/modules/webconfig/nodejs/utils/generatorXml.js
@@ -224,6 +224,15 @@ exports.generateClusterConfiguration = function(cluster) {
return res.join('');
};
+exports.generateCacheConfiguration = function(cacheCfg, varName, res) {
+ if (!res)
+ res = generatorUtils.builder();
+
+ res.line('cache');
+
+ return res;
+}
+
function addProperty(res, obj, propName) {
var val = obj[propName];