Permalink
Browse files

Removed old event-based loggers

  • Loading branch information...
1 parent affbd03 commit 01ab1c3e969829c15e240dc07d3379fc5a0f9dcd @christav christav committed Mar 16, 2013
Showing with 4 additions and 114 deletions.
  1. +0 −111 lib/logging.js
  2. +0 −2 lib/sbstore.js
  3. +4 −1 test/store-tests.js
View
@@ -1,111 +0,0 @@
-/**
-* Copyright (c) Microsoft. All rights reserved.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-'use strict';
-
-var util = require('util');
-
-/**
- * Convenience function to create listener objects
- * which wire up to the events on the store
- * and service bus interface.
- *
- * @param {object} handlers
- * object containing handlers for the various
- * events from the store & service bus. Looks
- * for methods with the following names:
- *
- * onsubscribe(name, consumer) - a new subscriber to a store message
- * onreceived(nodeId, name, args) - message has been received, args as array
- * onunsubscribe(name, consumer) - unsubscribe from store
- * onpoll(err, message) - poll cycle on service bus completed
- * onsberror(err) - error when interacting with service bus
- *
- */
-
-function makeListener(handlers) {
- var storeEvents = ['subscribe', 'unsubscribe', 'received'];
- var sbEvents = ['poll', 'sberror'];
-
- function wireHandlers(emitter, eventNames) {
- eventNames.forEach(function (eventName) {
- var handlerFunc = handlers['on' + eventName];
- if (handlerFunc) {
- emitter.on(eventName, handlerFunc.bind(handlers));
- }
- });
- }
-
- var listener = {
- store: function (store) {
- wireHandlers(store, storeEvents);
- if (handlers.init) {
- handlers.init(store);
- }
- },
-
- sb: function (sb) {
- wireHandlers(sb, sbEvents);
- }
- };
-
- return listener;
-}
-
-/**
- * Logger object which outputs everything to the console
- *
- */
- var consoleLog = makeListener({
- init: function (store) {
- this.nodeId = store.nodeId;
- },
-
- onsubscribe: function (name, consumer) {
- log('SbStore has new subscriber for %s events', name);
- },
-
- onreceived: function (nodeId, name, args) {
- log('SbStore nodeId %s received message of type %s from node %s',
- this.nodeId, name, nodeId);
- },
-
- onunsubscribe: function (name, consumer) {
- log('SbStore unsubscribing from %s', name);
- },
-
- onpoll: function (err, message) {
- if (err === 'No messages to receive') {
- log('Service bus poll completed, no message');
- } else {
- log('Service bus poll completed, err = %s, message = %s', err, util.inspect(message));
- }
- },
-
- onsberror: function (err) {
- log('Service bus error: %s', err.message);
- }
- });
-
-// helper for formatting
-
-function log() {
- console.log(util.format.apply(null, arguments));
-}
-
-module.exports = {
- makeListener: makeListener,
- console: consoleLog
-};
View
@@ -20,14 +20,12 @@ var io = require('socket.io')
, uuid = require('node-uuid')
, azure = require('azure')
, Client = require('./sbclient')
- , logging = require('./logging')
, MessageBatcher = require('./messagebatcher')
, MessageSequencer = require('./messagesequencer')
, ServiceBusConnector = require('./servicebusconnector');
exports = module.exports = ServiceBusStore;
ServiceBusStore.Client = Client;
-ServiceBusStore.logging = logging;
/**
* construct the store that uses Service Bus to communicate
View
@@ -112,7 +112,10 @@ describe('Service Bus Store objects', function() {
};
before(function () {
- store = new SbStore({listeners: [SbStore.logging.makeListener(listeners)]});
+ store = new SbStore();
+ store.on('subscribe', listeners.onsubscribe);
+ store.on('received', listeners.onreceived);
+ store.on('unsubscribe', listeners.onunsubscribe);
store.subscribe('message1', subscriber1);
store.subscribe('message2', subscriber2);

0 comments on commit 01ab1c3

Please sign in to comment.