infinispan 0.13.0 → 0.14.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.
- package/Dockerfile.server +8 -0
- package/README.md +4 -10
- package/docker-compose.yml +272 -0
- package/gen-asciidoc.sh +46 -0
- package/lib/codec.js +358 -27
- package/lib/functional.js +40 -7
- package/lib/infinispan.js +503 -52
- package/lib/io.js +399 -43
- package/lib/listeners.js +50 -3
- package/lib/near-cache.js +99 -0
- package/lib/protocols.js +560 -75
- package/lib/sasl/digest.js +22 -17
- package/lib/sasl/external.js +7 -4
- package/lib/sasl/factory.js +6 -5
- package/lib/sasl/oauthbearer.js +7 -5
- package/lib/sasl/plain.js +6 -4
- package/lib/sasl/scram.js +19 -11
- package/lib/utils.js +89 -24
- package/package.json +2 -2
- package/run-docker-testsuite.sh +72 -0
- package/types/index.d.ts +192 -1
package/lib/listeners.js
CHANGED
|
@@ -12,15 +12,38 @@
|
|
|
12
12
|
|
|
13
13
|
module.exports = listeners;
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Creates the listener management subsystem for a protocol instance.
|
|
17
|
+
* @param {Object} protocol Protocol instance with encode/decode methods.
|
|
18
|
+
* @returns {Object} Listener manager with add, remove, find, and dispatch methods.
|
|
19
|
+
*/
|
|
15
20
|
function listeners(protocol) {
|
|
16
21
|
var logger = u.logger('listeners');
|
|
17
22
|
var listeners = u.keyValueMap();
|
|
18
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Sends a request with a pre-write hook executed before sending.
|
|
26
|
+
* @param {Object} transport Transport instance.
|
|
27
|
+
* @param {Object} ctx Request context.
|
|
28
|
+
* @param {number} op Operation code.
|
|
29
|
+
* @param {Function} body Body encoder function.
|
|
30
|
+
* @param {Function} decoder Response decoder function.
|
|
31
|
+
* @param {Object} opts Operation options.
|
|
32
|
+
* @param {Function} preWrite Hook function called before writing.
|
|
33
|
+
* @returns {Promise} Promise resolved with the decoded response.
|
|
34
|
+
*/
|
|
19
35
|
function futurePreWrite(transport, ctx, op, body, decoder, opts, preWrite) {
|
|
20
36
|
f.actions(protocol.stepsHeaderBody(ctx, op, body, opts), codec.bytesEncoded)(ctx);
|
|
21
37
|
return transport.writeCommand(ctx, decoder, preWrite);
|
|
22
38
|
}
|
|
23
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Creates a pre-write hook that registers a listener before sending the add request.
|
|
42
|
+
* @param {string} event Event type name.
|
|
43
|
+
* @param {Function} listener Callback function for the event.
|
|
44
|
+
* @param {string} listenerId Listener identifier.
|
|
45
|
+
* @returns {Function} Pre-write hook function accepting a connection.
|
|
46
|
+
*/
|
|
24
47
|
function preWriteAddListener(event, listener, listenerId) {
|
|
25
48
|
return function(conn) {
|
|
26
49
|
// Listener needs to be registered in advance since events might come
|
|
@@ -28,16 +51,32 @@
|
|
|
28
51
|
// is enabled. To avoid leaking listeners, remove listener if there's
|
|
29
52
|
// any problem.
|
|
30
53
|
emitterAddListener(event, listener, listenerId, conn);
|
|
31
|
-
}
|
|
54
|
+
};
|
|
32
55
|
}
|
|
33
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Creates a new event emitter and registers it in the listeners map.
|
|
59
|
+
* @param {string} listenerId Listener identifier.
|
|
60
|
+
* @param {Object} conn Connection associated with this listener.
|
|
61
|
+
* @param {string} event Event type name.
|
|
62
|
+
* @param {Function} callback Callback function for the event.
|
|
63
|
+
* @returns {EventEmitter} Newly created event emitter.
|
|
64
|
+
*/
|
|
34
65
|
function createEmitter(listenerId, conn, event, callback) {
|
|
35
66
|
var emitter = new events.EventEmitter();
|
|
36
67
|
logger.tracef('Create listener emitter for connection %s and listener with listenerId=%s', conn, listenerId);
|
|
37
|
-
listeners.put(listenerId, {emitter: emitter, conn: conn, event: event, callback: callback});
|
|
68
|
+
listeners.put(listenerId, {id: listenerId, emitter: emitter, conn: conn, event: event, callback: callback});
|
|
38
69
|
return emitter;
|
|
39
70
|
}
|
|
40
71
|
|
|
72
|
+
/**
|
|
73
|
+
* Adds a listener callback to an existing or new emitter for the given listener id.
|
|
74
|
+
* @param {string} event Event type name.
|
|
75
|
+
* @param {Function} callback Callback function for the event.
|
|
76
|
+
* @param {string} listenerId Listener identifier.
|
|
77
|
+
* @param {Object} [conn] Connection associated with this listener.
|
|
78
|
+
* @returns {void}
|
|
79
|
+
*/
|
|
41
80
|
function emitterAddListener(event, callback, listenerId, conn) {
|
|
42
81
|
var l = listeners.get(listenerId);
|
|
43
82
|
var emitter = f.existy(l) ? l.emitter : createEmitter(listenerId, conn, event, callback);
|
|
@@ -98,13 +137,21 @@
|
|
|
98
137
|
|
|
99
138
|
logger.error('No emitter exists for listener %s', listenerId);
|
|
100
139
|
return true;
|
|
101
|
-
}
|
|
140
|
+
};
|
|
102
141
|
},
|
|
103
142
|
getListenersAt: function (addr) {
|
|
104
143
|
return _.filter(listeners.values(), function(listener) {
|
|
105
144
|
return _.isEqual(addr, listener.conn.getAddress());
|
|
106
145
|
});
|
|
107
146
|
},
|
|
147
|
+
/**
|
|
148
|
+
* Replaces the protocol instance used by the listener subsystem.
|
|
149
|
+
* @param {Object} newProtocol Replacement protocol instance.
|
|
150
|
+
* @returns {void}
|
|
151
|
+
*/
|
|
152
|
+
setProtocol: function(newProtocol) {
|
|
153
|
+
protocol = newProtocol;
|
|
154
|
+
},
|
|
108
155
|
};
|
|
109
156
|
return listen;
|
|
110
157
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
(function() {
|
|
4
|
+
|
|
5
|
+
var u = require('./utils');
|
|
6
|
+
|
|
7
|
+
module.exports = nearCache;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Creates a near cache with LRU eviction.
|
|
11
|
+
* @param {number} maxEntries Maximum number of entries to store.
|
|
12
|
+
* @returns {Object} Near cache instance with get, put, remove, clear, and size methods.
|
|
13
|
+
*/
|
|
14
|
+
function nearCache(maxEntries) {
|
|
15
|
+
var logger = u.logger('near-cache');
|
|
16
|
+
var cache = new Map();
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Moves a key to the end of the Map iteration order (most recently used).
|
|
20
|
+
* @param {string} key The cache key to touch.
|
|
21
|
+
* @param {*} value The cached value.
|
|
22
|
+
* @returns {void}
|
|
23
|
+
*/
|
|
24
|
+
function touch(key, value) {
|
|
25
|
+
cache.delete(key);
|
|
26
|
+
cache.set(key, value);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Evicts the least recently used entry if the cache exceeds maxEntries.
|
|
31
|
+
* @returns {void}
|
|
32
|
+
*/
|
|
33
|
+
function evict() {
|
|
34
|
+
while (cache.size > maxEntries) {
|
|
35
|
+
var oldest = cache.keys().next().value;
|
|
36
|
+
logger.tracef('Near cache evicting key=%s (size=%d, max=%d)', oldest, cache.size, maxEntries);
|
|
37
|
+
cache.delete(oldest);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
/**
|
|
43
|
+
* Get a value from the near cache.
|
|
44
|
+
* @param {string} key Cache key.
|
|
45
|
+
* @returns {Object|undefined} Cached entry with value (and optionally metadata), or undefined on miss.
|
|
46
|
+
*/
|
|
47
|
+
get: function(key) {
|
|
48
|
+
var entry = cache.get(key);
|
|
49
|
+
if (entry !== undefined) {
|
|
50
|
+
touch(key, entry);
|
|
51
|
+
logger.tracef('Near cache hit for key=%s', key);
|
|
52
|
+
return entry;
|
|
53
|
+
}
|
|
54
|
+
logger.tracef('Near cache miss for key=%s', key);
|
|
55
|
+
return undefined;
|
|
56
|
+
},
|
|
57
|
+
/**
|
|
58
|
+
* Put a value into the near cache.
|
|
59
|
+
* @param {string} key Cache key.
|
|
60
|
+
* @param {Object} entry Cached entry object.
|
|
61
|
+
* @returns {void}
|
|
62
|
+
*/
|
|
63
|
+
put: function(key, entry) {
|
|
64
|
+
cache.set(key, entry);
|
|
65
|
+
evict();
|
|
66
|
+
logger.tracef('Near cache put key=%s (size=%d)', key, cache.size);
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* Remove a key from the near cache.
|
|
70
|
+
* @param {string} key Cache key to remove.
|
|
71
|
+
* @returns {boolean} True if the key was present.
|
|
72
|
+
*/
|
|
73
|
+
remove: function(key) {
|
|
74
|
+
var removed = cache.delete(key);
|
|
75
|
+
if (removed) {
|
|
76
|
+
logger.tracef('Near cache invalidated key=%s', key);
|
|
77
|
+
}
|
|
78
|
+
return removed;
|
|
79
|
+
},
|
|
80
|
+
/**
|
|
81
|
+
* Clear all entries from the near cache.
|
|
82
|
+
* @returns {void}
|
|
83
|
+
*/
|
|
84
|
+
clear: function() {
|
|
85
|
+
var oldSize = cache.size;
|
|
86
|
+
cache.clear();
|
|
87
|
+
logger.tracef('Near cache cleared (%d entries removed)', oldSize);
|
|
88
|
+
},
|
|
89
|
+
/**
|
|
90
|
+
* Get the number of entries in the near cache.
|
|
91
|
+
* @returns {number} Current cache size.
|
|
92
|
+
*/
|
|
93
|
+
size: function() {
|
|
94
|
+
return cache.size;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
}.call(this));
|