Class: Net::SSH::Multi::PendingConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/net/ssh/multi/pending_connection.rb

Overview

A PendingConnection instance mimics a Net::SSH::Connection::Session instance, without actually being an open connection to a server. It is used by Net::SSH::Multi::Session when a concurrent connection limit is in effect, so that a server can hang on to a “connection” that isn’t really a connection.

Any requests against this connection (like #open_channel or #send_global_request) are not actually sent, but are added to a list of recordings. When the real session is opened and replaces this pending connection, all recorded actions will be replayed against that session.

You’ll never need to initialize one of these directly, and (if all goes well!) should never even notice that one of these is in use. Net::SSH::Multi::Session will instantiate these as needed, and only when there is a concurrent connection limit.

Defined Under Namespace

Classes: ChannelOpenRecording, SendGlobalRequestRecording

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ PendingConnection

Instantiates a new pending connection for the given Net::SSH::Multi::Server object.



52
53
54
55
# File 'lib/net/ssh/multi/pending_connection.rb', line 52

def initialize(server)
  @server = server
  @recordings = []
end

Instance Attribute Details

#serverObject (readonly)

The Net::SSH::Multi::Server object that “owns” this pending connection.



48
49
50
# File 'lib/net/ssh/multi/pending_connection.rb', line 48

def server
  @server
end

Instance Method Details

#busy?(include_invisible = false) ⇒ Boolean

Always returns true, so that the pending connection looks active until it can be truly opened and replaced with a real connection.

Returns:

  • (Boolean)


82
83
84
# File 'lib/net/ssh/multi/pending_connection.rb', line 82

def busy?(include_invisible=false)
  true
end

#channelsObject

Returns an empty array, since a pending connection cannot have any real channels.



92
93
94
# File 'lib/net/ssh/multi/pending_connection.rb', line 92

def channels
  []
end

#closeObject

Does nothing, except to make a pending connection quack like a real connection.



87
88
89
# File 'lib/net/ssh/multi/pending_connection.rb', line 87

def close
  self
end

#listenersObject

Returns an empty hash, since a pending connection has no real listeners.



107
108
109
# File 'lib/net/ssh/multi/pending_connection.rb', line 107

def listeners
  {}
end

#open_channel(type = "session", *extras, &on_confirm) ⇒ Object

Records that a channel open request has been made, and returns a new Net::SSH::Multi::ChannelProxy object to represent the (as yet unopened) channel.



67
68
69
70
71
# File 'lib/net/ssh/multi/pending_connection.rb', line 67

def open_channel(type="session", *extras, &on_confirm)
  channel = ChannelProxy.new(&on_confirm)
  @recordings << ChannelOpenRecording.new(type, extras, channel)
  return channel
end

#postprocess(readers, writers) ⇒ Object

Returns true, and does nothing else.



102
103
104
# File 'lib/net/ssh/multi/pending_connection.rb', line 102

def postprocess(readers, writers)
  true
end

#preprocessObject

Returns true, and does nothing else.



97
98
99
# File 'lib/net/ssh/multi/pending_connection.rb', line 97

def preprocess
  true
end

#replace_with(session) ⇒ Object

Instructs the pending session to replay all of its recordings against the given session, and to then replace itself with the given session.



59
60
61
62
# File 'lib/net/ssh/multi/pending_connection.rb', line 59

def replace_with(session)
  @recordings.each { |recording| recording.replay_on(session) }
  @server.replace_session(session)
end

#send_global_request(type, *extra, &callback) ⇒ Object

Records that a global request has been made. The request is not actually sent, and won’t be until #replace_with is called.



75
76
77
78
# File 'lib/net/ssh/multi/pending_connection.rb', line 75

def send_global_request(type, *extra, &callback)
  @recordings << SendGlobalRequestRecording.new(type, extra, callback)
  self
end