Class: Omega::Server::ProxyNode

Inherits:
Object
  • Object
show all
Defined in:
lib/omega/server/proxy.rb

Overview

Omega Proxy Node, proxies request to a remote omega server, maintaining a session to do so

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ ProxyNode

Returns a new instance of ProxyNode


71
72
73
74
75
76
77
78
79
80
81
# File 'lib/omega/server/proxy.rb', line 71

def initialize(args = {})
  attr_from_args args, :id         => nil,
                       :dst        => nil,
                       :node_id    => nil,
                       :user_id    => nil,
                       :password   => nil,
                       :login_time => nil

  @user = Users::User.new :id => @user_id, :password => @password
  @rjr_node = RJR::Nodes::Easy.node_type_for(dst).new(:node_id => @node_id)
end

Instance Attribute Details

#dstObject

Returns the value of attribute dst


63
64
65
# File 'lib/omega/server/proxy.rb', line 63

def dst
  @dst
end

#idObject

Returns the value of attribute id


60
61
62
# File 'lib/omega/server/proxy.rb', line 60

def id
  @id
end

#login_timeObject

Returns the value of attribute login_time


64
65
66
# File 'lib/omega/server/proxy.rb', line 64

def 
  @login_time
end

#node_idObject

required for attr_from_args below


67
68
69
# File 'lib/omega/server/proxy.rb', line 67

def node_id
  @node_id
end

#passwordObject

XXX


69
70
71
# File 'lib/omega/server/proxy.rb', line 69

def password
  @password
end

#rjr_nodeObject

Returns the value of attribute rjr_node


61
62
63
# File 'lib/omega/server/proxy.rb', line 61

def rjr_node
  @rjr_node
end

#userObject

Returns the value of attribute user


62
63
64
# File 'lib/omega/server/proxy.rb', line 62

def user
  @user
end

#user_idObject

Returns the value of attribute user_id


68
69
70
# File 'lib/omega/server/proxy.rb', line 68

def user_id
  @user_id
end

Class Method Details

.set_config(config) ⇒ Object


41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/omega/server/proxy.rb', line 41

def set_config(config)
  # create nodes for target by 'proxy_to' in config
  @nodes ||=
    config.proxy_to.to_h.collect { |id, opts| # XXX to_h needed,
                                              # see fixme in config class
      ProxyNode.new :id       => id.to_s,
                    :node_id  => config.proxy_node_id,
                    :user_id  => opts[:user_id],
                    :password => opts[:password],
                    :dst      => opts[:dst]
    } if config.proxy_to
end

.with_id(id) ⇒ Object

return node for specified dst


56
57
58
# File 'lib/omega/server/proxy.rb', line 56

def self.with_id(id)
  @nodes ? @nodes.find { |n| n.id == id } : nil
end

Instance Method Details

#invoke(*args) ⇒ Object


92
93
94
# File 'lib/omega/server/proxy.rb', line 92

def invoke(*args)
  @rjr_node.invoke @dst, *args
end

#loginObject


83
84
85
86
87
88
89
90
# File 'lib/omega/server/proxy.rb', line 83

def 
  # unless [email protected]_time.nil? && Time.now - @login_time < SESSION_EXPIRATION TODO - remote session expiration may be different than local
  session = invoke 'users::login', @user
  @rjr_node.message_headers['session_id'] = session.id
  @rjr_node.message_headers['source_node'] = @user.id
  @login_time = Time.now
  self
end

#notify(*args) ⇒ Object


96
97
98
# File 'lib/omega/server/proxy.rb', line 96

def notify(*args)
  @rjr_node.notify @dst, *args
end