Module: FFWD::TCP
- Defined in:
- lib/ffwd/protocol/tcp/connection.rb,
lib/ffwd/protocol/tcp.rb,
lib/ffwd/protocol/tcp/bind.rb,
lib/ffwd/protocol/tcp/plain_connect.rb,
lib/ffwd/protocol/tcp/flushing_connect.rb
Overview
$LICENSE Copyright 2013-2014 Spotify AB. All rights reserved.
The contents of this file are licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Defined Under Namespace
Classes: Bind, Connection, FlushingConnect, PlainConnect
Constant Summary collapse
- DEFAULT_OUTBOUND_LIMIT =
default amount of bytes that the outbound connection will allow in its application-level buffer.
2 ** 20
- DEFAULT_FLUSH_PERIOD =
default flush period, if non-zero will cause the connection to be buffered.
10- DEFAULT_EVENT_LIMIT =
defaults for buffered connections. maximum amount of events to buffer up.
1000- DEFAULT_METRIC_LIMIT =
maximum amount of metrics to buffer up.
10000- DEFAULT_FLUSH_LIMIT =
percent of maximum events/metrics which will cause a flush.
0.8- DEFAULT_REBIND_TIMEOUT =
Default initial timeout when binding fails.
10
Class Method Summary collapse
-
.bind(opts, core, log, connection, *args) ⇒ Object
Bind and listen for a TCP connection.
-
.connect(opts, core, log, handler, *args) ⇒ Object
Establish an outbound tcp connection.
- .family ⇒ Object
-
.tunnel(opts, core, plugin, log, connection, *args) ⇒ Object
Set up a TCP tunnel.
Class Method Details
.bind(opts, core, log, connection, *args) ⇒ Object
Bind and listen for a TCP connection.
opts - Option hash.
:host - The host to bind to.
:port - The port to bind to.
:rebind_timeout - The initial timeout to use when rebinding the
connection.
core - The core interface associated with this connection. log - The logger to use for this connection. connection - An implementation of FFWD::Connection containing the connection logic. args - Arguments passed to the connection when a new instance is created.
106 107 108 109 110 111 |
# File 'lib/ffwd/protocol/tcp.rb', line 106 def self.bind opts, core, log, connection, *args raise "Missing required option :host" if (host = opts[:host]).nil? raise "Missing required option :port" if (port = opts[:port]).nil? rebind_timeout = opts[:rebind_timeout] || DEFAULT_REBIND_TIMEOUT Bind.new core, log, host, port, connection, args, rebind_timeout end |
.connect(opts, core, log, handler, *args) ⇒ Object
Establish an outbound tcp connection.
opts - Option hash.
Expects the following keys.
:host - The host to connect to.
:port - The port to connect to.
:outbound_limit - The amount of bytes that are allowed to be pending in
the application level buffer for the connection to be considered
'writable'.
:flush_period - The period in which outgoing data is buffered. If this
is 0 no buffering will occur.
Reads the following keys if the connection is buffered.
:event_limit - The maximum amount of events the connection is allowed
to buffer up.
:metric_limimt - The maximum amount of metrics the connection is
allowed to buffer up.
:flush_limit - A percentage (0.0 - 1.0) indicating 'the percentage of
events/metrics' that is required for a flush to be forced.
If this percentage is reached, the connection will attempt to forcibly
flush all buffered events and metrics prior to the end of the flushing
period.
core - The core interface associated with this connection. log - The logger to use for this connection. handler - An implementation of FFWD::Handler containing the connection logic. args - Arguments passed to the handler when a new instance is created.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ffwd/protocol/tcp.rb', line 71 def self.connect opts, core, log, handler, *args raise "Missing required option :host" if (host = opts[:host]).nil? raise "Missing required option :port" if (port = opts[:port]).nil? outbound_limit = opts[:outbound_limit] || DEFAULT_OUTBOUND_LIMIT flush_period = opts[:flush_period] || DEFAULT_FLUSH_PERIOD connection = Connection.new log, host, port, handler, args, outbound_limit if flush_period == 0 PlainConnect.new core, log, connection else event_limit = opts[:event_limit] || DEFAULT_EVENT_LIMIT metric_limit = opts[:metric_limit] || DEFAULT_METRIC_LIMIT flush_limit = opts[:flush_limit] || DEFAULT_FLUSH_LIMIT FlushingConnect.new( core, log, connection, flush_period, event_limit, metric_limit, flush_limit ) end end |
.family ⇒ Object
26 27 28 |
# File 'lib/ffwd/protocol/tcp.rb', line 26 def self.family :tcp end |
.tunnel(opts, core, plugin, log, connection, *args) ⇒ Object
Set up a TCP tunnel.
opts - Option hash.
:port - The port to bind to on the remote side.
core - The core interface associated with this connection. log - The logger to use for this connection. connection - An implementation of FFWD::Connection containing the connection logic. args - Arguments passed to the connection when a new instance is created.
122 123 124 125 |
# File 'lib/ffwd/protocol/tcp.rb', line 122 def self.tunnel opts, core, plugin, log, connection, *args raise "Missing required option :port" if (port = opts[:port]).nil? FFWD.tunnel self.family, port, core, plugin, log, connection, args end |