Skip to content

Commit 4ebf424

Browse files
committed
inital commit
0 parents  commit 4ebf424

13 files changed

+623
-0
lines changed

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.gradle
2+
build/
3+
bin/
4+
.settings
5+
6+
# Ignore VertX file cache
7+
.vertx/
8+
9+
# Ignore Gradle GUI config
10+
gradle-app.setting
11+
12+
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
13+
!gradle-wrapper.jar
14+
15+
# Cache of project
16+
.gradletasknamecache
17+
18+
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
19+
# gradle/wrapper/gradle-wrapper.properties
20+
21+
22+
.vscode/
23+
.classpath
24+
.project
25+
26+
node_modules
27+
28+
.bundle
29+
gemfile.lock
30+

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Vertx Javascript Verticle with Validate.js NPM import
2+
3+
This is a example of importing Validate.js with NPM
4+
5+
Uses a Gradle build.

app/cluster.xml

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2017 Red Hat, Inc.
4+
~
5+
~ Red Hat licenses this file to you under the Apache License, version 2.0
6+
~ (the "License"); you may not use this file except in compliance with the
7+
~ License. You may obtain a copy of the License at:
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
~ License for the specific language governing permissions and limitations
15+
~ under the License.
16+
-->
17+
18+
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.8.xsd"
19+
xmlns="http://www.hazelcast.com/schema/config"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
21+
<properties>
22+
<property name="hazelcast.mancenter.enabled">false</property>
23+
<property name="hazelcast.memcache.enabled">false</property>
24+
<property name="hazelcast.rest.enabled">false</property>
25+
<property name="hazelcast.wait.seconds.before.join">0</property>
26+
</properties>
27+
28+
<group>
29+
<name>dev</name>
30+
<password>dev-pass</password>
31+
</group>
32+
<management-center enabled="false">http://localhost:8085/mancenter</management-center>
33+
<network>
34+
<port auto-increment="true" port-count="10000">5701</port>
35+
<outbound-ports>
36+
<!--
37+
Allowed port range when connecting to other nodes.
38+
0 or * means use system provided port.
39+
-->
40+
<ports>0</ports>
41+
</outbound-ports>
42+
<join>
43+
<multicast enabled="true">
44+
<multicast-group>224.2.2.3</multicast-group>
45+
<multicast-port>54327</multicast-port>
46+
</multicast>
47+
<tcp-ip enabled="false">
48+
<interface>192.168.1.28</interface>
49+
</tcp-ip>
50+
<aws enabled="false">
51+
<access-key>my-access-key</access-key>
52+
<secret-key>my-secret-key</secret-key>
53+
<!--optional, default is us-east-1 -->
54+
<region>us-west-1</region>
55+
<!--optional, default is ec2.amazonaws.com. If set, region shouldn't be set as it will override this property -->
56+
<host-header>ec2.amazonaws.com</host-header>
57+
<!-- optional, only instances belonging to this group will be discovered, default will try all running instances -->
58+
<security-group-name>hazelcast-sg</security-group-name>
59+
<tag-key>type</tag-key>
60+
<tag-value>hz-nodes</tag-value>
61+
</aws>
62+
</join>
63+
<interfaces enabled="false">
64+
<interface>10.10.1.*</interface>
65+
</interfaces>
66+
<ssl enabled="false"/>
67+
<socket-interceptor enabled="false"/>
68+
<symmetric-encryption enabled="false">
69+
<!--
70+
encryption algorithm such as
71+
DES/ECB/PKCS5Padding,
72+
PBEWithMD5AndDES,
73+
AES/CBC/PKCS5Padding,
74+
Blowfish,
75+
DESede
76+
-->
77+
<algorithm>PBEWithMD5AndDES</algorithm>
78+
<!-- salt value to use when generating the secret key -->
79+
<salt>thesalt</salt>
80+
<!-- pass phrase to use when generating the secret key -->
81+
<password>thepass</password>
82+
<!-- iteration count to use when generating the secret key -->
83+
<iteration-count>19</iteration-count>
84+
</symmetric-encryption>
85+
</network>
86+
<partition-group enabled="false"/>
87+
<executor-service name="default">
88+
<pool-size>16</pool-size>
89+
<!--Queue capacity. 0 means Integer.MAX_VALUE.-->
90+
<queue-capacity>0</queue-capacity>
91+
</executor-service>
92+
93+
<multimap name="__vertx.subs">
94+
95+
<!--
96+
Number of backups. If 1 is set as the backup-count for example,
97+
then all entries of the map will be copied to another JVM for
98+
fail-safety. 0 means no backup.
99+
-->
100+
<backup-count>1</backup-count>
101+
</multimap>
102+
103+
<map name="__vertx.haInfo">
104+
105+
<!--
106+
Number of backups. If 1 is set as the backup-count for example,
107+
then all entries of the map will be copied to another JVM for
108+
fail-safety. 0 means no backup.
109+
-->
110+
<backup-count>1</backup-count>
111+
<!--
112+
Maximum number of seconds for each entry to stay in the map. Entries that are
113+
older than <time-to-live-seconds> and not updated for <time-to-live-seconds>
114+
will get automatically evicted from the map.
115+
Any integer between 0 and Integer.MAX_VALUE. 0 means infinite. Default is 0.
116+
-->
117+
<time-to-live-seconds>0</time-to-live-seconds>
118+
<!--
119+
Maximum number of seconds for each entry to stay idle in the map. Entries that are
120+
idle(not touched) for more than <max-idle-seconds> will get
121+
automatically evicted from the map. Entry is touched if get, put or containsKey is called.
122+
Any integer between 0 and Integer.MAX_VALUE. 0 means infinite. Default is 0.
123+
-->
124+
<max-idle-seconds>0</max-idle-seconds>
125+
<!--
126+
Valid values are:
127+
NONE (no eviction),
128+
LRU (Least Recently Used),
129+
LFU (Least Frequently Used).
130+
NONE is the default.
131+
-->
132+
<eviction-policy>NONE</eviction-policy>
133+
<!--
134+
Maximum size of the map. When max size is reached,
135+
map is evicted based on the policy defined.
136+
Any integer between 0 and Integer.MAX_VALUE. 0 means
137+
Integer.MAX_VALUE. Default is 0.
138+
-->
139+
<max-size policy="PER_NODE">0</max-size>
140+
<!--
141+
When max. size is reached, specified percentage of
142+
the map will be evicted. Any integer between 0 and 100.
143+
If 25 is set for example, 25% of the entries will
144+
get evicted.
145+
-->
146+
<eviction-percentage>25</eviction-percentage>
147+
<!--
148+
While recovering from split-brain (network partitioning),
149+
map entries in the small cluster will merge into the bigger cluster
150+
based on the policy set here. When an entry merge into the
151+
cluster, there might an existing entry with the same key already.
152+
Values of these entries might be different for that same key.
153+
Which value should be set for the key? Conflict is resolved by
154+
the policy set here. Default policy is PutIfAbsentMapMergePolicy
155+
156+
There are built-in merge policies such as
157+
com.hazelcast.map.merge.PassThroughMergePolicy; entry will be added if there is no existing entry for the key.
158+
com.hazelcast.map.merge.PutIfAbsentMapMergePolicy ; entry will be added if the merging entry doesn't exist in the cluster.
159+
com.hazelcast.map.merge.HigherHitsMapMergePolicy ; entry with the higher hits wins.
160+
com.hazelcast.map.merge.LatestUpdateMapMergePolicy ; entry with the latest update wins.
161+
-->
162+
<merge-policy>com.hazelcast.map.merge.LatestUpdateMapMergePolicy</merge-policy>
163+
164+
</map>
165+
166+
<!-- Used internally in Vert.x to implement async locks -->
167+
<semaphore name="__vertx.*">
168+
<initial-permits>1</initial-permits>
169+
</semaphore>
170+
171+
</hazelcast>

app/entryPointVerticle.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
exports.vertxStart = function() {
2+
console.log("Starting primary verticle")
3+
}
4+
exports.vertxStop = function() {
5+
console.log('Stopping primary verticle')
6+
}
7+
8+
var _ = require('lodash')
9+
var validate = require('validate.js')
10+
11+
var constraints = {
12+
creditCardNumber: {
13+
presence: true,
14+
format: {
15+
pattern: /^(34|37|4|5[1-5]).*$/,
16+
message: function(value, attribute, validatorOptions, attributes, globalOptions) {
17+
return validate.format("^%{num} is not a valid credit card number", {
18+
num: value
19+
});
20+
}
21+
},
22+
length: function(value, attributes, attributeName, options, constraints) {
23+
if (value) {
24+
// Amex
25+
if ((/^(34|37).*$/).test(value)) return {is: 15};
26+
// Visa, Mastercard
27+
if ((/^(4|5[1-5]).*$/).test(value)) return {is: 16};
28+
}
29+
// Unknown card, don't validate length
30+
return false;
31+
}
32+
},
33+
creditCardZip: function(value, attributes, attributeName, options, constraints) {
34+
if (!(/^(34|37).*$/).test(attributes.creditCardNumber)) return null;
35+
return {
36+
presence: {message: "is required when using AMEX"},
37+
length: {is: 5}
38+
};
39+
}
40+
};
41+
42+
var myValidation = validate({creditCardNumber: "4"}, constraints)
43+
44+
console.log(JSON.stringify(myValidation));
45+
// => {"creditCardNumber": ["Credit card number is the wrong length (should be 16 characters)"]}
46+
47+
// print(JSON.stringify(validate({creditCardNumber: "9999999999999999"}, constraints)));
48+
// // => {"creditCardNumber": ["9999999999999999 is not a valid credit card number"]}
49+
50+
// print(JSON.stringify(validate({creditCardNumber: "4242424242424242"}, constraints)));
51+
// // => undefined
52+
53+
// print(JSON.stringify(validate({creditCardNumber: "340000000000000", creditCardZip: "123"}, constraints)));
54+
// // => {"creditCardZip": ["Credit card zip is required when using AMEX"]}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) 2011-2017 Contributors to the Eclipse Foundation
2+
#
3+
# This program and the accompanying materials are made available under the
4+
# terms of the Eclipse Public License 2.0 which is available at
5+
# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
6+
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
7+
#
8+
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
9+
10+
# Logging levels:
11+
# https://docs.oracle.com/javase/8/docs/api/java/util/logging/Level.html
12+
13+
handlers=java.util.logging.ConsoleHandler,java.util.logging.FileHandler
14+
java.util.logging.SimpleFormatter.format=%5$s %6$s\n
15+
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
16+
17+
java.util.logging.ConsoleHandler.level=CONFIG
18+
java.util.logging.FileHandler.level=CONFIG
19+
java.util.logging.FileHandler.formatter=io.vertx.core.logging.VertxLoggerFormatter
20+
21+
# Put the log in the system temporary directory
22+
java.util.logging.FileHandler.pattern=%t/vertx.log
23+
24+
com.hazelcast.level=CONFIG
25+
26+
.level=CONFIG
27+
io.vertx.level=CONFIG
28+
io.netty.util.internal.PlatformDependent.level=CONFIG

build.gradle

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
plugins {
2+
id 'java'
3+
id 'application'
4+
id 'com.github.johnrengelman.shadow' version '2.0.2'
5+
id "com.moowork.node" version "1.2.0" //https://github.com/srs/gradle-node-plugin
6+
}
7+
8+
repositories {
9+
jcenter()
10+
}
11+
12+
version = '0.1.0'
13+
sourceCompatibility = '1.8'
14+
mainClassName = 'io.vertx.core.Launcher'
15+
16+
def vertxVersion = '3.5.1'
17+
def mainVerticleName = 'entryPointVerticle.js'
18+
def watchForChange = 'app/**'
19+
def doOnChange = './gradlew classes'
20+
21+
def vertxConfigFile = 'vertx-config.json'
22+
23+
dependencies {
24+
compile "io.vertx:vertx-core:$vertxVersion"
25+
compile "io.vertx:vertx-lang-js:$vertxVersion" // JS Lang
26+
compile "io.vertx:vertx-hazelcast:$vertxVersion"
27+
compile "io.vertx:vertx-config:$vertxVersion"
28+
compile "io.vertx:vertx-config-yaml:$vertxVersion"
29+
testCompile "junit:junit:4.12"
30+
testCompile "io.vertx:vertx-unit:$vertxVersion"
31+
}
32+
33+
processResources {
34+
from 'app'
35+
from ('node_modules') {into 'node_modules'}
36+
}
37+
38+
shadowJar {
39+
classifier = 'fat'
40+
manifest {
41+
attributes "Main-Verticle": mainVerticleName
42+
}
43+
mergeServiceFiles {
44+
include 'META-INF/services/io.vertx.core.spi.VerticleFactory'
45+
}
46+
}
47+
48+
run {
49+
args = ['run', mainVerticleName,
50+
"--redeploy=$watchForChange",
51+
"--launcher-class=$mainClassName",
52+
"--on-redeploy=$doOnChange",
53+
]
54+
}
55+
56+
task wrapper(type: Wrapper) {
57+
gradleVersion = '4.6.0'
58+
}

gradle/wrapper/gradle-wrapper.jar

53.4 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
zipStoreBase=GRADLE_USER_HOME
4+
zipStorePath=wrapper/dists
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-bin.zip

0 commit comments

Comments
 (0)