infinispan 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. package/Jenkinsfile-release +1 -1
  2. package/README.md +31 -907
  3. package/documentation/asciidoc/stories/assembly_client_usage_examples.adoc +10 -0
  4. package/documentation/asciidoc/stories/assembly_installation_configuration.adoc +20 -0
  5. package/documentation/asciidoc/titles/js_client.asciidoc +28 -0
  6. package/documentation/asciidoc/titles/stories.adoc +5 -0
  7. package/documentation/asciidoc/topics/attributes/community-attributes.adoc +8 -0
  8. package/documentation/asciidoc/topics/attributes/downstream-attributes.adoc +2 -0
  9. package/documentation/asciidoc/topics/code_examples/authentication-digest.js +12 -0
  10. package/documentation/asciidoc/topics/code_examples/authentication-external.js +15 -0
  11. package/documentation/asciidoc/topics/code_examples/authentication-oauthbearer.js +10 -0
  12. package/documentation/asciidoc/topics/code_examples/authentication-plain.js +11 -0
  13. package/documentation/asciidoc/topics/code_examples/authentication-scram.js +11 -0
  14. package/documentation/asciidoc/topics/code_examples/await-multiple-entries.js +36 -0
  15. package/documentation/asciidoc/topics/code_examples/await-single-entries.js +29 -0
  16. package/documentation/asciidoc/topics/code_examples/conditional-operations.js +57 -0
  17. package/documentation/asciidoc/topics/code_examples/connection-multiple-servers.js +23 -0
  18. package/documentation/asciidoc/topics/code_examples/connection-xsite-cluster-switch.js +39 -0
  19. package/documentation/asciidoc/topics/code_examples/connection-xsite.js +13 -0
  20. package/documentation/asciidoc/topics/code_examples/data-types.js +30 -0
  21. package/documentation/asciidoc/topics/code_examples/encryption-crypto-store.js +11 -0
  22. package/documentation/asciidoc/topics/code_examples/encryption-private-key.js +13 -0
  23. package/documentation/asciidoc/topics/code_examples/encryption-sni-hostname.js +9 -0
  24. package/documentation/asciidoc/topics/code_examples/encryption-trust-certs.js +8 -0
  25. package/documentation/asciidoc/topics/code_examples/ephemeral-data.js +52 -0
  26. package/documentation/asciidoc/topics/code_examples/hello-world.js +42 -0
  27. package/documentation/asciidoc/topics/code_examples/key-value-converter.js +67 -0
  28. package/documentation/asciidoc/topics/code_examples/logging-configuration.js +2 -0
  29. package/documentation/asciidoc/topics/code_examples/multiple-entries.js +64 -0
  30. package/documentation/asciidoc/topics/code_examples/register-event-listener.js +64 -0
  31. package/documentation/asciidoc/topics/code_examples/sample-script-execute.js +33 -0
  32. package/documentation/asciidoc/topics/code_examples/sample-script.js +3 -0
  33. package/documentation/asciidoc/topics/code_examples/single-entries.js +49 -0
  34. package/documentation/asciidoc/topics/config_examples/logging.json +14 -0
  35. package/documentation/asciidoc/topics/proc_configuring_authentication.adoc +16 -0
  36. package/documentation/asciidoc/topics/proc_configuring_connections.adoc +25 -0
  37. package/documentation/asciidoc/topics/proc_configuring_connections_xsite.adoc +18 -0
  38. package/documentation/asciidoc/topics/proc_configuring_data_formats.adoc +30 -0
  39. package/documentation/asciidoc/topics/proc_configuring_encryption.adoc +15 -0
  40. package/documentation/asciidoc/topics/proc_configuring_logging.adoc +28 -0
  41. package/documentation/asciidoc/topics/proc_installing_clients.adoc +58 -0
  42. package/documentation/asciidoc/topics/proc_switching_clusters.adoc +17 -0
  43. package/documentation/asciidoc/topics/ref_authentication_mechanisms.adoc +68 -0
  44. package/documentation/asciidoc/topics/ref_client_usage.adoc +116 -0
  45. package/documentation/asciidoc/topics/ref_encryption.adoc +71 -0
  46. package/lib/codec.js +153 -2
  47. package/lib/infinispan.js +33 -1
  48. package/lib/io.js +23 -16
  49. package/lib/protocols.js +165 -68
  50. package/lib/protostream/message-wrapping.proto +134 -0
  51. package/lib/protostream/query.proto +122 -0
  52. package/lib/sasl/bitops.js +24 -0
  53. package/lib/sasl/digest.js +188 -0
  54. package/lib/sasl/external.js +54 -0
  55. package/lib/sasl/factory.js +71 -0
  56. package/lib/sasl/oauthbearer.js +63 -0
  57. package/lib/sasl/plain.js +65 -0
  58. package/lib/sasl/scram.js +135 -0
  59. package/lib/utils.js +1 -1
  60. package/memory-profiling/helper.js +9 -0
  61. package/memory-profiling/infinispan_memory_many_get.js +1 -3
  62. package/memory-profiling/infinispan_memory_one_get.js +6 -4
  63. package/package.json +7 -13
  64. package/run-servers.sh +17 -8
  65. package/run-testsuite.sh +1 -1
  66. package/smoke-tests.sh +8 -2
  67. package/spec/codec_spec.js +7 -7
  68. package/spec/configs/infinispan-clustered.xml +17 -14
  69. package/spec/configs/infinispan-ssl.xml +25 -22
  70. package/spec/configs/infinispan-xsite-EARTH.xml +17 -14
  71. package/spec/configs/infinispan-xsite-MOON.xml +14 -11
  72. package/spec/configs/infinispan.xml +22 -13
  73. package/spec/infinispan_auth_spec.js +16 -37
  74. package/spec/protostream_spec.js +237 -0
  75. package/spec/utils/testing.js +1 -3
  76. package/lib/bitops.js +0 -26
  77. package/lib/scram.js +0 -116
@@ -0,0 +1,10 @@
1
+ [id='client-usage-examples']
2
+ :context: client-usage-examples
3
+ = Using {hr_js} clients
4
+ Take a look at some examples for using the {hr_js} client with {brandname}.
5
+
6
+ include::{topics}/ref_client_usage.adoc[leveloffset=+1]
7
+
8
+ // Restore the parent context.
9
+ ifdef::parent-context[:context: {parent-context}]
10
+ ifndef::parent-context[:!context:]
@@ -0,0 +1,20 @@
1
+ [id='install-configure']
2
+ :context: install-configure
3
+ = Installing and configuring {hr_js} clients
4
+ Ensure your system meets requirements before installing the {hr_js} client.
5
+ You can then configure {hr_js} clients to connect to {brandname} Server, use different media types for keys and values, and customize logging.
6
+
7
+ include::{topics}/proc_installing_clients.adoc[leveloffset=+1]
8
+ include::{topics}/proc_configuring_connections.adoc[leveloffset=+1]
9
+ include::{topics}/proc_configuring_connections_xsite.adoc[leveloffset=+2]
10
+ include::{topics}/proc_switching_clusters.adoc[leveloffset=+2]
11
+ include::{topics}/proc_configuring_authentication.adoc[leveloffset=+1]
12
+ include::{topics}/ref_authentication_mechanisms.adoc[leveloffset=+2]
13
+ include::{topics}/proc_configuring_encryption.adoc[leveloffset=+1]
14
+ include::{topics}/ref_encryption.adoc[leveloffset=+2]
15
+ include::{topics}/proc_configuring_data_formats.adoc[leveloffset=+1]
16
+ include::{topics}/proc_configuring_logging.adoc[leveloffset=+1]
17
+
18
+ // Restore the parent context.
19
+ ifdef::parent-context[:context: {parent-context}]
20
+ ifndef::parent-context[:!context:]
@@ -0,0 +1,28 @@
1
+ //Directory attributes
2
+ :stories: ../stories
3
+ :topics: ../topics
4
+
5
+ //Doc attributes
6
+ //Community
7
+ :community:
8
+ include::{topics}/attributes/community-attributes.adoc[]
9
+ //Downstream
10
+ //include::{topics}/attributes/downstream-attributes.adoc[]
11
+ //:downstream:
12
+ //:rhdg-install-npmrepo:
13
+
14
+ //Title attributes
15
+ :toc2:
16
+ :icons: font
17
+ :toclevels: 3
18
+ :numbered:
19
+ :sectanchors:
20
+
21
+ //Title
22
+ = {hr_js} Client Guide
23
+
24
+ {hr_js} clients provide asynchronous, event-driven access to {brandname} clusters for Node.js applications.
25
+ The asynchronous operation results are represented with `Promise` instances, which allows the client to chain multiple invocations and centralize error handling.
26
+
27
+ //User stories
28
+ include::stories.adoc[]
@@ -0,0 +1,5 @@
1
+ //Reference user stories or topics.
2
+ //Please review authoring guidelines in the Contributors Guide.
3
+
4
+ include::{stories}/assembly_installation_configuration.adoc[leveloffset=+1]
5
+ include::{stories}/assembly_client_usage_examples.adoc[leveloffset=+1]
@@ -0,0 +1,8 @@
1
+ :brandname: Infinispan
2
+ :hr_js: Hot Rod JS
3
+
4
+ :doc_home: https://infinispan.org/documentation/
5
+ :download_url: https://infinispan.org/hotrod-clients
6
+ :node_docs: https://docs.jboss.org/infinispan/hotrod-clients/javascript/1.0/apidocs/
7
+ :server_docs: https://infinispan.org/docs/stable/titles/server/server.html
8
+ :code_tutorials: https://github.com/infinispan/infinispan-simple-tutorials/
@@ -0,0 +1,2 @@
1
+ :brandname: Data Grid
2
+ :hr_js: Hot Rod JS
@@ -0,0 +1,12 @@
1
+ var connected = infinispan.client(
2
+ {port: 11222, host: '127.0.0.1'},
3
+ {
4
+ authentication: {
5
+ enabled: true,
6
+ saslMechanism: 'DIGEST-MD5',
7
+ userName: 'username',
8
+ password: 'changeme',
9
+ serverName: 'infinispan'
10
+ }
11
+ }
12
+ );
@@ -0,0 +1,15 @@
1
+ var connected = infinispan.client(
2
+ {port: 11222, host: '127.0.0.1'},
3
+ {
4
+ authentication: {
5
+ enabled: true,
6
+ saslMechanism: 'EXTERNAL'
7
+ },
8
+ ssl: {
9
+ enabled: true,
10
+ clientAuth: {
11
+ cert: 'out/ssl/client/client.p12',
12
+ }
13
+ }
14
+ }
15
+ );
@@ -0,0 +1,10 @@
1
+ var connected = infinispan.client(
2
+ {port: 11222, host: '127.0.0.1'},
3
+ {
4
+ authentication: {
5
+ enabled: true,
6
+ saslMechanism: 'OAUTHBEARER',
7
+ token: `<token>`
8
+ }
9
+ }
10
+ );
@@ -0,0 +1,11 @@
1
+ var connected = infinispan.client(
2
+ {port: 11222, host: '127.0.0.1'},
3
+ {
4
+ authentication: {
5
+ enabled: true,
6
+ saslMechanism: 'PLAIN',
7
+ userName: 'username',
8
+ password: 'changeme'
9
+ }
10
+ }
11
+ );
@@ -0,0 +1,11 @@
1
+ var connected = infinispan.client(
2
+ {port: 11222, host: '127.0.0.1'},
3
+ {
4
+ authentication: {
5
+ enabled: true,
6
+ saslMechanism: 'SCRAM-SHA-1',
7
+ userName: 'username',
8
+ password: 'changeme'
9
+ }
10
+ }
11
+ );
@@ -0,0 +1,36 @@
1
+ const infinispan = require("infinispan");
2
+
3
+ const log4js = require('log4js');
4
+ log4js.configure('example-log4js.json');
5
+
6
+ async function test() {
7
+ let client = await infinispan.client({port: 11222, host: '127.0.0.1'});
8
+ console.log(`Connected to Infinispan dashboard data`);
9
+
10
+ let data = [
11
+ {key: 'multi1', value: 'v1'},
12
+ {key: 'multi2', value: 'v2'},
13
+ {key: 'multi3', value: 'v3'}];
14
+
15
+ await client.putAll(data);
16
+
17
+ let entries = await client.getAll(['multi2', 'multi3']);
18
+ console.log('getAll(multi2, multi3)=%s', JSON.stringify(entries));
19
+
20
+ let iterator = await client.iterator(1);
21
+
22
+ let entry = {done: true};
23
+
24
+ do {
25
+ entry = await iterator.next();
26
+ console.log('iterator.next()=' + JSON.stringify(entry));
27
+ } while (!entry.done);
28
+
29
+ await iterator.close();
30
+
31
+ await client.clear();
32
+
33
+ await client.disconnect();
34
+ }
35
+
36
+ test();
@@ -0,0 +1,29 @@
1
+ const infinispan = require("infinispan");
2
+
3
+ const log4js = require('log4js');
4
+ log4js.configure('example-log4js.json');
5
+
6
+ async function test() {
7
+ await new Promise((resolve, reject) => setTimeout(() => resolve(), 1000));
8
+ console.log('Hello, World!');
9
+
10
+ let client = await infinispan.client({port: 11222, host: '127.0.0.1'});
11
+ console.log(`Connected to Infinispan dashboard data`);
12
+
13
+ await client.put('key', 'value');
14
+
15
+ let value = await client.get('key');
16
+ console.log('get(key)=' + value);
17
+
18
+ let success = await client.remove('key');
19
+ console.log('remove(key)=' + success);
20
+
21
+ let stats = await client.stats();
22
+ console.log('Number of stores: ' + stats.stores);
23
+ console.log('Number of cache hits: ' + stats.hits);
24
+ console.log('All statistics: ' + JSON.stringify(stats, null, " "));
25
+
26
+ await client.disconnect();
27
+ }
28
+
29
+ test();
@@ -0,0 +1,57 @@
1
+ var infinispan = require('infinispan');
2
+
3
+ var connected = infinispan.client(
4
+ {port: 11222, host: '127.0.0.1'}
5
+ {
6
+ // Configure client connections with authentication and encryption here.
7
+ }
8
+ );
9
+
10
+ connected.then(function (client) {
11
+
12
+ var clientPut = client.putIfAbsent('cond', 'v0');
13
+
14
+ var showPut = clientPut.then(
15
+ function(success) { console.log(':putIfAbsent(cond)=' + success); });
16
+
17
+ var clientReplace = showPut.then(
18
+ function() { return client.replace('cond', 'v1'); } );
19
+
20
+ var showReplace = clientReplace.then(
21
+ function(success) { console.log('replace(cond)=' + success); });
22
+
23
+ var clientGetMetaForReplace = showReplace.then(
24
+ function() { return client.getWithMetadata('cond'); });
25
+
26
+ // Call the getWithMetadata method to retrieve the value and its metadata.
27
+ var clientReplaceWithVersion = clientGetMetaForReplace.then(
28
+ function(entry) {
29
+ console.log('getWithMetadata(cond)=' + JSON.stringify(entry));
30
+ return client.replaceWithVersion('cond', 'v2', entry.version);
31
+ }
32
+ );
33
+
34
+ var showReplaceWithVersion = clientReplaceWithVersion.then(
35
+ function(success) { console.log('replaceWithVersion(cond)=' + success); });
36
+
37
+ var clientGetMetaForRemove = showReplaceWithVersion.then(
38
+ function() { return client.getWithMetadata('cond'); });
39
+
40
+ var clientRemoveWithVersion = clientGetMetaForRemove.then(
41
+ function(entry) {
42
+ console.log('getWithMetadata(cond)=' + JSON.stringify(entry));
43
+ return client.removeWithVersion('cond', entry.version);
44
+ }
45
+ );
46
+
47
+ var showRemoveWithVersion = clientRemoveWithVersion.then(
48
+ function(success) { console.log('removeWithVersion(cond)=' + success)});
49
+
50
+ return showRemoveWithVersion.finally(
51
+ function() { return client.disconnect(); });
52
+
53
+ }).catch(function(error) {
54
+
55
+ console.log("Got error: " + error.message);
56
+
57
+ });
@@ -0,0 +1,23 @@
1
+ var infinispan = require('infinispan');
2
+
3
+ var connected = infinispan.client(
4
+ [{port: 11322, host: '127.0.0.1'}, {port: 11222, host: '127.0.0.1'}]
5
+ {
6
+ // Configure client connections with authentication and encryption here.
7
+ }
8
+ );
9
+
10
+ connected.then(function (client) {
11
+
12
+ var members = client.getTopologyInfo().getMembers();
13
+
14
+ // Displays all members of the {brandname} cluster.
15
+ console.log('Connected to: ' + JSON.stringify(members));
16
+
17
+ return client.disconnect();
18
+
19
+ }).catch(function(error) {
20
+
21
+ console.log("Got error: " + error.message);
22
+
23
+ });
@@ -0,0 +1,39 @@
1
+ var connected = infinispan.client({port: 11222, host: '127.0.0.1'},
2
+ {
3
+ clusters: [
4
+ {
5
+ name: 'LON',
6
+ servers: [{port: 11222, host: 'LON-host'}]
7
+ },
8
+ {
9
+ name: 'NYC',
10
+ servers: [{port: 11222, host: 'NYC-host1'}, {port: 11322, host: 'NYC-host2'}]
11
+ }
12
+ ]
13
+ });
14
+
15
+ connected.then(function (client) {
16
+
17
+ var switchToB = client.getTopologyInfo().switchToCluster('NYC');
18
+
19
+ switchToB.then(function(switchSucceed) {
20
+
21
+ if (switchSucceed) {
22
+ ...
23
+ }
24
+
25
+ ...
26
+
27
+ var switchToDefault = client.getTopologyInfo().switchToDefaultCluster();
28
+
29
+ switchToDefault.then(function(switchSucceed) {
30
+
31
+ if (switchSucceed) {
32
+ ...
33
+ }
34
+
35
+ })
36
+
37
+ })
38
+
39
+ });
@@ -0,0 +1,13 @@
1
+ var connected = infinispan.client({port: 11222, host: '127.0.0.1'},
2
+ {
3
+ clusters: [
4
+ {
5
+ name: 'LON',
6
+ servers: [{port: 11222, host: 'LON-host'}]
7
+ },
8
+ {
9
+ name: 'NYC',
10
+ servers: [{port: 11222, host: 'NYC-host1'}, {port: 11322, host: 'NYC-host2'}]
11
+ }
12
+ ]
13
+ });
@@ -0,0 +1,30 @@
1
+ var infinispan = require('infinispan');
2
+
3
+ var connected = infinispan.client(
4
+ {port: 11222, host: '127.0.0.1'},
5
+ {
6
+ dataFormat : {
7
+ keyType: 'application/json',
8
+ valueType: 'application/json'
9
+ }
10
+ }
11
+ );
12
+
13
+ connected.then(function (client) {
14
+
15
+ var clientPut = client.put({k: 'key'}, {v: 'value'});
16
+
17
+ var clientGet = clientPut.then(
18
+ function() { return client.get({k: 'key'}); });
19
+
20
+ var showGet = clientGet.then(
21
+ function(value) { console.log("get({k: 'key'})=" + JSON.stringify(value)); });
22
+
23
+ return showGet.finally(
24
+ function() { return client.disconnect(); });
25
+
26
+ }).catch(function(error) {
27
+
28
+ console.log("Got error: " + error.message);
29
+
30
+ });
@@ -0,0 +1,11 @@
1
+ var connected = infinispan.client({port: 11222, host: '127.0.0.1'},
2
+ {
3
+ ssl: {
4
+ enabled: true,
5
+ cryptoStore: {
6
+ path: 'my-truststore.p12',
7
+ passphrase: 'secret'
8
+ }
9
+ }
10
+ }
11
+ );
@@ -0,0 +1,13 @@
1
+ var connected = infinispan.client({port: 11222, host: '127.0.0.1'},
2
+ {
3
+ ssl: {
4
+ enabled: true,
5
+ trustCerts: ['my-root-ca.crt.pem'],
6
+ clientAuth: {
7
+ key: 'privkey.pem',
8
+ passphrase: 'secret',
9
+ cert:ssl 'cert.pem'
10
+ }
11
+ }
12
+ }
13
+ );
@@ -0,0 +1,9 @@
1
+ var connected = infinispan.client({port: 11222, host: '127.0.0.1'},
2
+ {
3
+ ssl: {
4
+ enabled: true,
5
+ trustCerts: ['my-root-ca.crt.pem']
6
+ sniHostName: 'example.com'
7
+ }
8
+ }
9
+ );
@@ -0,0 +1,8 @@
1
+ var connected = infinispan.client({port: 11222, host: '127.0.0.1'},
2
+ {
3
+ ssl: {
4
+ enabled: true,
5
+ trustCerts: ['my-root-ca.crt.pem']
6
+ }
7
+ }
8
+ );
@@ -0,0 +1,52 @@
1
+ var infinispan = require('infinispan');
2
+
3
+ var connected = infinispan.client(
4
+ {port: 11222, host: '127.0.0.1'}
5
+ {
6
+ // Configure client connections with authentication and encryption here.
7
+ }
8
+ );
9
+
10
+ connected.then(function (client) {
11
+
12
+ var clientPutExpiry = client.put('expiry', 'value', {lifespan: '1s'});
13
+
14
+ var clientGetMetaAndSize = clientPutExpiry.then(
15
+ function() {
16
+ // Compute getWithMetadata and size in parallel.
17
+ return Promise.all([client.getWithMetadata('expiry'), client.size()]);
18
+ });
19
+
20
+ var showGetMetaAndSize = clientGetMetaAndSize.then(
21
+ function(values) {
22
+ console.log('Before expiration:');
23
+ console.log('getWithMetadata(expiry)=' + JSON.stringify(values[0]));
24
+ console.log('size=' + values[1]);
25
+ });
26
+
27
+ var clientContainsAndSize = showGetMetaAndSize.then(
28
+ function() {
29
+ sleepFor(1100); // Sleep to force expiration.
30
+ return Promise.all([client.containsKey('expiry'), client.size()]);
31
+ });
32
+
33
+ var showContainsAndSize = clientContainsAndSize.then(
34
+ function(values) {
35
+ console.log('After expiration:');
36
+ console.log('containsKey(expiry)=' + values[0]);
37
+ console.log('size=' + values[1]);
38
+ });
39
+
40
+ return showContainsAndSize.finally(
41
+ function() { return client.disconnect(); });
42
+
43
+ }).catch(function(error) {
44
+
45
+ console.log("Got error: " + error.message);
46
+
47
+ });
48
+
49
+ function sleepFor(sleepDuration){
50
+ var now = new Date().getTime();
51
+ while(new Date().getTime() < now + sleepDuration){ /* Do nothing. */ }
52
+ }
@@ -0,0 +1,42 @@
1
+ var infinispan = require('infinispan');
2
+
3
+ // Connect to {brandname} Server.
4
+ // Use an existing cache named "myCache".
5
+ var connected = infinispan.client(
6
+ {port: 11222, host: '127.0.0.1'},
7
+ {
8
+ cacheName: 'myCache',
9
+ clientIntelligence: 'BASIC',
10
+ authentication: {
11
+ enabled: true,
12
+ saslMechanism: 'DIGEST-MD5',
13
+ userName: 'username',
14
+ password: 'changeme'
15
+ }
16
+ }
17
+ );
18
+
19
+ connected.then(function (client) {
20
+
21
+ console.log('Connected to `myCache`');
22
+
23
+ // Add an entry to the cache.
24
+ var clientPut = client.put('hello', 'world');
25
+
26
+ // Retrieve the entry you added.
27
+ var clientGet = clientPut.then(
28
+ function() { return client.get('hello'); });
29
+
30
+ // Print the value of the entry.
31
+ var showGet = clientGet.then(
32
+ function(value) { console.log('get(hello)=' + value); });
33
+
34
+ // Disconnect from {brandname} Server.
35
+ return client.disconnect();
36
+
37
+ }).catch(function(error) {
38
+
39
+ // Log any errors.
40
+ console.log("Got error: " + error.message);
41
+
42
+ });
@@ -0,0 +1,67 @@
1
+ var infinispan = require('infinispan');
2
+
3
+ var connected = infinispan.client(
4
+ {port: 11222, host: '127.0.0.1'}
5
+ , {
6
+ dataFormat : {
7
+ keyType: 'application/json',
8
+ valueType: 'application/json'
9
+ }
10
+ }
11
+ );
12
+
13
+ connected.then(function (client) {
14
+ // Include the remote event converter to avoid unnecessary roundtrips.
15
+ var opts = {
16
+ converterFactory : {
17
+ name: "key-value-with-previous-converter-factory"
18
+ }
19
+ };
20
+
21
+ var clientAddListenerCreate = client.addListener('create', logEvent("Created"), opts);
22
+
23
+ var clientAddListeners = clientAddListenerCreate.then(
24
+ function(listenerId) {
25
+ // Associate multiple callbacks with a single client-side listener.
26
+ // To do this, register listeners with the same listener ID.
27
+ var clientAddListenerModify =
28
+ client.addListener('modify', logEvent("Modified"), {opts, listenerId: listenerId});
29
+
30
+ var clientAddListenerRemove =
31
+ client.addListener('remove', logEvent("Removed"), {opts, listenerId: listenerId});
32
+
33
+ return Promise.all([clientAddListenerModify, clientAddListenerRemove]);
34
+ });
35
+
36
+ var clientCreate = clientAddListeners.then(
37
+ function() { return client.putIfAbsent('converted', 'v0'); });
38
+
39
+ var clientModify = clientCreate.then(
40
+ function() { return client.replace('converted', 'v1'); });
41
+
42
+ var clientRemove = clientModify.then(
43
+ function() { return client.remove('converted'); });
44
+
45
+ var clientRemoveListener =
46
+ Promise.all([clientAddListenerCreate, clientRemove]).then(
47
+ function(values) {
48
+ var listenerId = values[0];
49
+ return client.removeListener(listenerId);
50
+ });
51
+
52
+ return clientRemoveListener.finally(
53
+ function() { return client.disconnect(); });
54
+
55
+ }).catch(function(error) {
56
+
57
+ console.log("Got error: " + error.message);
58
+
59
+ });
60
+
61
+ function logEvent(prefix) {
62
+ return function(event) {
63
+ console.log(prefix + " key: " + event.key);
64
+ console.log(prefix + " value: " + event.value);
65
+ console.log(prefix + " previous value: " + event.prev);
66
+ }
67
+ }
@@ -0,0 +1,2 @@
1
+ var log4js = require('log4js');
2
+ log4js.configure('path/to/my-log4js.json');
@@ -0,0 +1,64 @@
1
+ var infinispan = require('infinispan');
2
+
3
+ var connected = infinispan.client(
4
+ {port: 11222, host: '127.0.0.1'},
5
+ {
6
+ cacheName: 'myCache',
7
+ authentication: {
8
+ enabled: true,
9
+ saslMechanism: 'DIGEST-MD5',
10
+ userName: 'username',
11
+ password: 'changeme'
12
+ }
13
+ }
14
+ );
15
+
16
+ connected.then(function (client) {
17
+ var data = [
18
+ {key: 'multi1', value: 'v1'},
19
+ {key: 'multi2', value: 'v2'},
20
+ {key: 'multi3', value: 'v3'}];
21
+
22
+ var clientPutAll = client.putAll(data);
23
+
24
+ var clientGetAll = clientPutAll.then(
25
+ function() { return client.getAll(['multi2', 'multi3']); });
26
+
27
+ var showGetAll = clientGetAll.then(
28
+ function(entries) {
29
+ console.log('getAll(multi2, multi3)=%s', JSON.stringify(entries));
30
+ }
31
+ );
32
+
33
+ var clientIterator = showGetAll.then(
34
+ function() { return client.iterator(1); });
35
+
36
+ var showIterated = clientIterator.then(
37
+ function(it) {
38
+ function loop(promise, fn) {
39
+ // Simple recursive loop over the iterator's next() call.
40
+ return promise.then(fn).then(function (entry) {
41
+ return entry.done
42
+ ? it.close().then(function () { return entry.value; })
43
+ : loop(it.next(), fn);
44
+ });
45
+ }
46
+
47
+ return loop(it.next(), function (entry) {
48
+ console.log('iterator.next()=' + JSON.stringify(entry));
49
+ return entry;
50
+ });
51
+ }
52
+ );
53
+
54
+ var clientClear = showIterated.then(
55
+ function() { return client.clear(); });
56
+
57
+ return clientClear.finally(
58
+ function() { return client.disconnect(); });
59
+
60
+ }).catch(function(error) {
61
+
62
+ console.log("Got error: " + error.message);
63
+
64
+ });