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 12:46:08 UTC
[5/6] incubator-ignite git commit: # IGNITE-843 Implement java code
generator
# IGNITE-843 Implement java code generator
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/8c2fdaee
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/8c2fdaee
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/8c2fdaee
Branch: refs/heads/ignite-843
Commit: 8c2fdaee21e320461bef3f19a8cba1ad3083ab4d
Parents: adc1e4d
Author: sevdokimov <se...@jetbrains.com>
Authored: Tue Jun 23 13:44:53 2015 +0300
Committer: sevdokimov <se...@jetbrains.com>
Committed: Tue Jun 23 13:44:53 2015 +0300
----------------------------------------------------------------------
modules/webconfig/nodejs/utils/generatorJava.js | 300 ++++++++++++++++++-
.../webconfig/nodejs/utils/generatorUtils.js | 4 +
modules/webconfig/nodejs/utils/generatorXml.js | 149 ++++-----
3 files changed, 380 insertions(+), 73 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8c2fdaee/modules/webconfig/nodejs/utils/generatorJava.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/utils/generatorJava.js b/modules/webconfig/nodejs/utils/generatorJava.js
index 6ab62bf..64a742c 100644
--- a/modules/webconfig/nodejs/utils/generatorJava.js
+++ b/modules/webconfig/nodejs/utils/generatorJava.js
@@ -17,6 +17,304 @@
var generatorUtils = require("./generatorUtils");
+function toJavaCode(val, type) {
+ if (val == null)
+ return 'null';
+
+ if (type == 'f')
+ return val + 'f';
+
+ if (type)
+ return type + '.' + val;
+
+ if (typeof(val) == 'string')
+ return '"' + val.replace('"', '\\"') + '"';
+
+ if (typeof(val) == 'number' || typeof(val) == 'boolean')
+ return '' + val;
+
+ throw "Unknown type: " + typeof(val) + ' (' + val + ')';
+}
+
+function addProperty(res, obj, objVariableName, propName, enumType) {
+ var val = obj[propName];
+
+ if (val) {
+ res.emptyLineIfNeeded();
+
+ res.line(objVariableName + '.' + getSetterName(propName) + '(' + toJavaCode(val, enumType) + ');');
+ }
+}
+
+function getSetterName(propName) {
+ return 'set' + propName.charAt(0).toLocaleUpperCase() + propName.slice(1);
+}
+
+function addListProperty(res, obj, objVariableName, propName, enumType) {
+ var val = obj[propName];
+
+ if (val && val.length > 0) {
+ var setterName = getSetterName(propName);
+
+ res.append(objVariableName + '.' + setterName + '(Arrays.asList(');
+
+ for (var i = 0; i < val.length; i++) {
+ if (i > 0)
+ res.append(', ');
+
+ res.append(toJavaCode(val[i], enumType));
+ }
+
+ res.line('));');
+ }
+}
+
+function addMultiparamProperty(res, obj, objVariableName, propName, enumType) {
+ var val = obj[propName];
+
+ if (val && val.length > 0) {
+ var setterName = getSetterName(propName);
+
+ res.append(objVariableName + '.' + setterName + '(');
+
+ for (var i = 0; i < val.length; i++) {
+ if (i > 0)
+ res.append(', ');
+
+ res.append(toJavaCode(val[i], enumType));
+ }
+
+ res.line(');');
+ }
+}
+
+function addBeanWithProperties(res, bean, objVarName, beanPropName, beanVarName, beanClass, props, alwaysCreateBean) {
+ if (!bean)
+ return;
+
+ var hasProps = false;
+ for (var propName in props) {
+ if (props.hasOwnProperty(propName)) {
+ if (bean[propName]) {
+ hasProps = true;
+ break;
+ }
+ }
+ }
+
+ if (hasProps) {
+ if (!res.emptyLineIfNeeded()) {
+ res.line();
+ }
+
+ res.line(beanClass + ' ' + beanVarName + ' = new ' + beanClass + '();');
+ for (propName in props) {
+ if (props.hasOwnProperty(propName)) {
+ var val = bean[propName];
+ if (val) {
+ var type = props[propName];
+
+ if (type == 'list') {
+ addListProperty(res, bean, beanVarName, propName);
+ }
+ else {
+ addProperty(res, bean, beanVarName, propName, type);
+ }
+ }
+ }
+ }
+ res.line(objVarName + '.' + getSetterName(beanPropName) + '(' + beanVarName + ');');
+
+ res.needEmptyLine = true;
+ }
+ else if (alwaysCreateBean) {
+ res.emptyLineIfNeeded();
+
+ res.line(objVarName + '.' + getSetterName(beanPropName) + '(new ' + beanClass + '());');
+ }
+}
+
exports.generate = function(cluster) {
- return 'java'
+ var res = generatorUtils.builder();
+
+ res.line('IgniteConfiguration cfg = new IgniteConfiguration();');
+ res.line();
+
+ if (cluster.discovery) {
+ var d = cluster.discovery;
+
+ res.line('TcpDiscoverySpi discovery = new TcpDiscoverySpi();');
+ switch (d.kind) {
+ case 'Multicast':
+ addBeanWithProperties(res, d.Multicast, 'discovery', 'ipFinder', 'ipFinder',
+ 'TcpDiscoveryMulticastIpFinder', {
+ multicastGroup: null,
+ multicastPort: null,
+ responseWaitTime: null,
+ addressRequestAttempts: null,
+ localAddress: null
+ }, true);
+
+ break;
+
+ case 'Vm':
+ addBeanWithProperties(res, d.Vm, 'discovery', 'ipFinder', 'ipFinder',
+ 'TcpDiscoveryVmIpFinder', {addresses: 'list'}, true);
+
+ break;
+
+ case 'S3':
+ if (d.S3) {
+ addBeanWithProperties(res, d.S3, 'discovery', 'ipFinder', 'ipFinder',
+ 'TcpDiscoveryS3IpFinder', {bucketName: null}, true);
+ }
+ else {
+ res.line('discovery.setIpFinder(new TcpDiscoveryS3IpFinder());');
+ }
+
+ break;
+
+ case 'Cloud':
+ addBeanWithProperties(res, d.Cloud, 'discovery', 'ipFinder', 'ipFinder',
+ 'TcpDiscoveryCloudIpFinder', {
+ credential: null,
+ credentialPath: null,
+ identity: null,
+ provider: null
+ }, true);
+
+ break;
+
+ case 'GoogleStorage':
+ addBeanWithProperties(res, d.GoogleStorage, 'discovery', 'ipFinder', 'ipFinder',
+ 'TcpDiscoveryGoogleStorageIpFinder', {
+ projectName: null,
+ bucketName: null,
+ serviceAccountP12FilePath: null
+ }, true);
+
+ //if (d.GoogleStorage.addrReqAttempts) todo ????
+ // res.line('<property name="serviceAccountP12FilePath" value="' + escapeAttr(d.GoogleStorage.addrReqAttempts) + '"/>');
+
+ break;
+
+ case 'Jdbc':
+ res.line();
+ res.line('TcpDiscoveryJdbcIpFinder ipFinder = new TcpDiscoveryJdbcIpFinder();');
+ res.line('ipFinder.setInitSchema(' + (d.Jdbc.initSchema != null || d.Jdbc.initSchema) + ');');
+ res.line('discovery.setIpFinder(ipFinder);');
+ res.needEmptyLine = true;
+
+ break;
+
+ case 'SharedFs':
+ addBeanWithProperties(res, d.SharedFs, 'discovery', 'ipFinder', 'ipFinder',
+ 'TcpDiscoverySharedFsIpFinder', {path: null}, true);
+
+ break;
+
+ default:
+ throw "Unknown discovery kind: " + d.kind;
+ }
+
+ res.emptyLineIfNeeded();
+
+ res.line('cfg.setDiscoverySpi(discovery);');
+
+ res.needEmptyLine = true;
+ }
+
+ addBeanWithProperties(res, cluster.atomicConfiguration, 'cfg', 'atomicConfiguration', 'atomicCfg', 'AtomicConfiguration', {
+ backups: null,
+ cacheMode: 'CacheMode',
+ atomicSequenceReserveSize: null});
+
+ res.needEmptyLine = true;
+
+ addProperty(res, cluster, 'cfg', 'networkTimeout');
+ addProperty(res, cluster, 'cfg', 'networkSendRetryDelay');
+ addProperty(res, cluster, 'cfg', 'networkSendRetryCount');
+ addProperty(res, cluster, 'cfg', 'segmentCheckFrequency');
+ addProperty(res, cluster, 'cfg', 'waitForSegmentOnStart');
+ addProperty(res, cluster, 'cfg', 'discoveryStartupDelay');
+
+ res.needEmptyLine = true;
+
+ addProperty(res, cluster, 'cfg', 'deploymentMode', 'DeploymentMode');
+
+ res.needEmptyLine = true;
+
+ addListProperty(res, cluster, 'cfg', 'includeEventTypes');
+
+ res.needEmptyLine = true;
+
+ addProperty(res, cluster, 'cfg', 'marshalLocalJobs');
+ addProperty(res, cluster, 'cfg', 'marshCacheKeepAliveTime');
+ addProperty(res, cluster, 'cfg', 'marshCachePoolSize');
+
+ res.needEmptyLine = true;
+
+ addProperty(res, cluster, 'cfg', 'metricsExpireTime');
+ addProperty(res, cluster, 'cfg', 'metricsHistorySize');
+ addProperty(res, cluster, 'cfg', 'metricsLogFrequency');
+ addProperty(res, cluster, 'cfg', 'metricsUpdateFrequency');
+ res.needEmptyLine = true;
+
+ addProperty(res, cluster, 'cfg', 'peerClassLoadingEnabled');
+ addMultiparamProperty(res, cluster, 'cfg', 'peerClassLoadingLocalClassPathExclude');
+ addProperty(res, cluster, 'cfg', 'peerClassLoadingMissedResourcesCacheSize');
+ addProperty(res, cluster, 'cfg', 'peerClassLoadingThreadPoolSize');
+ res.needEmptyLine = true;
+
+ addBeanWithProperties(res, cluster.swapSpaceSpi.FileSwapSpaceSpi, 'cfg', 'swapSpaceSpi', 'swapSpi', 'FileSwapSpaceSpi', {
+ baseDirectory: null,
+ readStripesNumber: null,
+ maximumSparsity: 'f',
+ maxWriteQueueSize: null,
+ writeBufferSize: null
+ }, true);
+
+ res.needEmptyLine = true;
+
+ addProperty(res, cluster, 'cfg', 'clockSyncSamples');
+ addProperty(res, cluster, 'cfg', 'clockSyncFrequency');
+ addProperty(res, cluster, 'cfg', 'timeServerPortBase');
+ addProperty(res, cluster, 'cfg', 'timeServerPortRange');
+
+ res.needEmptyLine = true;
+
+ addProperty(res, cluster, 'cfg', 'publicThreadPoolSize');
+ addProperty(res, cluster, 'cfg', 'systemThreadPoolSize');
+ addProperty(res, cluster, 'cfg', 'managementThreadPoolSize');
+ addProperty(res, cluster, 'cfg', 'igfsThreadPoolSize');
+
+ res.needEmptyLine = true;
+
+ addBeanWithProperties(res, cluster.transactionConfiguration, 'cfg', 'transactionConfiguration',
+ 'transactionConfiguration', 'TransactionConfiguration', {
+ defaultTxConcurrency: 'TransactionConcurrency',
+ transactionIsolation: 'TransactionIsolation',
+ defaultTxTimeout: null,
+ pessimisticTxLogLinger: null,
+ pessimisticTxLogSize: null,
+ txSerializableEnabled: null
+ });
+
+ res.needEmptyLine = true;
+
+ addProperty(res, cluster, 'cfg', 'cacheSanityCheckEnabled');
+
+ res.needEmptyLine = true;
+
+ addProperty(res, cluster, 'cfg', 'segmentationPolicy', 'SegmentationPolicy');
+ addProperty(res, cluster, 'cfg', 'segmentationResolveAttempts');
+ addProperty(res, cluster, 'cfg', 'allSegmentationResolversPassRequired');
+
+ res.needEmptyLine = true;
+
+ res.needEmptyLine = true;
+ addProperty(res, cluster, 'cfg', 'utilityCacheKeepAliveTime');
+ addProperty(res, cluster, 'cfg', 'utilityCachePoolSize');
+
+ return res.join('');
};
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8c2fdaee/modules/webconfig/nodejs/utils/generatorUtils.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/utils/generatorUtils.js b/modules/webconfig/nodejs/utils/generatorUtils.js
index dd26314..84e8f62 100644
--- a/modules/webconfig/nodejs/utils/generatorUtils.js
+++ b/modules/webconfig/nodejs/utils/generatorUtils.js
@@ -94,7 +94,11 @@ exports.builder = function () {
this.line();
this.needEmptyLine = false;
+
+ return true;
}
+
+ return false;
};
return res;
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/8c2fdaee/modules/webconfig/nodejs/utils/generatorXml.js
----------------------------------------------------------------------
diff --git a/modules/webconfig/nodejs/utils/generatorXml.js b/modules/webconfig/nodejs/utils/generatorXml.js
index d72874d..e786612 100644
--- a/modules/webconfig/nodejs/utils/generatorXml.js
+++ b/modules/webconfig/nodejs/utils/generatorXml.js
@@ -135,83 +135,89 @@ exports.generate = function(cluster) {
res.needEmptyLine = true
}
- addBeanWithProperties(res, cluster, 'atomicConfiguration', 'org.apache.ignite.configuration.AtomicConfiguration',
- ['backups', 'cacheMode', 'atomicSequenceReserveSize']);
+ addBeanWithProperties(res, cluster.atomicConfiguration, 'atomicConfiguration',
+ 'org.apache.ignite.configuration.AtomicConfiguration', ['backups', 'cacheMode', 'atomicSequenceReserveSize']);
res.needEmptyLine = true;
- addProperty(res, cluster, 'clockSyncSamples');
- addProperty(res, cluster, 'clockSyncFrequency');
+ addProperty(res, cluster, 'networkTimeout');
+ addProperty(res, cluster, 'networkSendRetryDelay');
+ addProperty(res, cluster, 'networkSendRetryCount');
+ addProperty(res, cluster, 'segmentCheckFrequency');
+ addProperty(res, cluster, 'waitForSegmentOnStart');
+ addProperty(res, cluster, 'discoveryStartupDelay');
+
res.needEmptyLine = true;
- addListProperty(res, cluster, 'includeEventTypes');
+
+ addProperty(res, cluster, 'deploymentMode');
+
res.needEmptyLine = true;
- addProperty(res, cluster, 'igfsThreadPoolSize');
- addProperty(res, cluster, 'publicThreadPoolSize');
- addProperty(res, cluster, 'systemThreadPoolSize');
- addProperty(res, cluster, 'utilityCachePoolSize');
- addProperty(res, cluster, 'managementThreadPoolSize');
+
+ addListProperty(res, cluster, 'includeEventTypes');
+
res.needEmptyLine = true;
+
addProperty(res, cluster, 'marshalLocalJobs');
- res.needEmptyLine = true;
addProperty(res, cluster, 'marshCacheKeepAliveTime');
addProperty(res, cluster, 'marshCachePoolSize');
+
res.needEmptyLine = true;
- addProperty(res, cluster, 'cacheSanityCheckEnabled');
- res.needEmptyLine = true;
+
addProperty(res, cluster, 'metricsExpireTime');
addProperty(res, cluster, 'metricsHistorySize');
addProperty(res, cluster, 'metricsLogFrequency');
addProperty(res, cluster, 'metricsUpdateFrequency');
+
res.needEmptyLine = true;
- addProperty(res, cluster, 'networkTimeout');
- addProperty(res, cluster, 'networkSendRetryDelay');
- addProperty(res, cluster, 'networkSendRetryCount');
- addProperty(res, cluster, 'discoveryStartupDelay');
- res.needEmptyLine = true;
- addProperty(res, cluster, 'deploymentMode');
- res.needEmptyLine = true;
+
addProperty(res, cluster, 'peerClassLoadingEnabled');
addListProperty(res, cluster, 'peerClassLoadingLocalClassPathExclude');
addProperty(res, cluster, 'peerClassLoadingMissedResourcesCacheSize');
addProperty(res, cluster, 'peerClassLoadingThreadPoolSize');
+
res.needEmptyLine = true;
- addProperty(res, cluster, 'segmentCheckFrequency');
- addProperty(res, cluster, 'segmentationPolicy');
- addProperty(res, cluster, 'allSegmentationResolversPassRequired');
- addProperty(res, cluster, 'segmentationResolveAttempts');
- addProperty(res, cluster, 'waitForSegmentOnStart');
+
+ addBeanWithProperties(res, cluster.swapSpaceSpi.FileSwapSpaceSpi, 'swapSpaceSpi',
+ 'org.apache.ignite.spi.swapspace.file.FileSwapSpaceSpi', ['baseDirectory', 'readStripesNumber',
+ 'maximumSparsity', 'maxWriteQueueSize', 'writeBufferSize'], true);
+
res.needEmptyLine = true;
+
+ addProperty(res, cluster, 'clockSyncSamples');
+ addProperty(res, cluster, 'clockSyncFrequency');
+ addProperty(res, cluster, 'timeServerPortBase');
+ addProperty(res, cluster, 'timeServerPortRange');
- //addBeanWithProperties(res, cluster, 'swapSpaceSpi', 'org.apache.ignite.spi.swapspace.file.FileSwapSpaceSpi',
- //['baseDirectory', 'readStripesNumber', 'maximumSparsity', 'maxWriteQueueSize', 'writeBufferSize']);
- //res.emptyLineIfNeeded();
+ res.needEmptyLine = true;
- if (cluster.swapSpaceSpi) {
- res.emptyLineIfNeeded();
+ addProperty(res, cluster, 'publicThreadPoolSize');
+ addProperty(res, cluster, 'systemThreadPoolSize');
+ addProperty(res, cluster, 'managementThreadPoolSize');
+ addProperty(res, cluster, 'igfsThreadPoolSize');
- res.startBlock('<property name="swapSpaceSpi">');
- res.startBlock('<bean class="org.apache.ignite.spi.swapspace.file.FileSwapSpaceSpi">');
+ res.needEmptyLine = true;
+
+ addBeanWithProperties(res, cluster.transactionConfiguration, 'transactionConfiguration',
+ 'org.apache.ignite.configuration.TransactionConfiguration', ['defaultTxConcurrency', 'transactionIsolation',
+ 'defaultTxTimeout', 'pessimisticTxLogLinger',
+ 'pessimisticTxLogSize', 'txSerializableEnabled']);
- addProperty(res, cluster.swapSpaceSpi, 'baseDirectory');
- addProperty(res, cluster.swapSpaceSpi, 'readStripesNumber');
- addProperty(res, cluster.swapSpaceSpi, 'maximumSparsity');
- addProperty(res, cluster.swapSpaceSpi, 'maxWriteQueueSize');
- addProperty(res, cluster.swapSpaceSpi, 'writeBufferSize');
- res.endBlock('</bean>');
- res.endBlock('</property>');
+ res.needEmptyLine = true;
- res.needEmptyLine = true;
- }
+ addProperty(res, cluster, 'segmentationPolicy');
+ addProperty(res, cluster, 'allSegmentationResolversPassRequired');
+ addProperty(res, cluster, 'segmentationResolveAttempts');
+
+ res.needEmptyLine = true;
- addBeanWithProperties(res, cluster, 'transactionConfiguration', 'org.apache.ignite.configuration.TransactionConfiguration',
- ['defaultTxConcurrency', 'transactionIsolation', 'defaultTxTimeout', 'pessimisticTxLogLinger',
- 'pessimisticTxLogSize', 'txSerializableEnabled']);
+ addProperty(res, cluster, 'cacheSanityCheckEnabled');
+
+ res.needEmptyLine = true;
- addProperty(res, cluster, 'timeServerPortBase');
- addProperty(res, cluster, 'timeServerPortRange');
res.needEmptyLine = true;
addProperty(res, cluster, 'utilityCacheKeepAliveTime');
-
+ addProperty(res, cluster, 'utilityCachePoolSize');
+
res.push(' </bean>\n');
res.push('</beans>');
@@ -229,36 +235,35 @@ function addProperty(res, obj, propName) {
}
}
-function addBeanWithProperties(res, obj, beanPropName, beanClass, props) {
- var bean = obj[beanPropName];
-
- if (bean) {
- var hasProp = false;
-
- for (var i = 0; i < props.length; i++) {
- if (bean[props[i]]) {
- hasProp = true;
+function addBeanWithProperties(res, bean, beanPropName, beanClass, props, alwaysCreateBean) {
+ if (!bean)
+ return;
- break;
- }
+ var hasProp = false;
+ for (var i = 0; i < props.length; i++) {
+ if (bean[props[i]]) {
+ hasProp = true;
+ break;
}
-
- if (hasProp) {
- res.emptyLineIfNeeded();
-
- res.startBlock('<property name="' + beanPropName + '">');
- res.startBlock('<bean class="' + beanClass + '">');
-
- for (i = 0; i < props.length; i++) {
- addProperty(res, bean, props[i]);
- }
-
- res.endBlock('</bean>');
- res.endBlock('</property>');
+ }
+
+ if (hasProp) {
+ res.emptyLineIfNeeded();
+ res.startBlock('<property name="' + beanPropName + '">');
+ res.startBlock('<bean class="' + beanClass + '">');
+ for (i = 0; i < props.length; i++) {
+ addProperty(res, bean, props[i]);
}
+ res.endBlock('</bean>');
+ res.endBlock('</property>');
+ }
+ else if (alwaysCreateBean) {
+ res.emptyLineIfNeeded();
+ res.line('<property name="' + beanPropName + '">');
+ res.line(' <bean class="' + beanClass + '"/>');
+ res.line('</property>');
}
}
-
function addListProperty(res, obj, propName) {
var val = obj[propName];