Skip to content

Commit

Permalink
Merge pull request #70 from ba-st/66-Allow-to-configure-session-pool
Browse files Browse the repository at this point in the history
Make configurable session pooling options
  • Loading branch information
gcotelli authored Dec 16, 2021
2 parents 9aeaa93 + bdb0c61 commit 92d9d93
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 13 deletions.
8 changes: 7 additions & 1 deletion docs/Getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ There is 3 different ways of instantiating a provider:

- `InMemoryRepositoryProvider new`
- `RDBMSRepositoryProvider usingSingleSessionWith: aLogin`
- `RDBMSRepositoryProvider using: aLogin`
- `RDBMSRepositoryProvider usingSessionPoolWith: aLogin configuredBy: configurationAction`.

Valid options for the session pooling configuration are:

- `maxIdleSessionsCount` defaulting to 10
- `minIdleSessionsCount` defaulting to 5
- `maxActiveSessionsCount` defaulting to 12

Concretely, the complete algorithm to start a project with persistence using
Sagan is:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,14 @@ PooledRDBMSRepositoryProviderTest >> setUp [
{ #category : #initialization }
PooledRDBMSRepositoryProviderTest >> setUpRepositoryWith: aConflictCheckingStrategy [

provider := RDBMSRepositoryProvider using: SingleSessionRDMBSRepositoryTest login.
provider := RDBMSRepositoryProvider
usingSessionPoolWith:
SingleSessionRDMBSRepositoryTest login
configuredBy: [ :options |
options
at: #maxIdleSessionsCount put: 8;
at: #minIdleSessionsCount put: 4;
at: #maxActiveSessionsCount put: 10 ].
extraterrestrials := provider
createRepositoryStoringObjectsOfType: Extraterrestrial
checkingConflictsAccordingTo: aConflictCheckingStrategy.
Expand Down
19 changes: 11 additions & 8 deletions source/Sagan-RDBMS/PooledRDBMSSessionProvider.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ Class {
}

{ #category : #'instance creation' }
PooledRDBMSSessionProvider class >> loginWith: aLogin [
PooledRDBMSSessionProvider class >> loginWith: aLogin configuredBy: aBlock [

^ self new initializeLoginWith: aLogin
| options |
options := Dictionary new.
aBlock cull: options.
^ self new initializeLoginWith: aLogin configuredBy: options
]

{ #category : #'private-accessing' }
Expand Down Expand Up @@ -73,17 +76,17 @@ PooledRDBMSSessionProvider >> initializeConfigurationSession [
]

{ #category : #initialization }
PooledRDBMSSessionProvider >> initializeLoginWith: aLogin [
PooledRDBMSSessionProvider >> initializeLoginWith: aLogin configuredBy: options [

login := aLogin.
descriptorSystem := ConfigurableDescriptorSystem new.
descriptorSystemWasCopied := false.
self initializeConfigurationSession.
self initializeWorkingSessionsPool
self initializeWorkingSessionsPoolConfiguredBy: options
]

{ #category : #initialization }
PooledRDBMSSessionProvider >> initializeWorkingSessionsPool [
PooledRDBMSSessionProvider >> initializeWorkingSessionsPoolConfiguredBy: options [

descriptorsBySession := Dictionary new.
sessionPool := OPBasicPool new.
Expand All @@ -93,9 +96,9 @@ PooledRDBMSSessionProvider >> initializeWorkingSessionsPool [
validator: #isLoggedIn;
passivator: #reset;
activator: [ :session | self configureDescriptorSystemTo: session ];
maxIdleObjects: 10;
minIdleObjects: 5;
maxActiveObjects: 12
maxIdleObjects: (options at: #maxIdleSessionsCount ifAbsent: [ 10 ]);
minIdleObjects: (options at: #minIdleSessionsCount ifAbsent: [ 5 ]);
maxActiveObjects: (options at: #maxActiveSessionsCount ifAbsent: [ 12 ])
]

{ #category : #accessing }
Expand Down
2 changes: 1 addition & 1 deletion source/Sagan-RDBMS/RDBMSMappingConfiguration.class.st
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Class {
#name : #RDBMSMappingConfiguration,
#superclass : #Object,
#category : #'Sagan-RDBMS'
#category : #'Sagan-RDBMS-Mappings'
}

{ #category : #applying }
Expand Down
6 changes: 4 additions & 2 deletions source/Sagan-RDBMS/RDBMSRepositoryProvider.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ RDBMSRepositoryProvider class >> obtainingSessionFrom: aSessionProvider [
]

{ #category : #'instance creation' }
RDBMSRepositoryProvider class >> using: aLogin [
RDBMSRepositoryProvider class >> usingSessionPoolWith: aLogin configuredBy: configurationAction [

^ self obtainingSessionFrom: ( PooledRDBMSSessionProvider loginWith: aLogin )
^ self obtainingSessionFrom: (PooledRDBMSSessionProvider
loginWith: aLogin
configuredBy: configurationAction)
]

{ #category : #'instance creation' }
Expand Down

0 comments on commit 92d9d93

Please sign in to comment.