Skip to content

Commit

Permalink
refactor(events): remove superfluous public events
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Aug 2, 2015
1 parent 4fbef5c commit e77a5be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 36 deletions.
22 changes: 4 additions & 18 deletions lib/amqp_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ AMQPClient.ErrorReceived = 'client:errorReceived'; // Called with error
AMQPClient.ConnectionOpened = 'connection:opened';
AMQPClient.ConnectionClosed = 'connection:closed';

AMQPClient.SessionMapped = 'session:mapped';
AMQPClient.SessionUnmapped = 'session:unmapped';


/**
* Exposes various AMQP-related constants, for use in policy overrides.
Expand Down Expand Up @@ -143,28 +140,17 @@ AMQPClient.prototype.connect = function(url) {
self._session.on(Session.Mapped, function(s) {
debug('mapped');
resolve(self);
self.emit(AMQPClient.SessionMapped);
});

self._session.on(Session.Unmapped, function(s) {
debug('unmapped');
self.emit(AMQPClient.SessionUnmapped);
});

self._session.on(Session.ErrorReceived, function(e) {
debug('session error: ', e);
self.emit(AMQPClient.ErrorReceived, e);
});

self._session.on(Session.LinkAttached, function(l) {
self.emit(AMQPClient.LinkAttached, l);
});

self._session.on(Session.LinkDetached, function(l) {
debug('link detached: ' + l.name);
self.emit(AMQPClient.LinkDetached, l);
});

self._session.begin(self.policy.session);
});

Expand Down Expand Up @@ -285,14 +271,14 @@ AMQPClient.prototype.createSender = function(address, options) {
};

var onMapped = function() {
self.removeListener(AMQPClient.SessionMapped, onMapped);
self._session.removeListener(Session.Mapped, onMapped);

var link = self._session.attachLink(linkPolicy);
link.on(Link.Attached, onAttached);
};

(self._session && self._session.mapped) ?
onMapped() : self.on(AMQPClient.SessionMapped, onMapped);
onMapped() : self._session.on(Session.Mapped, onMapped);
};

self._reattach[linkName] = attach;
Expand Down Expand Up @@ -391,14 +377,14 @@ AMQPClient.prototype.createReceiver = function(address, options) {
};

var onMapped = function() {
self.removeListener(AMQPClient.SessionMapped, onMapped);
self._session.removeListener(Session.Mapped, onMapped);

var link = self._session.attachLink(linkPolicy);
link.on(Link.Attached, onAttached);
};

(self._session && self._session.mapped) ?
onMapped() : self.on(AMQPClient.SessionMapped, onMapped);
onMapped() : self._session.on(Session.Mapped, onMapped);
};

self._reattach[linkName] = attach;
Expand Down
22 changes: 4 additions & 18 deletions lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,23 +169,17 @@ function Session(conn) {
util.inherits(Session, EventEmitter);

// Events
Session.Mapped = 'session:mapped';
Session.Unmapped = 'session:unmapped';
Session.Mapped = 'mapped';
Session.Unmapped = 'unmapped';

// Since 'error' events are "special" in Node (as in halt-the-process special),
// using a custom event for errors we receive from the other endpoint. Provides
// received AMQPError as an argument.
Session.ErrorReceived = 'session:errorReceived';

// On successful attach, Link given as argument.
Session.LinkAttached = 'session:linkAttached';

// On completion of detach, Link given as argument.
Session.LinkDetached = 'session:linkDetached';
Session.ErrorReceived = 'errorReceived';

// On receipt of a disposition frame, called with the first and last
// delivery-ids involved, whether they were settled, and the state.
Session.DispositionReceived = 'session:dispositionReceived';
Session.DispositionReceived = 'disposition';

Session.prototype.begin = function(sessionPolicy) {
var sessionParams = u.deepMerge(sessionPolicy.options);
Expand Down Expand Up @@ -227,14 +221,6 @@ Session.prototype.attachLink = function(linkPolicy) {
return link;
};

Session.prototype._linkAttached = function(link) {
this.emit(Session.LinkAttached, link);
};

Session.prototype._linkDetached = function(link) {
this.emit(Session.LinkDetached, link);
};

Session.prototype.addWindow = function(windowSize, flowOptions) {
var opts = flowOptions || {};
this._sessionParams.incomingWindow += windowSize;
Expand Down

0 comments on commit e77a5be

Please sign in to comment.