Skip to content
This repository was archived by the owner on Nov 28, 2018. It is now read-only.

Commit e47c1b9

Browse files
committed
Merge branch 'factor-out-annoying-stuff'
2 parents aea1092 + 8c7f4f7 commit e47c1b9

File tree

4 files changed

+44
-52
lines changed

4 files changed

+44
-52
lines changed

examples/stomp-producer-txn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
// Same as stomp-producer.js, but transactional
33

4-
var stomp = require('./lib/stomp');
4+
var stomp = require('stomp');
55

66
var num = process.argv[2];
77

lib/frame.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,32 @@ function Frame() {
3636
* @return {Object} Frame object
3737
*/
3838
Frame.prototype.build_frame = function(args, want_receipt) {
39-
var self = this,
40-
receipt_stamp = null;
39+
var receipt_stamp = null;
4140

42-
self.command = args['command'];
43-
self.headers = args['headers'];
44-
self.body = args['body'];
41+
this.command = args['command'];
42+
this.headers = args['headers'];
43+
this.body = args['body'];
4544

4645
if (want_receipt) {
4746
var _receipt = '';
4847
receipt_stamp = Math.floor(Math.random()*99999999999).toString();
49-
if (self.headers['session'] != undefined) {
50-
_receipt = receipt_stamp + "-" + self.headers['session'];
48+
if (this.headers['session'] != undefined) {
49+
_receipt = receipt_stamp + "-" + this.headers['session'];
5150
}
5251
else {
5352
_receipt = receipt_stamp;
5453
}
55-
self.headers['receipt'] = _receipt;
54+
this.headers['receipt'] = _receipt;
5655
}
57-
return self;
56+
return this;
5857
};
5958

6059
/**
6160
* String representation of Frame object
6261
* @return {String} - Frame as string
6362
*/
6463
Frame.prototype.as_string = function() {
65-
var self = this,
66-
header_strs = [],
64+
var header_strs = [],
6765
frame = "",
6866
command = this.command,
6967
headers = this.headers,

lib/stomp-utils.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ StompLogging = exports.StompLogging = function(should_debug) {
66
};
77

88
StompLogging.prototype.debug = function(message) {
9-
if (this.should_debug)
9+
if (this.should_debug) {
1010
console.log("debug: " + message);
11+
}
1112
};
1213

1314
StompLogging.prototype.warn = function(message) {
@@ -16,12 +17,13 @@ StompLogging.prototype.warn = function(message) {
1617

1718
StompLogging.prototype.error = function(message, die) {
1819
console.log("error: " + message);
19-
if (die)
20+
if (die) {
2021
process.exit(1);
22+
}
2123
};
2224

2325
StompLogging.prototype.die = function(message) {
24-
self.error(message, true);
26+
this.error(message, true);
2527
};
2628

2729
StompUtils = exports.StompUtils = function() {
@@ -34,8 +36,9 @@ StompUtils.prototype.really_defined = function(var_to_test) {
3436

3537
// Extend associative array
3638
StompUtils.prototype.extend = function(destination, source) {
37-
for (var property in source)
39+
for (var property in source) {
3840
destination[property] = source[property];
41+
}
3942
return destination;
4043
};
4144

@@ -69,7 +72,6 @@ StompQueue.prototype.get = function() {
6972

7073
if (++this.queue_space * 2 >= this.queue.length) {
7174
this.queue = this.queue.slice(this.queue_space);
72-
console.log("Queue: " + sys.inspect(this.queue));
7375
this.queue_space = 0;
7476
}
7577
}
@@ -83,10 +85,12 @@ StompQueue.prototype.get = function() {
8385
StompQueue.prototype.get_oldest_item = function() {
8486
var item = undefined;
8587

86-
if (this.queue.length)
88+
if (this.queue.length) {
8789
item = this.queue[this.queue_space];
88-
else
90+
}
91+
else {
8992
throw new QueueEmpty();
93+
}
9094

9195
return item;
9296
};

lib/stomp.js

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -256,41 +256,38 @@ Stomp.prototype = new process.EventEmitter();
256256
* Begin connection
257257
*/
258258
Stomp.prototype.connect = function() {
259-
var self = this;
260-
_connect(self);
259+
_connect(this);
261260
};
262261

263262
/**
264263
* Handle frame based on type
265264
* @param {Object} Frame Object
266265
*/
267266
Stomp.prototype.handle_new_frame = function(this_frame) {
268-
var self = this;
269-
270267
switch (this_frame.command) {
271268
case "MESSAGE":
272269
if (utils.really_defined(this_frame.headers['message-id'])) {
273270
// if a subscription to the destination queue exists, fire callback
274-
if (this_frame.headers !== null && this_frame.headers.destination !== null && self._subscribed_to[this_frame.headers.destination] !== null) {
275-
var subscription = self._subscribed_to[this_frame.headers.destination];
271+
if (this_frame.headers !== null && this_frame.headers.destination !== null && this._subscribed_to[this_frame.headers.destination] !== null) {
272+
var subscription = this._subscribed_to[this_frame.headers.destination];
276273
if (subscription.enabled && subscription.callback !== null && typeof(subscription.callback) == 'function') {
277274
subscription.callback(this_frame.body, this_frame.headers);
278275
}
279276
}
280-
self.emit('message', this_frame);
277+
this.emit('message', this_frame);
281278
}
282279

283280
break;
284281
case "CONNECTED":
285282
log.debug('Connected to STOMP');
286-
self.session = this_frame.headers['session'];
287-
self.emit('connected');
283+
this.session = this_frame.headers['session'];
284+
this.emit('connected');
288285
break;
289286
case "RECEIPT":
290-
self.emit('receipt', this_frame.headers['receipt-id']);
287+
this.emit('receipt', this_frame.headers['receipt-id']);
291288
break;
292289
case "ERROR":
293-
self.emit('error', this_frame);
290+
this.emit('error', this_frame);
294291
break;
295292
default:
296293
console.log("Could not parse command: " + this_frame.command);
@@ -309,46 +306,42 @@ Stomp.prototype.disconnect = function() {
309306
* @param {Object} headers
310307
*/
311308
Stomp.prototype.subscribe = function(headers, callback) {
312-
var self = this,
313-
destination = headers['destination'];
314-
headers['session'] = self.session;
309+
var destination = headers['destination'];
310+
headers['session'] = this.session;
315311
send_command(this, 'SUBSCRIBE', headers);
316-
self._subscribed_to[destination] = { enabled: true, callback: callback };
317-
self.log.debug('subscribed to: ' + destination + ' with headers ' + sys.inspect(headers));
312+
this._subscribed_to[destination] = { enabled: true, callback: callback };
313+
this.log.debug('subscribed to: ' + destination + ' with headers ' + sys.inspect(headers));
318314
};
319315

320316
/**
321317
* Unsubscribe from destination (queue or topic)
322318
* @param {Object} headers
323319
*/
324320
Stomp.prototype.unsubscribe = function(headers) {
325-
var self = this,
326-
destination = headers['destination'];
327-
headers['session'] = self.session;
321+
var destination = headers['destination'];
322+
headers['session'] = this.session;
328323
send_command(this, 'UNSUBSCRIBE', headers);
329-
self._subscribed_to[destination].enabled = false;
330-
self.log.debug('no longer subscribed to: ' + destination);
324+
this._subscribed_to[destination].enabled = false;
325+
this.log.debug('no longer subscribed to: ' + destination);
331326
};
332327

333328
/**
334329
* Acknowledge received message
335330
* @param {String} message id to acknowledge
336331
*/
337332
Stomp.prototype.ack = function(message_id) {
338-
var self = this;
339333
send_command(this, 'ACK', {'message-id': message_id});
340-
self.log.debug('acknowledged message: ' + message_id);
334+
this.log.debug('acknowledged message: ' + message_id);
341335
};
342336

343337
/**
344338
* Begin transaction
345339
* @return {String} generated transaction id
346340
*/
347341
Stomp.prototype.begin = function() {
348-
var self = this;
349-
transaction_id = Math.floor(Math.random()*99999999999).toString();
342+
var transaction_id = Math.floor(Math.random()*99999999999).toString();
350343
send_command(this, 'BEGIN', {'transaction': transaction_id});
351-
self.log.debug('begin transaction: ' + transaction_id);
344+
this.log.debug('begin transaction: ' + transaction_id);
352345
return transaction_id;
353346
};
354347

@@ -357,19 +350,17 @@ Stomp.prototype.begin = function() {
357350
* @param {String} transaction id generated by stomp.Stomp.begin()
358351
*/
359352
Stomp.prototype.commit = function(transaction_id) {
360-
var self = this;
361353
send_command(this, 'COMMIT', {'transaction': transaction_id});
362-
self.log.debug('commit transaction: ' + transaction_id);
354+
this.log.debug('commit transaction: ' + transaction_id);
363355
};
364356

365357
/**
366358
* Abort transaction
367359
* @param {String} transaction id generated by stomp.Stomp.begin()
368360
*/
369361
Stomp.prototype.abort = function(transaction_id) {
370-
var self = this;
371362
send_command(this, 'ABORT', {'transaction': transaction_id});
372-
self.log.debug('abort transaction: ' + transaction_id);
363+
this.log.debug('abort transaction: ' + transaction_id);
373364
};
374365

375366
/**
@@ -379,11 +370,10 @@ Stomp.prototype.abort = function(transaction_id) {
379370
* @return {Object} Frame object of message sent
380371
*/
381372
Stomp.prototype.send = function(headers, want_receipt) {
382-
var self = this,
383-
destination = headers['destination'],
373+
var destination = headers['destination'],
384374
body = headers['body'] || null;
385375
delete headers['body'];
386-
headers['session'] = self.session;
376+
headers['session'] = this.session;
387377
return send_command(this, 'SEND', headers, body, want_receipt)
388378
};
389379

0 commit comments

Comments
 (0)