Skip to content

Commit

Permalink
JsonRPCController instances are now transient
Browse files Browse the repository at this point in the history
  • Loading branch information
ytsejam78 committed Apr 12, 2024
1 parent 9557e2f commit 9baf8da
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 42 deletions.
8 changes: 5 additions & 3 deletions source/BaselineOfStargate/BaselineOfStargate.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ BaselineOfStargate >> baseline: spec [
<baseline>
spec for: #pharo do: [
spec postLoadDoIt:
#configureResourceRESTfulControllerInstancesAsTransient.
#configureControllerInstancesAsTransient.
self
setUpDependencies: spec;
setUpPackages: spec.
Expand All @@ -23,9 +23,11 @@ BaselineOfStargate >> baseline: spec [
]

{ #category : 'baselines' }
BaselineOfStargate >> configureResourceRESTfulControllerInstancesAsTransient [
BaselineOfStargate >> configureControllerInstancesAsTransient [

ResourceRESTfulController makeInstancesDbTransient
{
ResourceRESTfulController.
JsonRPCController } do: #makeInstancesDbTransient
]

{ #category : 'accessing' }
Expand Down
19 changes: 10 additions & 9 deletions source/Stargate-JSON-RPC/JRPCSelfContainedBlockHandler.class.st
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
Class {
#name : #JRPCSelfContainedBlockHandler,
#superclass : #JRPCMessageSendHandler,
#name : 'JRPCSelfContainedBlockHandler',
#superclass : 'JRPCMessageSendHandler',
#instVars : [
'argumentNames'
],
#category : #'Stargate-JSON-RPC'
#category : 'Stargate-JSON-RPC',
#package : 'Stargate-JSON-RPC'
}

{ #category : #'instance creation' }
{ #category : 'instance creation' }
JRPCSelfContainedBlockHandler class >> forProcedureNamed: aString withArgumentNames: argumentNames evaluating: aBlock [

AssertionChecker enforce: [ aBlock argumentCount = argumentNames size ]
Expand All @@ -17,7 +18,7 @@ JRPCSelfContainedBlockHandler class >> forProcedureNamed: aString withArgumentNa
^ self new initializeForProcedureNamed: aString withArgumentNames: argumentNames evaluating: aBlock
]

{ #category : #evaluation }
{ #category : 'evaluation' }
JRPCSelfContainedBlockHandler >> executeWithArguments: anArrayOrDictionary [

| arguments |
Expand All @@ -31,7 +32,7 @@ JRPCSelfContainedBlockHandler >> executeWithArguments: anArrayOrDictionary [
^ self send: self messageSelector to: self receiver with: arguments
]

{ #category : #initialization }
{ #category : 'initialization' }
JRPCSelfContainedBlockHandler >> initializeForProcedureNamed: aString withArgumentNames: theArgumentNames evaluating: aBlock [

self
Expand All @@ -40,19 +41,19 @@ JRPCSelfContainedBlockHandler >> initializeForProcedureNamed: aString withArgume
argumentNames := theArgumentNames collect: #asString
]

{ #category : #accessing }
{ #category : 'accessing' }
JRPCSelfContainedBlockHandler >> messageSelector [

^ #valueWithArguments:
]

{ #category : #accessing }
{ #category : 'accessing' }
JRPCSelfContainedBlockHandler >> parametersNames [

^ argumentNames
]

{ #category : #private }
{ #category : 'private' }
JRPCSelfContainedBlockHandler >> send: aSelector to: aBlock with: arguments [

^ super send: aSelector to: aBlock with: ( Array with: arguments )
Expand Down
39 changes: 23 additions & 16 deletions source/Stargate-JSON-RPC/JsonRPCController.class.st
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
Class {
#name : #JsonRPCController,
#superclass : #Object,
#name : 'JsonRPCController',
#superclass : 'Object',
#instVars : [
'requestHandler',
'procedureDefinitions'
],
#category : #'Stargate-JSON-RPC'
#category : 'Stargate-JSON-RPC',
#package : 'Stargate-JSON-RPC',
#'gs_options' : [
'dbTransient'
]
}

{ #category : #'instance creation' }
{ #category : 'instance creation' }
JsonRPCController class >> configuredBy: configurationAction [

| options |
Expand All @@ -18,42 +22,45 @@ JsonRPCController class >> configuredBy: configurationAction [
^ self with: options
]

{ #category : #'instance creation' }
{ #category : 'instance creation' }
JsonRPCController class >> with: options [

^self new initializeWith: options
]

{ #category : #configuring }
{ #category : 'configuring' }
JsonRPCController >> configureAvailableProcedures [

procedureDefinitions do: [ :definition | definition value: requestHandler ]
]

{ #category : #accessing }
{ #category : 'accessing' }
JsonRPCController >> endpoint [

^ self requestHandler endpoint
]

{ #category : #initialization }
{ #category : 'initialization' }
JsonRPCController >> initializeWith: options [

procedureDefinitions := options at: #procedureDefinitions.
requestHandler := JsonRPCRequestHandler handling: ( options at: #endpoint ).
options at: #debugMode ifPresent: [ :boolean | requestHandler debugMode: boolean ].
options at: #errorHandlers
ifPresent: [ :handlers |
handlers do: [ :errorHandler | requestHandler addErrorHandler: errorHandler ] ]
requestHandler := JsonRPCRequestHandler handling:
(options at: #endpoint).
options
at: #debugMode
ifPresent: [ :boolean | requestHandler debugMode: boolean ].
options at: #errorHandlers ifPresent: [ :handlers |
handlers do: [ :errorHandler |
requestHandler addErrorHandler: errorHandler ] ]
]

{ #category : #accessing }
{ #category : 'accessing' }
JsonRPCController >> requestHandler [

^ requestHandler
]

{ #category : #accessing }
{ #category : 'accessing' }
JsonRPCController >> routes [

^ Array with: ( RouteSpecification handling: #POST
Expand All @@ -62,7 +69,7 @@ JsonRPCController >> routes [
requestHandler process: httpRequest within: requestContext ] )
]

{ #category : #configuring }
{ #category : 'configuring' }
JsonRPCController >> serverUrl: aServerUrl [

requestHandler serverUrl: aServerUrl.
Expand Down
27 changes: 14 additions & 13 deletions source/Stargate-JSON-RPC/JsonRPCRequestHandler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,54 @@
I represent a JSON RPC request handler. I'm capable of processing RPC calls.
"
Class {
#name : #JsonRPCRequestHandler,
#superclass : #Object,
#name : 'JsonRPCRequestHandler',
#superclass : 'Object',
#instVars : [
'messageProcessor',
'acceptNegotiator',
'resourceLocator'
],
#category : #'Stargate-JSON-RPC'
#category : 'Stargate-JSON-RPC',
#package : 'Stargate-JSON-RPC'
}

{ #category : #'instance creation' }
{ #category : 'instance creation' }
JsonRPCRequestHandler class >> handling: anEndpoint [

^ self new initializeResolvingLocationWith: ( ResourceLocator handling: anEndpoint )
]

{ #category : #configuring }
{ #category : 'configuring' }
JsonRPCRequestHandler >> addErrorHandler: anErrorHandler [

messageProcessor addErrorHandler: anErrorHandler
]

{ #category : #configuring }
{ #category : 'configuring' }
JsonRPCRequestHandler >> addHandlerNamed: aString evaluating: aBlock [

messageProcessor addHandlerNamed: aString block: aBlock
]

{ #category : #configuring }
{ #category : 'configuring' }
JsonRPCRequestHandler >> addHandlerNamed: aString withArgumentNames: argumentNames evaluating: aBlock [

messageProcessor addHandlerNamed: aString withArgumentsNamed: argumentNames evaluating: aBlock
]

{ #category : #configuring }
{ #category : 'configuring' }
JsonRPCRequestHandler >> debugMode: aBoolean [

messageProcessor debugMode: aBoolean
]

{ #category : #accessing }
{ #category : 'accessing' }
JsonRPCRequestHandler >> endpoint [

^ resourceLocator endpoint
]

{ #category : #initialization }
{ #category : 'initialization' }
JsonRPCRequestHandler >> initialize [

super initialize.
Expand All @@ -57,13 +58,13 @@ JsonRPCRequestHandler >> initialize [
accepting: ( Array with: ZnMimeType applicationJson )
]

{ #category : #initialization }
{ #category : 'initialization' }
JsonRPCRequestHandler >> initializeResolvingLocationWith: aResourceLocator [

resourceLocator := aResourceLocator
]

{ #category : #API }
{ #category : 'API' }
JsonRPCRequestHandler >> process: httpRequest within: requestContext [

AssertionChecker
Expand All @@ -77,7 +78,7 @@ JsonRPCRequestHandler >> process: httpRequest within: requestContext [
ifNotEmpty: [ :rpcResponse | ZnResponse ok: ( ZnEntity json: rpcResponse ) ]
]

{ #category : #configuring }
{ #category : 'configuring' }
JsonRPCRequestHandler >> serverUrl: aServerUrl [

resourceLocator baseUrl: aServerUrl
Expand Down
2 changes: 1 addition & 1 deletion source/Stargate-JSON-RPC/package.st
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Package { #name : #'Stargate-JSON-RPC' }
Package { #name : 'Stargate-JSON-RPC' }

0 comments on commit 9baf8da

Please sign in to comment.