Class: Qpid::Proton::Handler::EndpointStateHandler

Inherits:
BaseHandler
  • Object
show all
Defined in:
lib/handler/endpoint_state_handler.rb

Overview

A utility that exposes endpoint events; i.e., the open/close of a link, session or connection, in a more intuitive manner.

A XXX_opened method will be called when both local and remote peers have opened the link, session or connection. This can be used to confirm a locally initiated action for example.

A XXX_opening method will be called when the remote peer has requested an open that was not initiated locally. By default this will simply open locally, which then trigtgers the XXX_opened called.

The same applies to close.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseHandler

#on_unhandled

Constructor Details

#initialize(peer_close_is_error = false, delegate = nil) ⇒ EndpointStateHandler

Returns a new instance of EndpointStateHandler.



37
38
39
40
# File 'lib/handler/endpoint_state_handler.rb', line 37

def initialize(peer_close_is_error = false, delegate = nil)
  @delegate = delegate
  @peer_close_is_error = peer_close_is_error
end

Class Method Details



42
43
44
45
46
47
# File 'lib/handler/endpoint_state_handler.rb', line 42

def self.print_error(endpoint, endpoint_type)
  if !endpoint.remote_condition.nil?
  elsif self.local_endpoint?(endpoint) && endpoint.remote_closed?
    logging.error("#{endpoint_type} closed by peer")
  end
end

Instance Method Details

#on_connection_closed(event) ⇒ Object



171
172
173
# File 'lib/handler/endpoint_state_handler.rb', line 171

def on_connection_closed(event)
  Qpid::Proton::Event.dispatch(@delegate, :on_connection_closed, event) if !@delegate.nil?
end

#on_connection_closing(event) ⇒ Object



183
184
185
186
187
188
189
# File 'lib/handler/endpoint_state_handler.rb', line 183

def on_connection_closing(event)
  if !@delegate.nil?
    Qpid::Proton::Event.dispatch(@delegate, :on_connection_closing, event)
  elsif @peer_close_is_error
    self.on_connection_error(event)
  end
end

#on_connection_error(event) ⇒ Object



145
146
147
148
149
150
151
# File 'lib/handler/endpoint_state_handler.rb', line 145

def on_connection_error(event)
  if !@delegate.nil?
    Qpid::Proton::Event.dispatch(@delegate, :on_connection_error, event)
  else
    self.log_error(event.connection, "connection")
  end
end

#on_connection_local_open(event) ⇒ Object



82
83
84
# File 'lib/handler/endpoint_state_handler.rb', line 82

def on_connection_local_open(event)
  self.on_connection_opened(event) if event.connection.remote_active?
end

#on_connection_opened(event) ⇒ Object



121
122
123
# File 'lib/handler/endpoint_state_handler.rb', line 121

def on_connection_opened(event)
  Qpid::Proton::Event.dispatch(@delegate, :on_session_opened, event) if !@delegate.nil?
end

#on_connection_opening(event) ⇒ Object



133
134
135
# File 'lib/handler/endpoint_state_handler.rb', line 133

def on_connection_opening(event)
  Qpid::Proton::Event.dispatch(@delegate, :on_connection_opening, event) if !@delegate.nil?
end

#on_connection_remote_close(event) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/handler/endpoint_state_handler.rb', line 71

def on_connection_remote_close(event)
  if !event.connection.remote_condition.nil?
    self.on_connection_error(event)
  elsif event.connection.local_closed?
    self.on_connection_closed(event)
  else
    self.on_connection_closing(event)
  end
  event.connection.close
end

#on_connection_remote_open(event) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/handler/endpoint_state_handler.rb', line 86

def on_connection_remote_open(event)
  if !(event.connection.state & Qpid::Proton::Endpoint::LOCAL_ACTIVE).zero?
    self.on_connection_opened(event)
  elsif event.connection.local_uninit?
    self.on_connection_opening(event)
    event.connection.open
  end
end


179
180
181
# File 'lib/handler/endpoint_state_handler.rb', line 179

def on_link_closed(event)
  Qpid::Proton::Event.dispatch(@delegate, :on_link_closed, event) if !@delegate.nil?
end


199
200
201
202
203
204
205
# File 'lib/handler/endpoint_state_handler.rb', line 199

def on_link_closing(event)
  if !@delegate.nil?
    Qpid::Proton::Event.dispatch(@delegate, :on_link_closing, event)
  elsif @peer_close_is_error
    self.on_link_error(event)
  end
end


162
163
164
165
166
167
168
169
# File 'lib/handler/endpoint_state_handler.rb', line 162

def on_link_error(event)
  if !@delegate.nil?
    Qpid::Proton::Event.dispatch(@delegate, :on_link_error, event)
  else
    self.log_error(event.link, "link")
    event.conneciton.close
  end
end


108
109
110
# File 'lib/handler/endpoint_state_handler.rb', line 108

def on_link_local_open(event)
  self.on_link_opened(event) if event.link.remote_active?
end


129
130
131
# File 'lib/handler/endpoint_state_handler.rb', line 129

def on_link_opened(event)
  Qpid::Proton::Event.dispatch(@delegate, :on_link_opened, event) if !@delegate.nil?
end


141
142
143
# File 'lib/handler/endpoint_state_handler.rb', line 141

def on_link_opening(event)
  Qpid::Proton::Event.dispatch(@delegate, :on_link_opening, event) if !@delegate.nil?
end


49
50
51
52
53
54
55
56
57
58
# File 'lib/handler/endpoint_state_handler.rb', line 49

def on_link_remote_close(event)
  if !event.link.remote_condition.nil?
    self.on_link_error(event)
  elsif event.link.local_closed?
    self.on_link_closed(event)
  else
    self.on_link_closing(event)
  end
  event.link.close
end


112
113
114
115
116
117
118
119
# File 'lib/handler/endpoint_state_handler.rb', line 112

def on_link_remote_open(event)
  if !(event.link.state & Qpid::Proton::Endpoint::LOCAL_ACTIVE).zero?
    self.on_link_opened(event)
  elsif event.link.local_uninit?
    self.on_link_opening(event)
    event.link.open
  end
end

#on_session_closed(event) ⇒ Object



175
176
177
# File 'lib/handler/endpoint_state_handler.rb', line 175

def on_session_closed(event)
  Qpid::Proton::Event.dispatch(@delegate, :on_session_closed, event) if !@delegate.nil?
end

#on_session_closing(event) ⇒ Object



191
192
193
194
195
196
197
# File 'lib/handler/endpoint_state_handler.rb', line 191

def on_session_closing(event)
  if !@delegate.nil?
    Qpid::Proton::Event.dispatch(@delegate, :on_session_closing, event)
  elsif @peer_close_is_error
    self.on_session_error(event)
  end
end

#on_session_error(event) ⇒ Object



153
154
155
156
157
158
159
160
# File 'lib/handler/endpoint_state_handler.rb', line 153

def on_session_error(event)
  if !@delegate.nil?
    Qpid::Proton::Event.dispatch(@delegate, :on_session_error, event)
  else
    self.log_error(event.session, "session")
    event.connection.close
  end
end

#on_session_local_open(event) ⇒ Object



95
96
97
# File 'lib/handler/endpoint_state_handler.rb', line 95

def on_session_local_open(event)
  self.on_session_opened(event) if event.session.remote_active?
end

#on_session_opened(event) ⇒ Object



125
126
127
# File 'lib/handler/endpoint_state_handler.rb', line 125

def on_session_opened(event)
  Qpid::Proton::Event.dispatch(@delegate, :on_session_opened, event) if !@delegate.nil?
end

#on_session_opening(event) ⇒ Object



137
138
139
# File 'lib/handler/endpoint_state_handler.rb', line 137

def on_session_opening(event)
  Qpid::Proton::Event.dispatch(@delegate, :on_session_opening, event) if !@delegate.nil?
end

#on_session_remote_close(event) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/handler/endpoint_state_handler.rb', line 60

def on_session_remote_close(event)
  if !event.session.remote_condition.nil?
    self.on_session_error(event)
  elsif event.session.local_closed?
    self.on_session_closed(event)
  else
    self.on_session_closing(event)
  end
  event.session.close
end

#on_session_remote_open(event) ⇒ Object



99
100
101
102
103
104
105
106
# File 'lib/handler/endpoint_state_handler.rb', line 99

def on_session_remote_open(event)
  if !(event.session.state & Qpid::Proton::Endpoint::LOCAL_ACTIVE).zero?
    self.on_session_opened(event)
  elsif event.session.local_uninit?
    self.on_session_opening(event)
    event.session.open
  end
end

#on_transport_closed(event) ⇒ Object



211
212
213
# File 'lib/handler/endpoint_state_handler.rb', line 211

def on_transport_closed(event)
  Qpid::Proton::Event.dispatch(@delegate, :on_disconnected, event) if !@delegate.nil?
end

#on_transport_tail_closed(event) ⇒ Object



207
208
209
# File 'lib/handler/endpoint_state_handler.rb', line 207

def on_transport_tail_closed(event)
  self.on_transport_closed(event)
end