Skip to content

Commit cc476b5

Browse files
authored
Merge pull request #40 from dionisiydk/simplifyRequestSend
Simplify request send logic
2 parents dc18e33 + d592bca commit cc476b5

3 files changed

+16
-32
lines changed

Seamless-Tests/SeamlessPeerIdentificationContextTests.class.st

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ SeamlessPeerIdentificationContextTests >> contextClass [
1515
{ #category : #specs }
1616
SeamlessPeerIdentificationContextTests >> contextShouldSend: aSeamlessRequest [
1717

18-
^connection should takeAWhile to receive sendDataPacket: aSeamlessRequest
18+
^connection should receive sendDataPacket: aSeamlessRequest
1919
]
2020

2121
{ #category : #running }

Seamless-Tests/SeamlessSyncRequestContextTests.class.st

+10-16
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ SeamlessSyncRequestContextTests >> contextClass [
1515
{ #category : #specs }
1616
SeamlessSyncRequestContextTests >> contextShouldSend: aSeamlessRequest [
1717

18-
^receiverPeer should takeAWhile to receive sendDataPacket: aSeamlessRequest
18+
^receiverPeer should receive sendDataPacket: aSeamlessRequest
1919
]
2020

2121
{ #category : #running }
@@ -88,27 +88,25 @@ SeamlessSyncRequestContextTests >> testSendingMessage [
8888
]
8989

9090
{ #category : #tests }
91-
SeamlessSyncRequestContextTests >> testSendingRequestShouldAssignItToContext [
91+
SeamlessSyncRequestContextTests >> testSendingRequest [
9292

9393
| request |
9494
request := Mock new.
95-
95+
9696
context sendRequest: request.
97-
98-
request should receive context: context
97+
98+
self contextShouldSend: request
9999
]
100100

101101
{ #category : #tests }
102-
SeamlessSyncRequestContextTests >> testSendingRequestShouldBeDoneAsynchronous [
102+
SeamlessSyncRequestContextTests >> testSendingRequestShouldAssignItToContext [
103103

104104
| request |
105105
request := Mock new.
106-
106+
107107
context sendRequest: request.
108-
109-
(self contextShouldSend: request) inAnotherProcess
110-
inProcessWhich priority should equal: Processor activeProcess priority.
111-
108+
109+
request should receive context: context
112110
]
113111

114112
{ #category : #tests }
@@ -140,10 +138,6 @@ SeamlessSyncRequestContextTests >> testSendingRequestWhenSendIsFailed [
140138
request := Mock new.
141139
sendFailure := Error new.
142140
(self stubRequestDataSend: request) willRaise: sendFailure.
143-
resultDelivery stub shipResult: Arg result.
144141

145-
context sendRequest: request.
146-
147-
Arg result should takeAWhile to beInstanceOf: SeamlessThrowExceptionResult.
148-
Arg result where exception should be: sendFailure
142+
[context sendRequest: request] should raise: sendFailure
149143
]

Seamless/SeamlessSyncRequestContext.class.st

+5-15
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"
22
I am request context which implements synchronous request sending when senders are waiting result from receiver peer.
3-
To implement this behaviour I fork actual request sending and wait signal from resultWaiter semaphore. I am transfered by reference to receiver peer as part of sent request. On receiver side request executed and result is returned to me by ""backward"" remote message. I receive #return: message which stores argument as result and signal resultWaiter semaphore. Signal resumes original sender process which continue execution with received value.
3+
To implement this behaviour send a request to receiver peer and wait a delivery of result from it.
4+
I am transfered by reference to receiver peer as part of sent request. On receiver side request executed and result is returned to me by SeamlessDeliverResultRequest using same context. At the end I receive #return: message which shifts the argument to the result delivery. Delivery signals the original sender process which continue execution with received value.
45
5-
During request execution receiver peer will keep reference to me. It can be used to retrieved information on receiver side about my sender process.
6+
During request execution the receiver peer will keep reference to me. It can be used to retrieved information on receiver side about my sender process.
67
78
Internal Representation and Key Implementation Points.
89
910
Instance Variables
10-
result: <SeamlessRequestResult>
11-
resultWaiter: <Semaphore>
1211
senderProcess: <Process>
12+
resultDelivery <SeamlessRequestResultDelivery>
1313
"
1414
Class {
1515
#name : #SeamlessSyncRequestContext,
@@ -26,16 +26,6 @@ SeamlessSyncRequestContext >> createSeamlessReference [
2626
^SeamlessRequestContextReference new
2727
]
2828

29-
{ #category : #private }
30-
SeamlessSyncRequestContext >> forkProcessingOf: aSeamlessRequest [
31-
32-
[
33-
[self performRequestSend: aSeamlessRequest] on: Error do: [ :err |
34-
self return: (SeamlessThrowExceptionResult with: err) ]
35-
36-
] forkAt: Processor activePriority named: 'Seamless request sending'
37-
]
38-
3929
{ #category : #private }
4030
SeamlessSyncRequestContext >> performRequestSend: aSeamlessRequest [
4131
receiverPeer sendDataPacket: aSeamlessRequest
@@ -77,7 +67,7 @@ SeamlessSyncRequestContext >> sendRequest: aSeamlessRequest [
7767
aSeamlessRequest context: self.
7868
senderProcess := Processor activeProcess.
7969

80-
self forkProcessingOf: aSeamlessRequest.
70+
self performRequestSend: aSeamlessRequest.
8171

8272
^resultDelivery deliverResultFor: aSeamlessRequest
8373
]

0 commit comments

Comments
 (0)