Skip to content

Commit

Permalink
Rename ensure to assert in messages that only checks something and ra…
Browse files Browse the repository at this point in the history
…ise error
  • Loading branch information
jvanecek committed Aug 30, 2024
1 parent aca79e7 commit f87db1e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
16 changes: 8 additions & 8 deletions source/Ansible-Protocol-Core/AmqpChannelHandler.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ Class {
#package : 'Ansible-Protocol-Core'
}

{ #category : 'handling' }
AmqpChannelHandler >> assertChannelOpen [

closeReason notNil
ifTrue: [ AmqpDisconnectedError signal: 'Channel closed' ]
]

{ #category : 'accessing' }
AmqpChannelHandler >> channelNumber [

Expand Down Expand Up @@ -67,13 +74,6 @@ AmqpChannelHandler >> dispatchCommand [
self resetState
]

{ #category : 'handling' }
AmqpChannelHandler >> ensureOpen [

closeReason notNil
ifTrue: [ AmqpDisconnectedError signal: 'Channel closed' ]
]

{ #category : 'handling' }
AmqpChannelHandler >> handleBodyFrame: frame [

Expand Down Expand Up @@ -167,7 +167,7 @@ AmqpChannelHandler >> waitForReply: acceptableReplies [
[ i > inbound size ] whileTrue: [
| currentConnection |

self ensureOpen.
self assertChannelOpen.
currentConnection := connection mainLoopCycle.
currentConnection
whenConnected: [ ]
Expand Down
40 changes: 20 additions & 20 deletions source/Ansible-Protocol-Core/AmqpConnection.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ AmqpConnection class >> to: aHostname
extraProperties: aClientPropertyCollection
]

{ #category : 'connection-handling' }
AmqpConnection >> assertChannelOpen: channelNumber [

self assertSocketConnected.
^ ( channels at: channelNumber ) assertChannelOpen
]

{ #category : 'connection-handling' }
AmqpConnection >> assertSocketConnected [

( socket isConnected and: [ socket isOtherEndClosed not ] ) ifFalse: [
AmqpDisconnectedError signal: 'Connection closed' ].

^ true
]

{ #category : 'connection-handling' }
AmqpConnection >> becomeCloseAfter: aBlock [

Expand Down Expand Up @@ -106,7 +122,7 @@ AmqpConnection >> createChannel [

| handler |

self ensureOpen.
self assertSocketConnected.
handler := AmqpChannelHandler new connection: self.
^ AmqpChannel using: handler
]
Expand All @@ -117,22 +133,6 @@ AmqpConnection >> credentials [
^ credentials
]

{ #category : 'connection-handling' }
AmqpConnection >> ensureChannel: channelNumber [

self ensureOpen.
^ ( channels at: channelNumber ) ensureOpen
]

{ #category : 'connection-handling' }
AmqpConnection >> ensureOpen [

( socket isConnected and: [ socket isOtherEndClosed not ] ) ifFalse: [
AmqpDisconnectedError signal: 'Connection closed' ].

^ true
]

{ #category : 'connection-handling' }
AmqpConnection >> handleConnectionClose: cmd [

Expand Down Expand Up @@ -347,7 +347,7 @@ AmqpConnection >> rpc: aRequestMethod onChannel: aChannelNumber ifConnectionClos

^ [
| ch |
ch := self ensureChannel: aChannelNumber.
ch := self assertChannelOpen: aChannelNumber.
self sendMethod: aRequestMethod onChannel: aChannelNumber.
ch waitForReply: aRequestMethod acceptableResponseClasses
]
Expand Down Expand Up @@ -395,7 +395,7 @@ AmqpConnection >> sendMethod: aMethod properties: aProperties body: aByteArray o

| pos |

self ensureChannel: channelNumber.
self assertChannelOpen: channelNumber.
self
sendFrame:
( AmqpMethodFrame new
Expand Down Expand Up @@ -483,7 +483,7 @@ AmqpConnection >> virtualHost [
{ #category : 'connection-handling' }
AmqpConnection >> waitForEvent [

[ self ensureOpen ] whileTrue: [ self mainLoopCycle ]
[ self assertSocketConnected ] whileTrue: [ self mainLoopCycle ]
]

{ #category : 'connection-handling' }
Expand Down

0 comments on commit f87db1e

Please sign in to comment.