Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

New connection Pooler #50

Closed
wants to merge 5 commits into from

1 participant

@e11137

Hi,
I have remade my pooler.
this version doesn't duplicate connection functions and you can use it this with multiple requests.

Regards

@e11137

I appologize the mistake, it's a duplicate of my last pull request :S
#43

@e11137 e11137 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 25, 2012
  1. add pool connection to tedious

    rcanedo authored
  2. remove debug log

    rcanedo authored
Commits on Jul 27, 2012
  1. add deps to package.json

    rcanedo authored
Commits on Sep 21, 2012
  1. Merge remote branch 'upstream/master'

    rcanedo authored
This page is out of date. Refresh to see the latest.
View
3  package.json
@@ -33,7 +33,8 @@
"dependencies": {
"async": "0.1.22",
"iconv-lite": "0.2.1",
- "sprintf": "0.1.1"
+ "sprintf": "0.1.1",
+ "generic-pool": "2.0.1"
},
"devDependencies": {
"coffee-script": "1.3.3",
View
34 src/connection-Pooler.coffee
@@ -0,0 +1,34 @@
+PoolModule = require('generic-pool')
+Connection = require('./connection')
+
+class ConnectionPooler
+
+ constructor: (config) ->
+ _this = this
+ param =
+ name: config.name
+ create: (callback) ->
+ connection = new Connection(config)
+ connection.on('connect', (err) ->
+ console.log('connected')
+ if !err
+ callback(null, connection)
+ connection.on('reusable', () ->
+ _this.pool.release(connection)
+ )
+ )
+ destroy: (client) ->
+ client.close()
+ max: config.max
+ idleTimeoutMillis : config.idleTimeoutMillis
+ @pool = PoolModule.Pool(param);
+
+ execute: (callback) ->
+ @pool.acquire((err, connection) ->
+ if(err)
+ console.log(err)
+ else
+ callback(connection)
+ )
+
+module.exports = ConnectionPooler
View
10 src/connection.coffee
@@ -113,23 +113,28 @@ class Connection extends EventEmitter
LOGGED_IN:
name: 'LoggedIn'
+ enter: ->
+ if @reusable
+ @emit('reusable')
events:
socketError: (error) ->
@transitionTo(@STATE.FINAL)
SENT_CLIENT_REQUEST:
name: 'SentClientRequest'
+ exit:->
+ @reusable = true
events:
socketError: (error) ->
@transitionTo(@STATE.FINAL)
data: (data) ->
@sendDataToTokenStreamParser(data)
message: ->
- @transitionTo(@STATE.LOGGED_IN)
-
sqlRequest = @request
@request = undefined
sqlRequest.callback(sqlRequest.error, sqlRequest.rowCount)
+
+ @transitionTo(@STATE.LOGGED_IN)
FINAL:
name: 'Final'
@@ -142,6 +147,7 @@ class Connection extends EventEmitter
# Do nothing, as the timer should be cleaned up.
constructor: (@config) ->
+ @reusable = false
@defaultConfig()
@createDebug()
@createTokenStreamParser()
View
1  src/tedious.coffee
@@ -1,6 +1,7 @@
exports.statemachineLogLevel = 0
exports.Connection = require('./connection')
+exports.ConnectionPooler = require('./connection-Pooler')
exports.Request = require('./request')
exports.library = require('./library')
exports.TYPES = require('./data-type').typeByName
Something went wrong with that request. Please try again.