infinispan 0.9.0 → 0.11.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 (65) hide show
  1. package/.eslintrc +25 -0
  2. package/Jenkinsfile-release +5 -3
  3. package/documentation/asciidoc/stories/assembly_client_usage_examples.adoc +2 -8
  4. package/documentation/asciidoc/stories/{assembly_configuration.adoc → assembly_installation_configuration.adoc} +6 -4
  5. package/documentation/asciidoc/titles/js_client.asciidoc +1 -0
  6. package/documentation/asciidoc/titles/stories.adoc +1 -2
  7. package/documentation/asciidoc/topics/attributes/community-attributes.adoc +2 -1
  8. package/documentation/asciidoc/topics/attributes/downstream-attributes.adoc +0 -2
  9. package/documentation/asciidoc/topics/code_examples/authentication-digest.js +3 -2
  10. package/documentation/asciidoc/topics/code_examples/authentication-external.js +3 -2
  11. package/documentation/asciidoc/topics/code_examples/authentication-oauthbearer.js +3 -2
  12. package/documentation/asciidoc/topics/code_examples/authentication-plain.js +3 -2
  13. package/documentation/asciidoc/topics/code_examples/authentication-scram.js +3 -2
  14. package/documentation/asciidoc/topics/code_examples/await-single-entries.js +1 -1
  15. package/documentation/asciidoc/topics/code_examples/conditional-operations.js +7 -1
  16. package/documentation/asciidoc/topics/code_examples/connection-multiple-servers.js +5 -1
  17. package/documentation/asciidoc/topics/code_examples/data-types.js +2 -2
  18. package/documentation/asciidoc/topics/code_examples/ephemeral-data.js +11 -6
  19. package/documentation/asciidoc/topics/code_examples/hello-world.js +13 -1
  20. package/documentation/asciidoc/topics/code_examples/key-value-converter.js +3 -4
  21. package/documentation/asciidoc/topics/code_examples/multiple-entries.js +13 -2
  22. package/documentation/asciidoc/topics/code_examples/queries.js +92 -0
  23. package/documentation/asciidoc/topics/code_examples/register-event-listener.js +8 -4
  24. package/documentation/asciidoc/topics/code_examples/sample-script-execute.js +6 -1
  25. package/documentation/asciidoc/topics/code_examples/single-entries.js +13 -2
  26. package/documentation/asciidoc/topics/proc_configuring_connections.adoc +8 -9
  27. package/documentation/asciidoc/topics/proc_installing_clients.adoc +23 -5
  28. package/documentation/asciidoc/topics/ref_client_usage.adoc +128 -0
  29. package/lib/codec.js +153 -2
  30. package/lib/infinispan.js +87 -57
  31. package/lib/io.js +14 -8
  32. package/lib/protocols.js +129 -4
  33. package/lib/protostream/message-wrapping.proto +134 -0
  34. package/lib/protostream/query.proto +122 -0
  35. package/lib/sasl/bitops.js +5 -7
  36. package/lib/sasl/factory.js +71 -0
  37. package/lib/utils.js +1 -1
  38. package/memory-profiling/helper.js +9 -0
  39. package/memory-profiling/infinispan_memory_many_get.js +1 -3
  40. package/memory-profiling/infinispan_memory_one_get.js +6 -4
  41. package/package.json +10 -12
  42. package/run-servers.sh +1 -1
  43. package/smoke-tests.sh +1 -0
  44. package/spec/codec_spec.js +7 -7
  45. package/spec/configs/infinispan-clustered.xml +17 -14
  46. package/spec/configs/infinispan-ssl.xml +25 -22
  47. package/spec/configs/infinispan-xsite-EARTH.xml +17 -14
  48. package/spec/configs/infinispan-xsite-MOON.xml +14 -11
  49. package/spec/configs/infinispan.xml +22 -13
  50. package/spec/protostream_spec.js +237 -0
  51. package/spec/utils/testing.js +1 -3
  52. package/types/README.md +91 -0
  53. package/types/index.d.ts +868 -0
  54. package/.jshintrc +0 -14
  55. package/documentation/asciidoc/stories/assembly_getting_started.adoc +0 -11
  56. package/documentation/asciidoc/topics/community-attributes.adoc +0 -10
  57. package/documentation/asciidoc/topics/downstream-attributes.adoc +0 -10
  58. package/documentation/asciidoc/topics/proc_executing_scripts.adoc +0 -16
  59. package/documentation/asciidoc/topics/proc_registering_event_listeners.adoc +0 -31
  60. package/documentation/asciidoc/topics/proc_using_async_await.adoc +0 -23
  61. package/documentation/asciidoc/topics/proc_using_conditional_operations.adoc +0 -7
  62. package/documentation/asciidoc/topics/proc_working_ephemeral_data.adoc +0 -7
  63. package/documentation/asciidoc/topics/proc_working_multiple_entries.adoc +0 -7
  64. package/documentation/asciidoc/topics/proc_working_single_entries_statistics.adoc +0 -7
  65. package/documentation/asciidoc/topics/ref_basic_usage.adoc +0 -8
package/lib/infinispan.js CHANGED
@@ -24,6 +24,7 @@
24
24
  logger.debugf('Using protocol version: %s', version);
25
25
 
26
26
  switch (version) {
27
+ case '3.0': return protocols.version30(clientOpts);
27
28
  case '2.9': return protocols.version29(clientOpts);
28
29
  case '2.5': return protocols.version25(clientOpts);
29
30
  case '2.2': return protocols.version22(clientOpts);
@@ -133,7 +134,7 @@
133
134
  /**
134
135
  * Returns the next entry being iterated over.
135
136
  *
136
- * @returns {module:promise.Promise.<IteratorNext>}
137
+ * @returns {Promise.<IteratorNext>}
137
138
  * It returns a Promise which will be completed with an instance that
138
139
  * provides the next element.
139
140
  * @memberof Iterator#
@@ -168,7 +169,7 @@
168
169
  /**
169
170
  * Close the iteration.
170
171
  *
171
- * @returns {module:promise.Promise}
172
+ * @returns {Promise}
172
173
  * A Promise which will be completed once the iteration has been closed.
173
174
  * @memberof Iterator#
174
175
  * @since 0.3
@@ -200,7 +201,7 @@
200
201
  /**
201
202
  * Disconnect client from backend server(s).
202
203
  *
203
- * @returns {module:promise.Promise}
204
+ * @returns {Promise<void>}
204
205
  * A promise that will be completed once client has
205
206
  * completed disconnection from server(s).
206
207
  * @memberof Client#
@@ -213,7 +214,7 @@
213
214
  * Get the value associated with the given key parameter.
214
215
  *
215
216
  * @param k {(String|Object)} Key to retrieve.
216
- * @returns {module:promise.Promise.<?String>}
217
+ * @returns {Promise.<?String>}
217
218
  * A promise that will be completed with the value associated with
218
219
  * the key, or undefined if the value is not present.
219
220
  * @memberof Client#
@@ -225,11 +226,28 @@
225
226
  var decoder = p.decodeValue();
226
227
  return futureKey(ctx, 0x03, k, p.encodeKey(k), decoder);
227
228
  },
229
+ /**
230
+ * Query the server with the given queryString.
231
+ *
232
+ * @param q {(Object)} query to retrieve.
233
+ * @returns {Promise.<?Object[]>}
234
+ * A promise that will be completed with the array of values associated with
235
+ * the query, or empty array if the no values matches the query.
236
+ * @memberof Client#
237
+ * @since 1.3
238
+ */
239
+ query: function(q) {
240
+ //TODO : extend the support of query with application/json datatypes
241
+ var ctx = transport.context(SMALL);
242
+ logger.debugf('Invoke query(msgId=%d,key=%s)', ctx.id, u.str(q));
243
+ var decoder = p.decodeQuery();
244
+ return futureKey(ctx, 0x1F, q, p.encodeQuery(q), decoder);
245
+ },
228
246
  /**
229
247
  * Check whether the given key is present.
230
248
  *
231
249
  * @param k {(String|Object)} Key to check for presence.
232
- * @returns {module:promise.Promise.<boolean>}
250
+ * @returns {Promise.<boolean>}
233
251
  * A promise that will be completed with true if there is a value
234
252
  * associated with the key, or false otherwise.
235
253
  * @memberof Client#
@@ -256,7 +274,7 @@
256
274
  * Get the value and metadata associated with the given key parameter.
257
275
  *
258
276
  * @param k {(String|Object)} Key to retrieve.
259
- * @returns {module:promise.Promise.<?MetadataValue>}
277
+ * @returns {Promise.<?MetadataValue>}
260
278
  * A promise that will be completed with the value and metadata
261
279
  * associated with the key, or undefined if the value is not present.
262
280
  * @memberof Client#
@@ -298,8 +316,8 @@
298
316
  *
299
317
  * @param k {(String|Object)} Key with which the specified value is to be associated.
300
318
  * @param v {(String|Object)} Value to be associated with the specified key.
301
- * @param opts {?StoreOptions} Optional store options.
302
- * @returns {module:promise.Promise.<?(String|Object)>}
319
+ * @param opts {StoreOptions=} Optional store options.
320
+ * @returns {Promise.<?(String|Object)>}
303
321
  * A promise that will be completed with undefined unless 'previous'
304
322
  * option has been enabled and a previous value exists, in which case it
305
323
  * would return the previous value.
@@ -327,8 +345,8 @@
327
345
  * Removes the mapping for a key if it is present.
328
346
  *
329
347
  * @param k {(String|Object)} Key whose mapping is to be removed.
330
- * @param opts {?RemoveOptions} Optional remove options.
331
- * @returns {module:promise.Promise.<(Boolean|String|Object)>}
348
+ * @param opts {RemoveOptions=} Optional remove options.
349
+ * @returns {Promise.<(Boolean|String|Object)>}
332
350
  * A promise that will be completed with true if the mapping was removed,
333
351
  * or false if the key did not exist.
334
352
  * If the 'previous' option is enabled, it returns the value
@@ -349,8 +367,8 @@
349
367
  *
350
368
  * @param k {(String|Object)} Key with which the specified value is to be associated.
351
369
  * @param v {(String|Object)} Value to be associated with the specified key.
352
- * @param opts {?StoreOptions} Optional store options.
353
- * @returns {module:promise.Promise.<(Boolean|String|Object)>}
370
+ * @param opts {StoreOptions=} Optional store options.
371
+ * @returns {Promise.<(Boolean|String|Object)>}
354
372
  * A promise that will be completed with true if the mapping was stored,
355
373
  * or false if the key is already present.
356
374
  * If the 'previous' option is enabled, it returns the existing value
@@ -371,8 +389,8 @@
371
389
  *
372
390
  * @param k {(String|Object)} Key with which the specified value is associated.
373
391
  * @param v {(String|Object)} Value expected to be associated with the specified key.
374
- * @param opts {?StoreOptions} Optional store options.
375
- * @returns {module:promise.Promise.<(Boolean|String|Object)>}
392
+ * @param opts {StoreOptions=} Optional store options.
393
+ * @returns {Promise.<(Boolean|String|Object)>}
376
394
  * A promise that will be completed with true if the mapping was replaced,
377
395
  * or false if the key does not exist.
378
396
  * If the 'previous' option is enabled, it returns the value that was
@@ -396,8 +414,8 @@
396
414
  * @param version {Buffer} binary buffer version that should match the
397
415
  * one in the server for the operation to succeed. Version information
398
416
  * can be retrieved with getWithMetadata method.
399
- * @param opts {?StoreOptions} Optional store options.
400
- * @returns {module:promise.Promise.<(Boolean|String|Object)>}
417
+ * @param opts {StoreOptions=} Optional store options.
418
+ * @returns {Promise.<(Boolean|String|Object)>}
401
419
  * A promise that will be completed with true if the version matches
402
420
  * and the mapping was replaced, otherwise it returns false if not
403
421
  * replaced because key does not exist or version sent does not match
@@ -424,8 +442,8 @@
424
442
  * @param version {Buffer} binary buffer version that should match the
425
443
  * one in the server for the operation to succeed. Version information
426
444
  * can be retrieved with getWithMetadata method.
427
- * @param opts {?RemoveOptions} Optional remove options.
428
- * @returns {module:promise.Promise.<(Boolean|String|Object)>}
445
+ * @param opts {RemoveOptions=} Optional remove options.
446
+ * @returns {Promise.<(Boolean|String|Object)>}
429
447
  * A promise that will be completed with true if the version matches
430
448
  * and the mapping was removed, otherwise it returns false if not
431
449
  * removed because key does not exist or version sent does not match
@@ -456,7 +474,7 @@
456
474
  * Retrieves all of the entries for the provided keys.
457
475
  *
458
476
  * @param keys {(String[]|Object[])} Keys to find values for.
459
- * @returns {module:promise.Promise.<Entry[]>}
477
+ * @returns {Promise.<Entry[]>}
460
478
  * A promise that will be completed with an array of entries for all
461
479
  * keys found. If a key does not exist, there won't be an entry for that
462
480
  * key in the returned array.
@@ -484,9 +502,9 @@
484
502
  * Stores all of the mappings from the specified entry array.
485
503
  *
486
504
  * @param pairs {Entry[]} key/value pair mappings to be stored
487
- * @param opts {MultiStoreOptions}
505
+ * @param opts {MultiStoreOptions=}
488
506
  * Optional storage options to apply to all entries.
489
- * @returns {module:promise.Promise}
507
+ * @returns {Promise}
490
508
  * A promise that will be completed when all entries have been stored.
491
509
  * @memberof Client#
492
510
  * @since 0.3
@@ -512,8 +530,8 @@
512
530
  *
513
531
  * @param batchSize {Number}
514
532
  * The number of entries transferred from the server at a time.
515
- * @param opts {?IteratorOptions} Optional iteration settings.
516
- * @return {module:promise.Promise.<Iterator>}
533
+ * @param opts {IteratorOptions=} Optional iteration settings.
534
+ * @return {Promise.<Iterator>}
517
535
  * A promise that will be completed with an iterator that can be used
518
536
  * to retrieve stored elements.
519
537
  * @memberof Client#
@@ -530,7 +548,7 @@
530
548
  /**
531
549
  * Count of entries in the server(s).
532
550
  *
533
- * @returns {module:promise.Promise.<Number>}
551
+ * @returns {Promise.<Number>}
534
552
  * A promise that will be completed with the number of entries stored.
535
553
  * @memberof Client#
536
554
  * @since 0.3
@@ -543,7 +561,7 @@
543
561
  /**
544
562
  * Clear all entries stored in server(s).
545
563
  *
546
- * @returns {module:promise.Promise}
564
+ * @returns {Promise}
547
565
  * A promise that will be completed when the clear has been completed.
548
566
  * @memberof Client#
549
567
  * @since 0.3
@@ -556,7 +574,7 @@
556
574
  /**
557
575
  * Pings the server(s).
558
576
  *
559
- * @returns {module:promise.Promise}
577
+ * @returns {Promise}
560
578
  * A promise that will be completed when ping response was received.
561
579
  * @memberof Client#
562
580
  * @since 0.3
@@ -564,7 +582,7 @@
564
582
  ping: function() {
565
583
  var ctx = transport.context(TINY);
566
584
  logger.debugf('Invoke ping(msgId=%d)', ctx.id);
567
- return futureDecodeOnly(ctx, 0x17, p.decodeServerMediaTypes);
585
+ return futureDecodeOnly(ctx, 0x17, p.decodePingResponse);
568
586
  },
569
587
 
570
588
  /**
@@ -580,7 +598,7 @@
580
598
  /**
581
599
  * Retrieve various statistics from server(s).
582
600
  *
583
- * @returns {module:promise.Promise<StatsItem[]>}
601
+ * @returns {Promise<StatsItem[]>}
584
602
  * A promise that will be completed with an array of statistics, where
585
603
  * each element will have a single property. This single property will
586
604
  * have the statistic name as property name and statistic value as
@@ -614,8 +632,8 @@
614
632
  * entry version and listener id.
615
633
  * 'remove' and 'expiry' events callback the function with key
616
634
  * and listener id.
617
- * @param opts {?ListenOptions} Options for adding listener.
618
- * @returns {module:promise.Promise<String>}
635
+ * @param opts {ListenOptions=} Options for adding listener.
636
+ * @returns {Promise<String>}
619
637
  * A promise that will be completed with the identifier of the listener.
620
638
  * This identifier can be used to register multiple callbacks with the
621
639
  * same listener, or to remove the listener.
@@ -645,7 +663,7 @@
645
663
  *
646
664
  * @param {String} listenerId
647
665
  * Listener identifier to identify listener to remove.
648
- * @return {module:promise.Promise}
666
+ * @return {Promise}
649
667
  * A promise that will be completed when the listener has been removed.
650
668
  * @memberof Client#
651
669
  * @since 0.3
@@ -672,7 +690,7 @@
672
690
  *
673
691
  * @param {String} scriptName Name of the script to store.
674
692
  * @param {String} script Script to store in server.
675
- * @return {module:promise.Promise}
693
+ * @return {Promise}
676
694
  * A promise that will be completed when the script has been stored.
677
695
  * @memberof Client#
678
696
  * @since 0.3
@@ -700,9 +718,9 @@
700
718
  * Execute the named script passing in optional parameters.
701
719
  *
702
720
  * @param {String} scriptName Name of the script to execute.
703
- * @param {?ExecParams[]} params
721
+ * @param {ExecParams[]} [params]
704
722
  * Optional array of named parameters to pass to script in server.
705
- * @returns {module:promise.Promise<String|String[]>}
723
+ * @returns {Promise<String|String[]>}
706
724
  * A promise that will be completed with either the value returned by the
707
725
  * script after execution for local scripts, or an array of values
708
726
  * returned by the script when executed in multiple servers for
@@ -735,6 +753,14 @@
735
753
  */
736
754
  toString: function() {
737
755
  return util.format('Client(%s)', transport);
756
+ },
757
+
758
+ registerProtostreamType: function(typeName,descriptorId){
759
+ return p.registerProtostreamType(typeName,descriptorId);
760
+ },
761
+
762
+ registerProtostreamRoot: function(root){
763
+ return p.registerProtostreamRoot(root);
738
764
  }
739
765
  }
740
766
  };
@@ -784,7 +810,7 @@
784
810
  * previously declared via configuration.
785
811
  *
786
812
  * @param clusterName name of the cluster to which to switch to
787
- * @return {module:promise.Promise<Boolean>}
813
+ * @return {Promise<Boolean>}
788
814
  * A promise encapsulating a Boolean that indicates {@code true} if the
789
815
  * switch happened, or {@code false} otherwise.
790
816
  * @memberof Topology#
@@ -797,7 +823,7 @@
797
823
  * Switch remote cache manager to the default cluster,
798
824
  * previously declared via configuration.
799
825
  *
800
- * @return {module:promise.Promise<Boolean>}
826
+ * @return {Promise<Boolean>}
801
827
  * A promise encapsulating a Boolean that indicates {@code true} if the
802
828
  * switch happened, or {@code false} otherwise.
803
829
  * @memberof Topology#
@@ -838,20 +864,18 @@
838
864
  * @param args {(ServerAddress|ServerAddress[])}
839
865
  * Optional single or multiple addresses to which to connect. If none
840
866
  * provided, the client will connect to localhost:11222 address by default.
841
- * @param options {module:infinispan.ClientOptions}
867
+ * @param [options] {ClientOptions}
842
868
  * Optional configuration settings.
843
- * @returns A promise that will be completed once the connection
844
- * has been established. The promise will be completed with a client
845
- * instance on which operations can invoked.
846
869
  * @constructs Client
870
+ * @returns {Promise<ReturnType<Client>>}
847
871
  * @since 0.3
848
872
  */
849
873
  exports.client = function client(args, options) {
850
874
  var merged = f.merge(Client.config, options);
851
875
  var c = new Client(u.normalizeAddresses(args), merged);
876
+
852
877
  return c.connect();
853
878
  };
854
-
855
879
  /**
856
880
  * Cluster information.
857
881
  *
@@ -868,26 +892,32 @@
868
892
  * @static
869
893
  * @typedef {Object} ClientOptions
870
894
  * @property {?(2.9|2.5|2.2)} [version=2.9] - Version of client/server protocol.
871
- * @property {?String} cacheName - Optional cache name.
895
+ * @property {?String} [cacheName] - Optional cache name.
872
896
  * @property {?Number} [maxRetries=3] - Optional number of retries for operation.
897
+ * @property {?Object} [ssl] - TLS/SSL properties.
873
898
  * @property {?boolean} [ssl.enabled=false] - Optional flag to enable SSL support.
874
899
  * @property {?String} [ssl.secureProtocol=TLSv1_2_method] - Optional field with secure protocol in use.
875
- * @property {?String[]} ssl.trustCerts - Optional paths of trusted SSL certificates.
876
- * @property {?String} ssl.clientAuth.key - Optional path to client authentication key.
877
- * @property {?String} ssl.clientAuth.passphrase - Optional password for client key.
878
- * @property {?String} ssl.clientAuth.cert - Optional client certificate.
879
- * @property {?String} ssl.sniHostName - Optional SNI host name.
880
- * @property {?String} ssl.cryptoStore.path - Optional crypto store path.
881
- * @property {?String} ssl.cryptoStore.passphrase - Optional password for crypto store.
882
- * @property {?boolean} authentication.enabled - Enable authentication.
883
- * @property {?String} authentication.saslMechanism - Select the SASL mechanism to use. Can be one of PLAIN, DIGEST-MD5, SCRAM-SHA-1, SCRAM-SHA-256, SCRAM-SHA-384, SCRAM-SHA-512, EXTERNAL, OAUTHBEARER
884
- * @property {?String} authentication.userName - The authentication username. Required by the PLAIN, DIGEST and SCRAM mechanisms.
885
- * @property {?String} authentication.password - The authentication password. Required by the PLAIN, DIGEST and SCRAM mechanisms.
886
- * @property {?String} authentication.token - The OAuth token. Required by the OAUTHBEARER mechanism.
887
- * @property {?String} authentication.authzid - The SASL authorization ID.
900
+ * @property {?String[]} [ssl.trustCerts] - Optional paths of trusted SSL certificates.
901
+ * @property {?String} [ssl.clientAuth.key] - Optional path to client authentication key.
902
+ * @property {?String} [ssl.clientAuth.passphrase] - Optional password for client key.
903
+ * @property {?String} [ssl.clientAuth.cert] - Optional client certificate.
904
+ * @property {?String} [ssl.sniHostName] - Optional SNI host name.
905
+ * @property {?String} [ssl.cryptoStore.path] - Optional crypto store path.
906
+ * @property {?String} [ssl.cryptoStore.passphrase] - Optional password for crypto store.
907
+ * @property {?Object} [authentication]- Authentication properties.
908
+ * @property {?boolean} [authentication.enabled]- Enable authentication.
909
+ * @property {?String} [authentication.saslMechanism] - Select the SASL mechanism to use. Can be one of PLAIN, DIGEST-MD5, SCRAM-SHA-1, SCRAM-SHA-256, SCRAM-SHA-384, SCRAM-SHA-512, EXTERNAL, OAUTHBEARER
910
+ * @property {?String} [authentication.userName] - The authentication username. Required by the PLAIN, DIGEST and SCRAM mechanisms.
911
+ * @property {?String} [authentication.password] - The authentication password. Required by the PLAIN, DIGEST and SCRAM mechanisms.
912
+ * @property {?String} [authentication.token] - The OAuth token. Required by the OAUTHBEARER mechanism.
913
+ * @property {?String} [authentication.authzid] - The SASL authorization ID.
914
+ * @property {?String} [authentication.authzid] - The SASL authorization ID.
915
+ * @property {?Object} [dataFormat] - Content-type for entry
916
+ * @property {?String} [dataFormat.keyType] - Content-type for key
917
+ * @property {?String} [dataFormat.valueType] - Content-type for value
888
918
  * @property {?boolean} [topologyUpdates=true] - Optional flag to controls whether the client deals with topology updates or not.
889
- * @property {?(text/plain|application/json)} [mediaType=text/plain] - Media type of the cache contents.
890
- * @property {?Cluster[]} clusters - Optional additional clusters for cross-site failovers.
919
+ * @property {?("text/plain"|"application/json")} [mediaType="text/plain"] - Media type of the cache contents.
920
+ * @property {?Cluster[]} [clusters] - Optional additional clusters for cross-site failovers.
891
921
  * @since 0.3
892
922
  */
893
923
  Client.config = {
package/lib/io.js CHANGED
@@ -7,9 +7,6 @@
7
7
  var fs = require('fs');
8
8
  var net = require('net');
9
9
 
10
- var promiseFinally = require('promise.prototype.finally');
11
- promiseFinally.shim(); // will be a no-op if not needed
12
-
13
10
  var tls = require('tls');
14
11
  var util = require('util');
15
12
 
@@ -259,10 +256,19 @@
259
256
  });
260
257
  },
261
258
  write: function(buffer) {
262
- var flushed = sock.write(buffer);
263
- if (!flushed)
264
- logger.debugf('Buffer write not fully flushed, part of of data queued for: %s',
265
- buffer.toString('hex').toUpperCase());
259
+ return new Promise(function (fulfill, reject) {
260
+ var flushed = sock.write(buffer, (err) => {
261
+ if (err) {
262
+ logger.error('Error writing to socket: %s', err);
263
+ transport.retryRpcs(addr); // retry RPCs in case of error
264
+ }
265
+ fulfill();
266
+ });
267
+ if (!flushed)
268
+ logger.debugf('Buffer write not fully flushed, part of of data queued for: %s',
269
+ buffer.toString('hex').toUpperCase());
270
+ });
271
+
266
272
  },
267
273
  getAddress: function() {
268
274
  return addr;
@@ -745,7 +751,7 @@
745
751
  logger.debugf('Invoke ping(msgId=%d)', ctx.id);
746
752
  var p = transport.getProtocol();
747
753
  f.actions(p.stepsHeader(ctx, 0x17, undefined), codec.bytesEncoded)(ctx);
748
- return transport.writeCommandPinned(ctx, p.decodeServerMediaTypes, conn);
754
+ return transport.writeCommandPinned(ctx, p.decodePingResponse, conn);
749
755
  }
750
756
 
751
757
  function auth(transport, conn, topologyId) {
package/lib/protocols.js CHANGED
@@ -3,14 +3,14 @@
3
3
  (function() {
4
4
 
5
5
  var _ = require('underscore');
6
-
6
+
7
7
  var f = require('./functional');
8
8
  var u = require('./utils');
9
9
  var codec = require('./codec');
10
10
 
11
11
  var logger = u.logger('protocols');
12
- var s = require('saslmechanisms');
13
- var factory = new s.Factory();
12
+ var Factory = require('./sasl/factory');
13
+ var factory = new Factory();
14
14
  factory.use(require('./sasl/plain'));
15
15
  factory.use(require('./sasl/external'));
16
16
  factory.use('DIGEST-MD5', require('./sasl/digest'));
@@ -55,6 +55,7 @@
55
55
  var DECODE_TIMESTAMP = f.actions([codec.decodeLong(), codec.decodeVInt()], codec.allDecoded(2));
56
56
  var DECODE_UBYTE = f.actions([codec.decodeUByte()], codec.lastDecoded);
57
57
  var DECODE_VINT = f.actions([codec.decodeVInt()], codec.lastDecoded);
58
+ var DECODE_SHORT = f.actions([codec.decodeShort()], codec.lastDecoded);
58
59
 
59
60
  function hasOpt(opts, name) { return _.has(opts, name) && f.truthy(opts[name]); }
60
61
  function hasOptPrev(opts) { return hasOpt(opts, 'previous'); }
@@ -117,6 +118,11 @@
117
118
  return [outer.encodeMediaKey(k)]; // key
118
119
  }
119
120
  },
121
+ encodeQuery: function (q) {
122
+ return function() {
123
+ return [codec.encodeQuery(q)]; // query
124
+ }
125
+ },
120
126
  encodeKeyVersion: function (k, version) {
121
127
  var outer = this;
122
128
  return function() {
@@ -361,6 +367,12 @@
361
367
  return decodeObject(header, bytebuf, decodeAction);
362
368
  }
363
369
  },
370
+ decodeQuery: function() {
371
+ return function(header, bytebuf) {
372
+ var decodeAction = f.actions([f.partial2(codec.decodeQuery,ProtostreamType.lookupProtostreamTypeById,ProtobufRoot.findRootByTypeName)()],codec.lastDecoded);
373
+ return decodeObject(header, bytebuf, decodeAction);
374
+ }
375
+ },
364
376
  decodeWithMeta: function() {
365
377
  var decoderValue = decoderMedia(this.valueMediaType);
366
378
  return function(header, bytebuf) {
@@ -749,6 +761,7 @@
749
761
  return f.dispatch(
750
762
  f.isa('application/json', encoder(2, encoderJson, decoderJson()))
751
763
  , f.isa('text/plain', encoder(13, encoderString, decoderString()))
764
+ , f.isa('application/x-protostream', encoder(12, encoderProtobuf, decoderProtobuf()))
752
765
  )(mediaType);
753
766
  }
754
767
 
@@ -768,6 +781,14 @@
768
781
  return codec.decodeString();
769
782
  }
770
783
 
784
+ function encoderProtobuf(message){
785
+ return codec.encodeProtobuf(message,ProtostreamType.lookupProtostreamTypeByName);
786
+ }
787
+
788
+ function decoderProtobuf(){
789
+ return f.partial2(codec.decodeProtobuf,ProtostreamType.lookupProtostreamTypeById,ProtobufRoot.findRootByTypeName)();
790
+ }
791
+
771
792
  function encoder(id, mediaEncoder, mediaDecoder) {
772
793
  return function() {
773
794
  return [
@@ -873,9 +894,9 @@
873
894
  if (keyMediaType.continue) {
874
895
  var valueMediaType = decodeServerMediaType(bytebuf);
875
896
  if (valueMediaType.continue)
897
+
876
898
  return {result: undefined, continue: true};
877
899
  }
878
-
879
900
  return {continue: false};
880
901
  }
881
902
  }
@@ -943,6 +964,73 @@
943
964
  }
944
965
  }());
945
966
 
967
+ var Ping29Mixin = (function() {
968
+ return {
969
+ decodePingResponse: function(header,bytebuf){
970
+ logger.debugf("header and bytebuf %s %s",header,bytebuf);
971
+ return MediaTypesMixin.decodeServerMediaTypes(header,bytebuf);
972
+ }
973
+ }
974
+ }());
975
+
976
+ var Ping30Mixin = (function() {
977
+ return {
978
+ decodePingResponse: function(header,bytebuf){
979
+ var serverMediaTypes= MediaTypesMixin.decodeServerMediaTypes(header,bytebuf);
980
+ var version=DECODE_UBYTE(bytebuf);
981
+ var opCount=DECODE_VINT(bytebuf);
982
+ var opRequestCodes=[];
983
+ for(let i=0;i<opCount;i++){
984
+ opRequestCodes.push(DECODE_SHORT(bytebuf));
985
+ }
986
+ return serverMediaTypes;
987
+ }
988
+ }
989
+ }());
990
+
991
+ var ProtostreamType = (function() {
992
+ var protostreamTypes=[];
993
+ return {
994
+ registerProtostreamType: function(protostreamTypeName,protostreamDescriptorId){
995
+ var protostreamType={
996
+ protostreamTypeName,
997
+ protostreamDescriptorId
998
+ };
999
+ protostreamTypes.push(protostreamType);
1000
+ return protostreamType;
1001
+ },
1002
+ lookupProtostreamTypeByName: function (protostreamTypeName) {
1003
+ return _.find(protostreamTypes,function(protostreamType){
1004
+ return _.isEqual(protostreamType.protostreamTypeName,protostreamTypeName)
1005
+ }).protostreamDescriptorId;
1006
+ },
1007
+ lookupProtostreamTypeById: function(protostreamDescriptorId){
1008
+ return _.find(protostreamTypes,function(protostreamType){
1009
+ return _.isEqual(protostreamType.protostreamDescriptorId,protostreamDescriptorId)
1010
+ }).protostreamTypeName;
1011
+ }
1012
+ }
1013
+ }());
1014
+
1015
+ var ProtobufRoot = (function() {
1016
+ var protobufRoot;
1017
+ return {
1018
+ registerProtostreamRoot: function(root){
1019
+ protobufRoot=root;
1020
+ return protobufRoot;
1021
+ },
1022
+ findRootByTypeName: function(typeName){
1023
+ try{
1024
+ var root= protobufRoot.lookupType(typeName);
1025
+ return root;
1026
+ }catch(err){
1027
+ throw new Error("Protobuf root not found");
1028
+ }
1029
+ }
1030
+ }
1031
+ }());
1032
+
1033
+
946
1034
  function Protocol(v, clientOpts) {
947
1035
  this.version = v;
948
1036
  this.clientOpts = clientOpts;
@@ -963,6 +1051,10 @@
963
1051
  Protocol.call(this, 29, clientOpts);
964
1052
  };
965
1053
 
1054
+ var Protocol30 = function(clientOpts) {
1055
+ Protocol.call(this, 30, clientOpts);
1056
+ };
1057
+
966
1058
  // TODO: Missing operations, just for reference
967
1059
  var IdsMixin = {
968
1060
  queryId: function() { return 0x1F },
@@ -978,6 +1070,8 @@
978
1070
  , ListenersMixin
979
1071
  , NoListenerInterestsMixin
980
1072
  , NoMediaTypesMixin
1073
+ , ProtostreamType
1074
+ , ProtobufRoot
981
1075
  );
982
1076
 
983
1077
  _.extend(Protocol25.prototype
@@ -989,6 +1083,8 @@
989
1083
  , NoListenerInterestsMixin
990
1084
  , IteratorMixin
991
1085
  , NoMediaTypesMixin
1086
+ , ProtostreamType
1087
+ , ProtobufRoot
992
1088
  );
993
1089
 
994
1090
  _.extend(Protocol29.prototype
@@ -1001,6 +1097,9 @@
1001
1097
  , IteratorMixin
1002
1098
  , MediaTypesMixin
1003
1099
  , SASLMixin
1100
+ , Ping29Mixin
1101
+ , ProtostreamType
1102
+ , ProtobufRoot
1004
1103
  // TODO 2.6 new ops: getStream and putStream
1005
1104
  // TODO 2.6 add listener change: listener event interests
1006
1105
  // TODO 2.7 new ops: prepare, commit and rollback
@@ -1010,6 +1109,28 @@
1010
1109
  // TODO 2.8 header change: media types
1011
1110
  );
1012
1111
 
1112
+ _.extend(Protocol30.prototype
1113
+ , EncodeMixin
1114
+ , ExpiryEncodeMixin
1115
+ , DecodeMixin
1116
+ , IdsMixin
1117
+ , ListenersMixin
1118
+ , ListenerInterestsMixin
1119
+ , IteratorMixin
1120
+ , MediaTypesMixin
1121
+ , SASLMixin
1122
+ , Ping30Mixin
1123
+ , ProtostreamType
1124
+ , ProtobufRoot
1125
+ // TODO 2.6 new ops: getStream and putStream
1126
+ // TODO 2.6 add listener change: listener event interests
1127
+ // TODO 2.7 new ops: prepare, commit and rollback
1128
+ // TODO 2.7 new ops: counter operations
1129
+ // TODO 2.7 new events: counter events
1130
+ // TODO 2.8 listener events: can come from any connection
1131
+ // TODO 2.8 header change: media types
1132
+ );
1133
+
1013
1134
  exports.version22 = function(clientOpts) {
1014
1135
  return new Protocol22(clientOpts);
1015
1136
  };
@@ -1022,4 +1143,8 @@
1022
1143
  return new Protocol29(clientOpts);
1023
1144
  };
1024
1145
 
1146
+ exports.version30 = function(clientOpts) {
1147
+ return new Protocol30(clientOpts);
1148
+ };
1149
+
1025
1150
  }.call(this));