ripple-hbase-client
Advanced tools
Comparing version 0.1.9-thrift to 0.1.10-thrift
{ | ||
"name": "ripple-hbase-client", | ||
"version": "0.1.9-thrift", | ||
"version": "0.1.10-thrift", | ||
"description": "ripple hbase client", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -144,2 +144,3 @@ const thrift = require('thrift') | ||
function HbaseClient(options) { | ||
const self = this | ||
this._prefix = options.prefix || '' | ||
@@ -169,6 +170,2 @@ this.logStats = (options.logLevel && options.logLevel > 3) ? true : false | ||
const timeout = setTimeout(() => { | ||
reject() | ||
}, options.timeout || 30000) | ||
const connection = thrift.createConnection(server.host, server.port, { | ||
@@ -181,3 +178,2 @@ transport: thrift.TFramedTransport, | ||
connection.once('connect', () => { | ||
clearTimeout(timeout) | ||
connection.connection.setKeepAlive(true) | ||
@@ -193,2 +189,3 @@ connection.client = thrift.createClient(HBase, connection) | ||
connection.on('close', () => { | ||
connection.connected = false | ||
reject() | ||
@@ -198,2 +195,3 @@ }) | ||
connection.on('timeout', () => { | ||
connection.connected = false | ||
reject() | ||
@@ -203,7 +201,10 @@ }) | ||
}, | ||
destroy: client => {} | ||
destroy: client => {}, | ||
validate: client => { | ||
return client.connected | ||
} | ||
} | ||
const params = { | ||
testOnBorrow: false, | ||
testOnBorrow: true, | ||
max: options.max_sockets || 100, | ||
@@ -221,5 +222,17 @@ min: options.min_sockets || 5, | ||
.then(client => { | ||
client.on('error', reject) | ||
client.on('timeout', reject.bind(this, TIMEOUT_MESSAGE)) | ||
client.on('close', reject.bind(this, CLOSE_MESSAGE)) | ||
const onError = reject | ||
const onTimeout = reject.bind(this, TIMEOUT_MESSAGE) | ||
const onClose = reject.bind(this, CLOSE_MESSAGE) | ||
client.on('error', onError) | ||
client.on('timeout', onTimeout) | ||
client.on('close', onClose) | ||
client.onRelease = function() { | ||
client.removeListener('error', onError) | ||
client.removeListener('timeout', onTimeout) | ||
client.removeListener('close', onClose) | ||
} | ||
return client | ||
@@ -230,3 +243,3 @@ }) | ||
HbaseClient.prototype.release = function(client) { | ||
client.removeAllListeners() | ||
client.onRelease() | ||
this.pool.release(client) | ||
@@ -233,0 +246,0 @@ } |
28
test.js
@@ -8,8 +8,12 @@ const Hbase = require('./src/index.js') | ||
host: 'hadoop3-private.wdc01.infra.ripple.com', | ||
//servers: [ | ||
// {host:'hadoop1000-private.wdc01.infra.ripple.com', port:9090}, | ||
// {host:'hadoop1000-private.wdc01.infra.ripple.com', port:9090} | ||
//], | ||
root: '/hbase', | ||
prefix: 'prod_', | ||
logLevel: 2, | ||
max_sockets: 2, | ||
logLevel: 3, | ||
timeout: 5000, | ||
min_sockets: 2, | ||
timeout: 5000 | ||
max_sockets: 2 | ||
}) | ||
@@ -19,5 +23,5 @@ | ||
setInterval(() => { | ||
console.log(++count) | ||
setInterval(check, 10000) | ||
function check() { | ||
hbase.getRow({ | ||
@@ -28,6 +32,3 @@ table: 'control', | ||
.then(console.log) | ||
.catch(function(err) { | ||
console.log('err') | ||
console.log(err) | ||
}) | ||
.catch(console.log) | ||
@@ -39,10 +40,7 @@ | ||
.then(console.log) | ||
.catch(function(err) { | ||
console.log('err') | ||
console.log(err) | ||
}) | ||
.catch(console.log) | ||
} | ||
}, 1000) | ||
check() | ||
process.on('unhandledRejection', error => { | ||
@@ -49,0 +47,0 @@ // Will print "unhandledRejection err is not defined" |
424500
14606