This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 129
/
filesystem_ascoltatore.js
94 lines (73 loc) · 2.29 KB
/
filesystem_ascoltatore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"use strict";
var AbstractAscoltatore = require('./abstract_ascoltatore');
var crypto = require('crypto');
var util = require('./util');
var debug = require('debug')('ascoltatori:filesystem');
/**
* FileSystemAscoltatore is a class that inherits from AbstractAscoltatore.
* It is implemented using the `qlobber-fsq` module and writes messages to disk. *
* See the [`qlobber-fsq` documentation](https://github.com/davedoesdev/qlobber-fsq) for available options.
*/
function FileSystemAscoltatore(opts)
{
AbstractAscoltatore.call(this, opts, {
separator: '.'
});
opts = opts || {};
var QlobberFSQ = (opts.qlobber_fsq || require('qlobber-fsq')).QlobberFSQ;
opts.separator = this._nativeSettings.separator;
opts.wildcard_one = this._wildcardOne;
opts.wildcard_some = this._wildcardSome;
opts.dedup = false;
this._dehnd = '__filesystem_ascoltatore' + crypto.randomBytes(16).toString('base64');
this._fsq = new QlobberFSQ(opts);
var ths = this;
this._fsq.on('start', function () {
ths.emit('ready');
});
}
/**
* See AbstractAscoltatore for the public API definitions.
*
* @api private
*/
FileSystemAscoltatore.prototype = Object.create(AbstractAscoltatore.prototype);
FileSystemAscoltatore.prototype.subscribe = function (topic, callback, done)
{
var ths = this;
function cb(data, info, cb2)
{
data = JSON.parse(data);
callback(ths._recvTopic(info.topic), data.message, data.options);
cb2();
}
var f = cb;
callback[this._dehnd] = callback[this._dehnd] || f;
this._fsq.subscribe(this._subTopic(topic),
callback[this._dehnd],
done);
};
FileSystemAscoltatore.prototype.unsubscribe = function (topic, callback, done)
{
this._fsq.unsubscribe(this._subTopic(topic),
callback[this._dehnd] || callback,
done);
};
FileSystemAscoltatore.prototype.publish = function (topic, message, options, done)
{
this._fsq.publish(this._pubTopic(topic), JSON.stringify({
message: message,
options: options
}), done);
};
FileSystemAscoltatore.prototype.close = function (done)
{
this._fsq.stop_watching(done);
};
util.aliasAscoltatore(FileSystemAscoltatore.prototype);
/**
* Exports the FileSystemAscoltatore.
*
* @api public
*/
module.exports = FileSystemAscoltatore;