@@ -53,6 +53,7 @@ type backend struct {
53
53
wrLock sync.Mutex
54
54
suppliedBookmarks map [string ]neo4j.Bookmarks
55
55
consumedBookmarks map [string ]struct {}
56
+ bookmarkManagers map [string ]neo4j.BookmarkManager
56
57
}
57
58
58
59
// To implement transactional functions a bit of extra state is needed on the
@@ -83,6 +84,7 @@ func newBackend(rd *bufio.Reader, wr io.Writer) *backend {
83
84
recordedErrors : make (map [string ]error ),
84
85
resolvedAddresses : make (map [string ][]any ),
85
86
id : 0 ,
87
+ bookmarkManagers : make (map [string ]neo4j.BookmarkManager ),
86
88
suppliedBookmarks : make (map [string ]neo4j.Bookmarks ),
87
89
consumedBookmarks : make (map [string ]struct {}),
88
90
}
@@ -448,9 +450,6 @@ func (b *backend) handleRequest(req map[string]any) {
448
450
if data ["connectionTimeoutMs" ] != nil {
449
451
c .SocketConnectTimeout = time .Millisecond * time .Duration (asInt64 (data ["connectionTimeoutMs" ].(json.Number )))
450
452
}
451
- if data ["bookmarkManager" ] != nil {
452
- c .BookmarkManager = neo4j .NewBookmarkManager (b .bookmarkManagerConfig (data ["bookmarkManager" ].(map [string ]any )))
453
- }
454
453
})
455
454
if err != nil {
456
455
b .writeError (err )
@@ -516,14 +515,35 @@ func (b *backend) handleRequest(req map[string]any) {
516
515
if data ["impersonatedUser" ] != nil {
517
516
sessionConfig .ImpersonatedUser = data ["impersonatedUser" ].(string )
518
517
}
519
- if data ["ignoreBookmarkManager" ] != nil {
520
- sessionConfig .IgnoreBookmarkManager = data ["ignoreBookmarkManager" ].(bool )
518
+ if data ["bookmarkManagerId" ] != nil {
519
+ bmmId := data ["bookmarkManagerId" ].(string )
520
+ bookmarkManager := b .bookmarkManagers [bmmId ]
521
+ if bookmarkManager == nil {
522
+ b .writeError (fmt .Errorf ("could not find bookmark manager with ID %s" , bmmId ))
523
+ return
524
+ }
525
+ sessionConfig .BookmarkManager = bookmarkManager
521
526
}
522
527
session := driver .NewSession (ctx , sessionConfig )
523
528
idKey := b .nextId ()
524
529
b .sessionStates [idKey ] = & sessionState {session : session }
525
530
b .writeResponse ("Session" , map [string ]any {"id" : idKey })
526
531
532
+ case "NewBookmarkManager" :
533
+ bookmarkManagerId := b .nextId ()
534
+ b .bookmarkManagers [bookmarkManagerId ] = neo4j .NewBookmarkManager (
535
+ b .bookmarkManagerConfig (bookmarkManagerId , data ))
536
+ b .writeResponse ("BookmarkManager" , map [string ]any {
537
+ "id" : bookmarkManagerId ,
538
+ })
539
+
540
+ case "BookmarkManagerClose" :
541
+ bookmarkManagerId := data ["id" ].(string )
542
+ delete (b .bookmarkManagers , bookmarkManagerId )
543
+ b .writeResponse ("BookmarkManager" , map [string ]any {
544
+ "id" : bookmarkManagerId ,
545
+ })
546
+
527
547
case "SessionClose" :
528
548
sessionId := data ["sessionId" ].(string )
529
549
sessionState := b .sessionStates [sessionId ]
@@ -1076,50 +1096,59 @@ func patchNumbersInMap(dictionary map[string]any) error {
1076
1096
return nil
1077
1097
}
1078
1098
1079
- func (b * backend ) bookmarkManagerConfig (config map [string ]any ) neo4j.BookmarkManagerConfig {
1099
+ func (b * backend ) bookmarkManagerConfig (bookmarkManagerId string ,
1100
+ config map [string ]any ) neo4j.BookmarkManagerConfig {
1101
+
1080
1102
var initialBookmarks map [string ]neo4j.Bookmarks
1081
1103
if config ["initialBookmarks" ] != nil {
1082
1104
initialBookmarks = convertInitialBookmarks (config ["initialBookmarks" ].(map [string ]any ))
1083
1105
}
1084
1106
result := neo4j.BookmarkManagerConfig {InitialBookmarks : initialBookmarks }
1085
1107
supplierRegistered := config ["bookmarksSupplierRegistered" ]
1086
1108
if supplierRegistered != nil && supplierRegistered .(bool ) {
1087
- result .BookmarkSupplier = & testkitBookmarkSupplier {supplierFn : b .supplyBookmarks }
1109
+ result .BookmarkSupplier = & testkitBookmarkSupplier {
1110
+ supplierFn : b .supplyBookmarks (bookmarkManagerId ),
1111
+ }
1088
1112
}
1089
1113
consumerRegistered := config ["bookmarksConsumerRegistered" ]
1090
1114
if consumerRegistered != nil && consumerRegistered .(bool ) {
1091
- result .BookmarkUpdateNotifier = b .consumeBookmarks
1115
+ result .BookmarkUpdateNotifier = b .consumeBookmarks ( bookmarkManagerId )
1092
1116
}
1093
1117
return result
1094
1118
}
1095
1119
1096
- func (b * backend ) supplyBookmarks (databases ... string ) neo4j.Bookmarks {
1097
- if len (databases ) > 1 {
1098
- panic ("at most 1 database should be specified" )
1099
- }
1100
- id := b .nextId ()
1101
- msg := map [string ]any {"id" : id }
1102
- if len (databases ) == 1 {
1103
- msg ["database" ] = databases [0 ]
1104
- }
1105
- b .writeResponse ("BookmarksSupplierRequest" , msg )
1106
- for {
1107
- b .process ()
1108
- return b .suppliedBookmarks [id ]
1120
+ func (b * backend ) supplyBookmarks (bookmarkManagerId string ) func (... string ) neo4j.Bookmarks {
1121
+ return func (databases ... string ) neo4j.Bookmarks {
1122
+ if len (databases ) > 1 {
1123
+ panic ("at most 1 database should be specified" )
1124
+ }
1125
+ id := b .nextId ()
1126
+ msg := map [string ]any {"id" : id , "bookmarkManagerId" : bookmarkManagerId }
1127
+ if len (databases ) == 1 {
1128
+ msg ["database" ] = databases [0 ]
1129
+ }
1130
+ b .writeResponse ("BookmarksSupplierRequest" , msg )
1131
+ for {
1132
+ b .process ()
1133
+ return b .suppliedBookmarks [id ]
1134
+ }
1109
1135
}
1110
1136
}
1111
1137
1112
- func (b * backend ) consumeBookmarks (database string , bookmarks neo4j.Bookmarks ) {
1113
- id := b .nextId ()
1114
- b .writeResponse ("BookmarksConsumerRequest" , map [string ]any {
1115
- "id" : id ,
1116
- "database" : database ,
1117
- "bookmarks" : bookmarks ,
1118
- })
1119
- for {
1120
- b .process ()
1121
- if _ , found := b .consumedBookmarks [id ]; found {
1122
- return
1138
+ func (b * backend ) consumeBookmarks (bookmarkManagerId string ) func (string , neo4j.Bookmarks ) {
1139
+ return func (database string , bookmarks neo4j.Bookmarks ) {
1140
+ id := b .nextId ()
1141
+ b .writeResponse ("BookmarksConsumerRequest" , map [string ]any {
1142
+ "id" : id ,
1143
+ "bookmarkManagerId" : bookmarkManagerId ,
1144
+ "database" : database ,
1145
+ "bookmarks" : bookmarks ,
1146
+ })
1147
+ for {
1148
+ b .process ()
1149
+ if _ , found := b .consumedBookmarks [id ]; found {
1150
+ return
1151
+ }
1123
1152
}
1124
1153
}
1125
1154
}
0 commit comments