Class: Marvin::Distributed::Client

Inherits:
AbstractClient show all
Defined in:
lib/marvin/distributed/client.rb

Defined Under Namespace

Classes: EMConnection, RemoteClientProxy

Instance Attribute Summary collapse

Attributes inherited from AbstractClient

#channels, #connection_config, #disconnect_expected, #nickname, #nicks, #pass, #port, #server

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractClient

#action, #command, configuration=, configure, #default_channels, #default_channels=, #dispatch, #handle_client_connected, #handle_incoming_error, #handle_incoming_join, #handle_incoming_numeric, #handle_incoming_ping, #handle_nick_taken, #handle_welcome, #host_with_port, #join, #msg, #nick, #part, #pong, #process_connect, #process_development, #process_disconnect, #quit, #receive_line, setup, setup?

Constructor Details

#initialize(em_connection) ⇒ Client

Returns a new instance of Client.



177
178
179
# File 'lib/marvin/distributed/client.rb', line 177

def initialize(em_connection)
  @em_connection = em_connection
end

Instance Attribute Details

#em_connectionObject

Returns the value of attribute em_connection.



10
11
12
# File 'lib/marvin/distributed/client.rb', line 10

def em_connection
  @em_connection
end

#remote_client_hostObject

Returns the value of attribute remote_client_host.



10
11
12
# File 'lib/marvin/distributed/client.rb', line 10

def remote_client_host
  @remote_client_host
end

#remote_client_nickObject

Returns the value of attribute remote_client_nick.



10
11
12
# File 'lib/marvin/distributed/client.rb', line 10

def remote_client_nick
  @remote_client_nick
end

Class Method Details

.runObject



202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/marvin/distributed/client.rb', line 202

def run
  logger.info "Preparing to start distributed client"
  EventMachine.kqueue
  EventMachine.epoll
  EventMachine.run do
    opts = Marvin::Settings.distributed || Marvin::Nash.new
    opts = opts.client || Marvin::Nash.new
    host = opts.host  || "0.0.0.0"
    port = (opts.port || 8943).to_i
    EMConnection.connect(host, port, opts)
  end
end

.stopObject



215
216
217
218
219
# File 'lib/marvin/distributed/client.rb', line 215

def stop
  logger.info "Stopping distributed client..."
  EMConnection.stopping = true
  EventMachine.stop_event_loop
end

Instance Method Details

#remote_clientObject



181
182
183
# File 'lib/marvin/distributed/client.rb', line 181

def remote_client
  @remote_client ||= RemoteClientProxy.new(@em_connection, @remote_client_host, @remote_client_nick)
end

#reset!Object



185
186
187
188
189
190
# File 'lib/marvin/distributed/client.rb', line 185

def reset!
  @remote_client = nil
  @remote_client_nick = nil
  @remote_client_host = nil
  reset_handlers
end

#reset_handlersObject



196
197
198
# File 'lib/marvin/distributed/client.rb', line 196

def reset_handlers
  self.class.handlers.each { |h| h.client = nil if h.respond_to?(:client=) }
end

#setup_handlersObject



192
193
194
# File 'lib/marvin/distributed/client.rb', line 192

def setup_handlers
  self.class.handlers.each { |h| h.client = remote_client if h.respond_to?(:client=) }
end