コード例 #1
0
ファイル: cal.js プロジェクト: radhikakhetan/prp
function Transformer(options) {
    Transformer.super_.apply(this);
    options = options || {};

    this._state = Transformer.State.DISCONNECT;
    this._connRetryCounter = 0;
    this._delayStart = DEFAULT_DELAY_START;

    var tconf = nconf && nconf.get('cal') || {};

    this._port = tconf.port || options.port || 1118;
    if (resolvedHost) {
        this._host = resolvedHost;
    } else {
        this._host = 'localhost';
        if (!deployEnv._env) {
            if (connectionTester.test(this._host, this._port).success) {
                resolvedHost = this._host;
            } else {
                this._host = tconf.host || options.host || this._host;
                debug('localhost caldaemon connection test failed, switching to %s host', this._host);
            }
        } else {
            resolvedHost = this._host;
        }
        if (!resolvedHost && connectionTester.test(this._host, this._port).success) {
            resolvedHost = this._host;
        } else {
            debug('%s connection test failed', this._host);
        }
    }

    this._environment = options.environment || 'PayPal';
    this._poolname    = options.poolname || apputil.getAppName() || constants.UNSET;
    this._buildLabel  = options.buildLabel || apputil.getBuildVersion() || constants.UNSET;
    this._buildLabel  = this._buildLabel + ';***;' + constants.PLATFORM;
    this._tryReconnect = true;
    this._connectionTimeout = options.timeout || DEFAULT_CONNECTION_TIMEOUT;

    this.on('finish', this._onEnd.bind(this));
}
コード例 #2
0
ファイル: app.js プロジェクト: rafaelc0sta/lopc-node
// Test connection to Apple

var ascii = require('./lib/ascii');

ascii();

var connectionTester = require('connection-tester');

var connectionTest = connectionTester.test('gateway.push.apple.com', 2195)

if (connectionTest.success == false) {
  console.log("\nWARNING: Could not reach Apple's Push Gateway.");
  console.log("WARNING: Check if port 2195 (outbound) is open.");
  console.log();
  console.log();
}

global.config = require('konfig')();

require('./lib/mongo')();

// Setup Webserver:

var express = require('express');
var Web = require('./lib/web');
var Authentication = require('./middleware/authentication');
var Logger = require('./middleware/logger');
var Preflight = require('./middleware/preflight');
// var git = require('./lib/git');

global.app = express();
コード例 #3
0
	    keepWampAlive = setInterval(function(){
	      
	      
		//NEW type of connection tester
		connectionTester.test(wampIP, 8888, 1000, function (err, output) {
		  
		    //logger.debug("[WAMP-STATUS] - CONNECTION STATUS: "+JSON.stringify(output));
		    
		    var reachable = output.success;
		    var error_test = output.error;
		    
		    //logger.debug("[WAMP-STATUS] - CONNECTION STATUS: "+reachable);
		    
		    if(!reachable){
		      
			  logger.warn("[CONNECTION-RECOVERY] - INTERNET CONNECTION STATUS: "+reachable+ " - ERROR: "+error_test);
			  wamp_check = false;
			  online=false;
		      
		    } else {
			    
			    try{
		      
				    if(!online){
				      
					logger.info("[CONNECTION-RECOVERY] - INTERNET CONNECTION STATUS: "+reachable);
					logger.info("[CONNECTION-RECOVERY] - INTERNET CONNECTION RECOVERED!");

					session.publish ('board.connection', [ 'alive-'+boardCode ], {}, { acknowledge: true}).then(
							    
					      function(publication) {
						      logger.info("[WAMP-ALIVE-STATUS] - WAMP ALIVE MESSAGE RESPONSE: published -> publication ID is " + JSON.stringify(publication));
						      wamp_check = true;
						      
					      },
					      function(error) {
						      logger.warn("[WAMP-RECOVERY] - WAMP ALIVE MESSAGE: publication error " + JSON.stringify(error));
						      wamp_check = false;
					      }
														    
					);	
					
					//It will wait the WAMP alive message response
					setTimeout(function(){
					
					    if (wamp_check){
					      
						// WAMP CONNECTION IS OK
					      
						logger.info("[WAMP-ALIVE-STATUS] - WAMP CONNECTION STATUS: " + wamp_check);
						online=true;
						
					    }
					    else{
					      
						  // WAMP CONNECTION IS NOT ESTABLISHED
					      
						  logger.warn("[WAMP-ALIVE-STATUS] - WAMP CONNECTION STATUS: " + wamp_check);
						  
						  // Check if the tcpkill process was killed after a previous connection recovery 
						  // Through this check we will avoid to start another tcpkill process
						  var tcpkill_status = running(tcpkill_pid);
						  logger.warn("[WAMP-ALIVE-STATUS] - TCPKILL STATUS: " + tcpkill_status + " - PID: " +tcpkill_pid);
						  
						  
						  //at LR startup "tcpkill_pid" is NULL and in this condition "is-running" module return "true" that is a WRONG result!
						  if (tcpkill_status === false || tcpkill_pid == null){ 
						  
							logger.warn("[WAMP-RECOVERY] - Cleaning WAMP socket...");
							
							var tcpkill_kill_count = 0;
							
							var spawn = require('child_process').spawn;
				      
							//tcpkill -9 port 8181
							var tcpkill = spawn('tcpkill',['-9','port','8181']); 
							
							tcpkill.stdout.on('data', function (data) {
							    logger.debug('[WAMP-RECOVERY] ... tcpkill stdout: ' + data);
							});
							
							tcpkill.stderr.on('data', function (data) {
							  
							    logger.debug('[WAMP-RECOVERY] ... tcpkill stderr:\n' + data);
							    
						    
							    if(data.toString().indexOf("listening") > -1){
							      
								// LISTENING
								// To manage the starting of tcpkill (listening on port 8181)
								logger.debug('[WAMP-RECOVERY] ... tcpkill listening...');
							      
								tcpkill_pid = tcpkill.pid;
								logger.debug('[WAMP-RECOVERY] ... tcpkill -9 port 8181 - PID ['+tcpkill_pid+']');
								
								
							    }else if (data.toString().indexOf("win 0") > -1){
							      
								// TCPKILL DETECT WAMP ACTIVITY (WAMP reconnection attempts)
								// This is the stage triggered when the WAMP socket was killed by tcpkill and wamp reconnection process automaticcally started:
								// in this phase we need to kill tcpkill to allow wamp reconnection.
								tcpkill.kill('SIGINT');
								
								//double check: It will test after a while if the tcpkill process has been killed
								setTimeout(function(){  
								  
								    if (running(tcpkill_pid || tcpkill_pid == null)){

									    tcpkill_kill_count = tcpkill_kill_count + 1;
									    
									    logger.warn("[WAMP-RECOVERY] ... tcpkill still running!!! PID ["+tcpkill_pid+"]");
									    logger.debug('[WAMP-RECOVERY] ... tcpkill killing retry_count '+ tcpkill_kill_count);
									    
									    tcpkill.kill('SIGINT');
					  
								    }
				    
								}, 3000);
							      
							    }
							    
							    
							});
		    
							
							tcpkill.on('close', function (code) {
							  
							    logger.debug('[WAMP-RECOVERY] ... tcpkill killed!');
							    logger.info("[WAMP-RECOVERY] - WAMP socket cleaned!");
							    
							    online=true;
							    
							});
							
							
							//online=true;
						  
						  }else{
						    
							logger.warn('[WAMP-RECOVERY] ...tcpkill already started!');
						    
						  }
						  
					    }
					
					
					
					
					}, 2 * 1000);  //time to wait WAMP alive message response
					
				    }

			      
			    }
			    catch(err){
				    logger.warn('[CONNECTION-RECOVERY] - Error keeping alive wamp connection: '+ err);
			    }
				  
		    }
		    
		});

		

	    }, 10 * 1000);