1. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 10/3/2017 11:52:35 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

1.1 Files compared

# Location File Last Modified
1 job-framework.zip\job-framework\src beanstalk-client.js Wed Nov 16 18:40:08 2016 UTC
2 job-framework.zip\job-framework\src beanstalk-client.js Tue Oct 3 16:49:30 2017 UTC

1.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 638
Changed 1 2
Inserted 0 0
Removed 0 0

1.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

1.4 Active regular expressions

No regular expressions were active.

1.5 Comparison detail

  1   'use stric t';
  2  
  3   var events  = require ('events') ;
  4   var net =  require('n et');
  5   var util =  require(' util');
  6   var _ = re quire('und erscore');
  7  
  8   var Respon seHandler  = require( './respons e-handler. js');
  9  
  10   var DEFAUL T_HOST = ' 127.0.0.1' ;
  11   var DEFAUL T_PORT =  PORT ;
  12   var LOWEST _PRIORITY  = 1000;
  13  
  14   var CRLF =  new Buffe r([0x0d, 0 x0a]);
  15  
  16   /*
  17   This class  emits:
  18       connec t
  19       error
  20       close
  21   */
  22   function B eanstalkCl ient(logge r, host, p ort, maxLi steners) {
  23       if (!( this insta nceof Bean stalkClien t)) {
  24           re turn new B eanstalkCl ient(logge r, host, p ort, maxLi steners);
  25       }
  26  
  27       this.l ogger = lo gger;
  28       this.l ogger.debu g('beansta lk-client. BeanstalkC lient(): h ost port % s:%s', hos t, port);
  29       events .EventEmit ter.call(t his);
  30  
  31       this.s tream = nu ll;
  32       this.h andlers =  [];
  33       this.b uffer = un defined;
  34       this.h ost = host  ? host :  DEFAULT_HO ST;
  35       this.p ort = port  ? port :  DEFAULT_PO RT;
  36  
  37       this.s etMaxListe ners(maxLi steners ||  500);
  38   }
  39   util.inher its(Beanst alkClient,  events.Ev entEmitter );
  40  
  41   BeanstalkC lient.prot otype.conn ect = func tion(callb ack) {
  42       this.l ogger.debu g('beansta lk-client. connect');
  43       var se lf = this;
  44       var tm p;
  45  
  46       this.l ogger.trac e('beansta lk-client. connect():  connectin g host por t %s:%s',  self.host,  self.port );
  47  
  48       self.s tream = ne t.createCo nnection(s elf.port,  self.host) ;
  49  
  50       self.s tream.on(' data', fun ction(data ) {
  51           if  (!self.bu ffer) {
  52                self.buf fer = data ;
  53           }  else {
  54                tmp = ne w Buffer(s elf.buffer .length +  data.lengt h);
  55                self.buf fer.copy(t mp, 0);
  56                data.cop y(tmp, sel f.buffer.l ength);
  57                self.buf fer = tmp;
  58           }
  59  
  60           se lf._tryHan dlingRespo nse();
  61       });
  62  
  63       //hand le callbac k
  64       self.s tream.on(' connect',  onSuccessf ulConnecti on);
  65       self.s tream.on(' error', on FailedConn ection);
  66  
  67       functi on onSucce ssfulConne ction() {
  68           se lf.logger. trace('bea nstalk-cli ent.onSucc essfulConn ection():  successful ly connect ed');
  69  
  70           se lf.stream. removeList ener('conn ect', onSu ccessfulCo nnection);
  71           se lf.stream. removeList ener('erro r', onFail edConnecti on);
  72  
  73           se lf.emit('c onnect');
  74  
  75           se lf.stream. on('connec t', functi on() {
  76                self.log ger.debug( 'beanstalk -client.on Successful Connection (): Beanst alkClient  emit conne ct');
  77                self.emi t('connect ');
  78           }) ;
  79  
  80           se lf.stream. on('error' , function (err) {
  81                self.log ger.debug( 'beanstalk -client.on Successful Connection (): Beanst alkClient  emit error ');
  82                self.emi t('error',  err);
  83           }) ;
  84  
  85           se lf.stream. on('close' , function (err) {
  86                self.log ger.debug( 'beanstalk -client.on Successful Connection (): Beanst alkClient  emit close ');
  87                self.emi t('close',  err);
  88           }) ;
  89  
  90           if  (callback ) {
  91                self.log ger.debug( 'beanstalk -client.on Successful Connection (): Beanst alkClient  letting co nsumer kno w of conne ction');
  92                callback ();
  93           }
  94       }
  95  
  96       functi on onFaile dConnectio n(err) {
  97           se lf.logger. debug('bea nstalk-cli ent.onFail edConnecti on() conne ction fail ure %s:%s  -> %j', se lf.host, s elf.port,  err);
  98           se lf.logger. warn('%j',  err);
  99           se lf.stream. removeList ener('conn ect', onSu ccessfulCo nnection);
  100           se lf.stream. removeList ener('erro r', onFail edConnecti on);
  101  
  102           if  (callback ) {
  103                callback (err);
  104           }
  105       }
  106   };
  107  
  108   BeanstalkC lient.prot otype.end  = function (callback)  {
  109       this.l ogger.debu g('beansta lk-client. end()');
  110       if (th is.stream)  {
  111           th is.stream. end();
  112           th is.stream  = null;
  113       }
  114  
  115       if (ca llback) {
  116           ca llback();
  117       }
  118   };
  119  
  120   // Beansta lkClient.p rototype._ tryHandlin gResponse  = function () {
  121   //     thi s.logger.t race('bean stalk-clie nt._tryHan dlingRespo nse()');
  122  
  123   //     whi le (true)  {
  124   //          // Peek a t the olde st handler  in our li st and see  if if thi nks it's d one.
  125   //          var lates t = _.firs t(this.han dlers);
  126   //          if (!late st) {
  127   //              break ;
  128   //          }
  129  
  130   //          var handl er = lates t.handler;
  131   //          var callb ack = late st.callbac k;
  132  
  133   //          if ((hand ler !== un defined) & & (handler  !== null) ) {
  134   //              this. buffer = h andler.pro cess(this. buffer);
  135   //              if (h andler.com plete) {
  136   //                  / / shift it  off & res et
  137   //                  t his.handle rs.shift() ;
  138   //                  i f (handler .success)  {
  139   //                       callbac k.call.app ly(callbac k, [null,  null].conc at(handler .args));
  140   //                  }  else {
  141   //                       callbac k.call(nul l, _.first (handler.a rgs));
  142   //                  }
  143   //              } els e {
  144   //                  h andler.res et();
  145   //                  b reak;
  146   //              }
  147   //          } else {
  148   //              break ;
  149   //          }
  150   //     }
  151   // };
  152  
  153   /*
  154   Fixed Vers ion
  155   */
  156   BeanstalkC lient.prot otype._try HandlingRe sponse = f unction()  {
  157       this.l ogger.trac e('beansta lk-client. _tryHandli ngResponse ()');
  158  
  159       while  (true) {
  160           //  Peek at t he oldest  handler in  our list  and see if  if thinks  it's done .
  161           va r latest =  _.first(t his.handle rs);
  162           if  (!latest)  {
  163                break;
  164           }
  165  
  166           va r handler  = latest.h andler;
  167           va r callback  = latest. callback;
  168  
  169           if  ((handler  !== undef ined) && ( handler != = null)) {
  170                this.buf fer = hand ler.proces s(this.buf fer);
  171                if (hand ler.comple te) {
  172                    // s hift it of f & reset
  173                    this .handlers. shift();
  174                    if ( handler.su ccess) {
  175                         callback.c all.apply( callback,  [null, nul l].concat( handler.ar gs));
  176                    } el se {
  177                         callback.c all(null,  _.first(ha ndler.args ));
  178                    }
  179  
  180                    if ( typeof han dler.remai nder !== ' undefined' ) {
  181                         this.buffe r = handle r.remainde r;
  182                    }
  183                } else {
  184                    hand ler.reset( );
  185                    brea k;
  186                }
  187           }  else {
  188                break;
  189           }
  190       }
  191   };
  192  
  193  
  194   // Impleme nting the  beanstalkd  interface .
  195   function m akeBeansta lkCommand( command, e xpectedRes ponse, sen dsData) {
  196  
  197       // Com mands are  called as  client.COM MAND(arg1,  arg2, ...  data, cal lback);
  198       // The y're sent  to beansta lkd as: CO MMAND arg1  arg2 ...
  199       // fol lowed by d ata.
  200       // So  we slice t he callbac k & data f rom the pa ssed-in ar guments, p repend
  201       // the  command,  then send  the arglis t otherwis e intact.
  202       // We  then push  a handler  for the ex pected res ponse onto  our handl er stack.
  203       // Som e commands  have no a rgs, just  a callback  (stats, s tats-tube,  etc);
  204       // Tha t's the ca se handled  when args  < 2.
  205       return  function( args, data , callback ) {
  206           th is.logger. trace('bea nstalk-cli ent.%s(%j) ', command , args ||  '');
  207           va r buffer;
  208           va r params =  _.toArray (arguments );
  209  
  210           ca llback = p arams.pop( );
  211           da ta = undef ined;
  212  
  213           pa rams.unshi ft(command );
  214           if  (sendsDat a) {
  215                data = p arams.pop( );
  216                if (!Buf fer.isBuff er(data))  {
  217                    data  = new Buf fer(data);
  218                }
  219                params.p ush(data.l ength);
  220           }
  221  
  222           th is.logger. trace('bea nstalk-cli ent.%s():  Adding Res ponse Hand ler to sta ck with pa rams: %s,  expectedRe sponse: %s ', command , params,  expectedRe sponse);
  223           th is.handler s.push({
  224                handler:  new Respo nseHandler (this.logg er, expect edResponse ),
  225                callback : callback
  226           }) ;
  227  
  228           if  (data) {
  229                buffer =  Buffer.co ncat([new  Buffer(par ams.join('  ')), CRLF , data, CR LF]);
  230           }  else {
  231                buffer =  Buffer.co ncat([new  Buffer(par ams.join('  ')), CRLF ]);
  232           }
  233  
  234           th is.stream. write(buff er);
  235       };
  236   }
  237  
  238  
  239   // beansta lkd comman ds
  240  
  241   // use(tub ename, cal lback)
  242   BeanstalkC lient.prot otype.use  = makeBean stalkComma nd('use',  'USING');
  243  
  244   // put(pri ority, del aySecs, tt rSecs, job , callback )
  245   BeanstalkC lient.prot otype.put  = makeBean stalkComma nd('put',  'INSERTED' , true);
  246  
  247   // watch(p riority, d elaySecs,  ttrSecs, j ob, callba ck)
  248   BeanstalkC lient.prot otype.watc h = makeBe anstalkCom mand('watc h', 'WATCH ING');
  249  
  250   // ignore( priority,  delaySecs,  ttrSecs,  job, callb ack)
  251   BeanstalkC lient.prot otype.igno re = makeB eanstalkCo mmand('ign ore', 'WAT CHING');
  252  
  253   // reserve (callback)
  254   BeanstalkC lient.prot otype.rese rve = make BeanstalkC ommand('re serve', 'R ESERVED');
  255  
  256   // reserve _with_time out(timeou tSecs, cal lback) whe re:
  257   // callbac k is: func tion (erro r, beansta lkJobId, b eanstalkJo bPayload)
  258   BeanstalkC lient.prot otype.rese rve_with_t imeout = m akeBeansta lkCommand( 'reserve-w ith-timeou t', 'RESER VED');
  259  
  260   // destroy (beanstalk JobId, cal lback)
  261   BeanstalkC lient.prot otype.dest roy = make BeanstalkC ommand('de lete', 'DE LETED');
  262  
  263   // release (beanstalk JobId, pri ority, del aySec, cal lback)
  264   BeanstalkC lient.prot otype.rele ase = make BeanstalkC ommand('re lease', 'R ELEASED');
  265  
  266   // bury(be anstalkJob Id, priori ty, callba ck)
  267   BeanstalkC lient.prot otype.bury  = makeBea nstalkComm and('bury' , 'BURIED' );
  268  
  269   // touch(b eanstalkJo bId, callb ack)
  270   BeanstalkC lient.prot otype.touc h = makeBe anstalkCom mand('touc h', 'TOUCH ED');
  271  
  272   // kick(bo und, callb ack)
  273   BeanstalkC lient.prot otype.kick  = makeBea nstalkComm and('kick' , 'KICKED' );
  274  
  275   // kick_jo b(beanstal kJobId, ca llback)
  276   BeanstalkC lient.prot otype.kick _job = mak eBeanstalk Command('k ick-job',  'KICKED');
  277  
  278   // peek(be anstalkJob Id, callba ck)
  279   BeanstalkC lient.prot otype.peek  = makeBea nstalkComm and('peek' , 'FOUND') ;
  280  
  281   // peek_re ady(callba ck)
  282   BeanstalkC lient.prot otype.peek _ready = m akeBeansta lkCommand( 'peek-read y', 'FOUND ');
  283  
  284   // peek_de layed(call back)
  285   BeanstalkC lient.prot otype.peek _delayed =  makeBeans talkComman d('peek-de layed', 'F OUND');
  286  
  287   // peek_bu ried(callb ack)
  288   BeanstalkC lient.prot otype.peek _buried =  makeBeanst alkCommand ('peek-bur ied', 'FOU ND');
  289  
  290   // list_tu be_used(ca llback)
  291   BeanstalkC lient.prot otype.list _tube_used  = makeBea nstalkComm and('list- tube-used' , 'USING') ;
  292  
  293   // pause_t ube(tubena me, delayS ecs, callb ack)
  294   BeanstalkC lient.prot otype.paus e_tube = m akeBeansta lkCommand( 'pause-tub e', 'PAUSE D');
  295  
  296   // the ser ver return s yaml fil es in resp onse to th ese comman ds:
  297  
  298   // list_tu bes(callba ck)
  299   BeanstalkC lient.prot otype.list _tubes = m akeBeansta lkCommand( 'list-tube s', 'OK');
  300  
  301   // list_tu bes_watche d(callback )
  302   BeanstalkC lient.prot otype.list _tubes_wat ched = mak eBeanstalk Command('l ist-tubes- watched',  'OK');
  303  
  304   // stats(c allback)
  305   BeanstalkC lient.prot otype.stat s = makeBe anstalkCom mand('stat s', 'OK');
  306  
  307   // stats_j ob(beansta lkJobId, c allback)
  308   BeanstalkC lient.prot otype.stat s_job = ma keBeanstal kCommand(' stats-job' , 'OK');
  309  
  310   // stats_t ube(tubena me, callba ck)
  311   BeanstalkC lient.prot otype.stat s_tube = m akeBeansta lkCommand( 'stats-tub e', 'OK');
  312  
  313   // quit()
  314   //Beanstal kClient.pr ototype.qu it = makeB eanstalkCo mmand('qui t', '');
  315  
  316   // end bea nstalkd co mmands
  317  
  318   module.exp orts = Bea nstalkClie nt;
  319   BeanstalkC lient.LOWE ST_PRIORIT Y = LOWEST _PRIORITY;
  320   BeanstalkC lient._mak eBeanstalk Command =  makeBeanst alkCommand ;