mqlight.js
function(fileUrl) {
  logger.entry('getFileServiceFunction', logger.NO_CLIENT_ID);
  logger.log('parms', logger.NO_CLIENT_ID, 'fileUrl:', fileUrl);

  if (typeof fileUrl !== 'string') {
    var err = new TypeError('fileUrl must be a string type');
    logger.ffdc('getFileServiceFunction', 'ffdc001', null, err);
    logger.throw('getFileServiceFunction', logger.NO_CLIENT_ID, err);
    throw err;
  }

  var filePath = fileUrl;
  // special case for Windows drive letters in file URIs, trim the leading /
  if (os.platform() === 'win32' && filePath.match('^/[a-zA-Z]:/')) {
    filePath = filePath.substring(1);
  }

  var fileServiceFunction = function(callback) {
    logger.entry('fileServiceFunction', logger.NO_CLIENT_ID);
    logger.log('parms', logger.NO_CLIENT_ID, 'filePath:', filePath);

    fs.readFile(filePath, {encoding: 'utf8'}, function(err, data) {
      logger.entry('fileServiceFunction.readFile.callback',
                   logger.NO_CLIENT_ID);
      logger.log('parms', logger.NO_CLIENT_ID, 'err:', err);
      logger.log('parms', logger.NO_CLIENT_ID, 'data:', data);

      if (err) {
        err.message = 'attempt to read ' + filePath + ' failed with the ' +
                      'following error: ' + err.message;
        logger.log('error', logger.NO_CLIENT_ID, err);
        logger.entry('fileServiceFunction.callback', logger.NO_CLIENT_ID);
        logger.log('parms', logger.NO_CLIENT_ID, 'err:', err);
        callback(err);
        logger.exit('fileServiceFunction.callback', logger.NO_CLIENT_ID, null);
      } else {
        var obj;
        try {
          obj = JSON.parse(data);
        } catch (err) {
          err.message = 'the content read from ' + filePath + ' contained ' +
                        'unparseable JSON: ' + err.message;
          logger.caught('fileServiceFunction.readFile.callback',
                        logger.NO_CLIENT_ID, err);
          logger.entry('fileServiceFunction.callback', logger.NO_CLIENT_ID);
          logger.log('parms', logger.NO_CLIENT_ID, 'err:', err);
          callback(err);
          logger.exit('fileServiceFunction.callback', logger.NO_CLIENT_ID,
                      null);
        }
        if (obj) {
          logger.entry('fileServiceFunction.callback', logger.NO_CLIENT_ID);
          logger.log('parms', logger.NO_CLIENT_ID, 'service:', obj.service);
          callback(null, obj.service);
          logger.exit('fileServiceFunction.callback', logger.NO_CLIENT_ID,
                      null);
        }
      }
      logger.exit('fileServiceFunction.readFile.callback', logger.NO_CLIENT_ID,
                  null);
    });

    logger.exit('fileServiceFunction', logger.NO_CLIENT_ID, null);
  };

  logger.exit('getFileServiceFunction', logger.NO_CLIENT_ID,
              fileServiceFunction);
  return fileServiceFunction;
}
function(fileUrl) {
  logger.entry('getFileServiceFunction', logger.NO_CLIENT_ID);
  logger.log('parms', logger.NO_CLIENT_ID, 'fileUrl:', fileUrl);

  if (typeof fileUrl !== 'string') {
    var err = new TypeError('fileUrl must be a string type');
    logger.ffdc('getFileServiceFunction', 'ffdc001', null, err);
    logger.throw('getFileServiceFunction', logger.NO_CLIENT_ID, err);
    throw err;
  }

  var filePath = fileUrl;
  // special case for Windows drive letters in file URIs, trim the leading /
  if (os.platform() === 'win32' && filePath.match('^/[a-zA-Z]:/')) {
    filePath = filePath.substring(1);
  }

  var fileServiceFunction = function(callback) {
    logger.entry('fileServiceFunction', logger.NO_CLIENT_ID);
    logger.log('parms', logger.NO_CLIENT_ID, 'filePath:', filePath);

    fs.readFile(filePath, {encoding: 'utf8'}, function(err, data) {
      logger.entry('fileServiceFunction.readFile.callback',
                   logger.NO_CLIENT_ID);
      logger.log('parms', logger.NO_CLIENT_ID, 'err:', err);
      logger.log('parms', logger.NO_CLIENT_ID, 'data:', data);

      if (err) {
        err.message = 'attempt to read ' + filePath + ' failed with the ' +
                      'following error: ' + err.message;
        logger.log('error', logger.NO_CLIENT_ID, err);
        logger.entry('fileServiceFunction.callback', logger.NO_CLIENT_ID);
        logger.log('parms', logger.NO_CLIENT_ID, 'err:', err);
        callback(err);
        logger.exit('fileServiceFunction.callback', logger.NO_CLIENT_ID, null);
      } else {
        var obj;
        try {
          obj = JSON.parse(data);
        } catch (err) {
          err.message = 'the content read from ' + filePath + ' contained ' +
                        'unparseable JSON: ' + err.message;
          logger.caught('fileServiceFunction.readFile.callback',
                        logger.NO_CLIENT_ID, err);
          logger.entry('fileServiceFunction.callback', logger.NO_CLIENT_ID);
          logger.log('parms', logger.NO_CLIENT_ID, 'err:', err);
          callback(err);
          logger.exit('fileServiceFunction.callback', logger.NO_CLIENT_ID,
                      null);
        }
        if (obj) {
          logger.entry('fileServiceFunction.callback', logger.NO_CLIENT_ID);
          logger.log('parms', logger.NO_CLIENT_ID, 'service:', obj.service);
          callback(null, obj.service);
          logger.exit('fileServiceFunction.callback', logger.NO_CLIENT_ID,
                      null);
        }
      }
      logger.exit('fileServiceFunction.readFile.callback', logger.NO_CLIENT_ID,
                  null);
    });

    logger.exit('fileServiceFunction', logger.NO_CLIENT_ID, null);
  };

  logger.exit('getFileServiceFunction', logger.NO_CLIENT_ID,
              fileServiceFunction);
  return fileServiceFunction;
}
function ( fileUrl ) { logger . entry ( 'getFileServiceFunction' , logger . NO_CLIENT_ID ) ; logger . log ( 'parms' , logger . NO_CLIENT_ID , 'fileUrl:' , fileUrl ) ; if ( typeof fileUrl !== 'string' ) { var err = new TypeError ( 'fileUrl must be a string type' ) ; logger . ffdc ( 'getFileServiceFunction' , 'ffdc001' , null , err ) ; logger . throw ( 'getFileServiceFunction' , logger . NO_CLIENT_ID , err ) ; throw err ; } var filePath = fileUrl ; // special case for Windows drive letters in file URIs, trim the leading / if ( os . platform ( ) === 'win32' && filePath . match ( '^/[a-zA-Z]:/' ) ) { filePath = filePath . substring ( 1 ) ; } var fileServiceFunction = function ( callback ) { logger . entry ( 'fileServiceFunction' , logger . NO_CLIENT_ID ) ; logger . log ( 'parms' , logger . NO_CLIENT_ID , 'filePath:' , filePath ) ; fs . readFile ( filePath , { encoding : 'utf8' } , function ( err , data ) { logger . entry ( 'fileServiceFunction.readFile.callback' , logger . NO_CLIENT_ID ) ; logger . log ( 'parms' , logger . NO_CLIENT_ID , 'err:' , err ) ; logger . log ( 'parms' , logger . NO_CLIENT_ID , 'data:' , data ) ; if ( err ) { err . message = 'attempt to read ' + filePath + ' failed with the ' + 'following error: ' + err . message ; logger . log ( 'error' , logger . NO_CLIENT_ID , err ) ; logger . entry ( 'fileServiceFunction.callback' , logger . NO_CLIENT_ID ) ; logger . log ( 'parms' , logger . NO_CLIENT_ID , 'err:' , err ) ; callback ( err ) ; logger . exit ( 'fileServiceFunction.callback' , logger . NO_CLIENT_ID , null ) ; } else { var obj ; try { obj = JSON . parse ( data ) ; } catch ( err ) { err . message = 'the content read from ' + filePath + ' contained ' + 'unparseable JSON: ' + err . message ; logger . caught ( 'fileServiceFunction.readFile.callback' , logger . NO_CLIENT_ID , err ) ; logger . entry ( 'fileServiceFunction.callback' , logger . NO_CLIENT_ID ) ; logger . log ( 'parms' , logger . NO_CLIENT_ID , 'err:' , err ) ; callback ( err ) ; logger . exit ( 'fileServiceFunction.callback' , logger . NO_CLIENT_ID , null ) ; } if ( obj ) { logger . entry ( 'fileServiceFunction.callback' , logger . NO_CLIENT_ID ) ; logger . log ( 'parms' , logger . NO_CLIENT_ID , 'service:' , obj . service ) ; callback ( null , obj . service ) ; logger . exit ( 'fileServiceFunction.callback' , logger . NO_CLIENT_ID , null ) ; } } logger . exit ( 'fileServiceFunction.readFile.callback' , logger . NO_CLIENT_ID , null ) ; } ) ; logger . exit ( 'fileServiceFunction' , logger . NO_CLIENT_ID , null ) ; } ; logger . exit ( 'getFileServiceFunction' , logger . NO_CLIENT_ID , fileServiceFunction ) ; return fileServiceFunction ; }
Function to take a single FILE URL and using the JSON retrieved from it to
return an array of service URLs.

@param {String}
fileUrl - Required; a FILE address to retrieve service info
from (e.g., file:///tmp/config.json).
@return {function(callback)} a function which will call the given callback
with a list of AMQP service URLs retrieved from the FILE.
@throws TypeError
If fileUrl is not a string.
@throws Error
if an unsupported or invalid FILE address is specified.
Function to take a single FILE URL and using the JSON retrieved from it to return an array of service URLs .