Module: FFWD::Plugin::JSON

Includes:
Logging, FFWD::Plugin
Defined in:
lib/ffwd/plugin/json.rb,
lib/ffwd/plugin/json/connection.rb

Defined Under Namespace

Modules: Connection Classes: FrameConnection, LineConnection

Constant Summary collapse

DEFAULT_HOST =
"localhost"
DEFAULT_PORT =
19000
DEFAULT_PROTOCOL =
{"line" => "tcp", "frame" => "udp"}
DEFAULT_KIND =
"line"
KINDS =
{"frame" => FrameConnection, "line" => LineConnection}

Class Method Summary collapse

Methods included from Logging

included, #log

Methods included from FFWD::Plugin

category, discovered, included, load_discovered, load_plugins, loaded, option

Class Method Details

.setup_input(opts, core) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/ffwd/plugin/json.rb', line 82

def self.setup_input opts, core
  kind = (opts[:kind] || DEFAULT_KIND).to_s
  raise "No such kind: #{kind}" unless connection = KINDS[kind]
  protocol = FFWD.parse_protocol opts[:protocol] || DEFAULT_PROTOCOL[kind]
  opts[:host] ||= DEFAULT_HOST
  opts[:port] ||= DEFAULT_PORT

  if connection == FrameConnection and protocol != FFWD::UDP
    log.warning "When using :frame kind, you should use the UDP protocol." +
                " Not #{protocol.family.to_s.upcase}"
  end

  if connection == LineConnection and protocol != FFWD::TCP
    log.warning "When using :line kind, you should use the TCP protocol. " +
                "Not #{protocol.family.to_s.upcase}"
  end

  protocol.bind opts, core, log, connection
end

.setup_tunnel(opts, core, tunnel) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/ffwd/plugin/json.rb', line 102

def self.setup_tunnel opts, core, tunnel
  protocol = FFWD.parse_protocol opts[:protocol] || "tcp"
  kind = (opts[:kind] || DEFAULT_KIND).to_s
  raise "No such kind: #{kind}" unless connection = KINDS[kind]
  opts[:port] ||= DEFAULT_PORT
  protocol.tunnel opts, core, tunnel, log, connection
end