Skip to content

Commit 33a5aff

Browse files
Merge branch 'reidmorrison:master' into master
2 parents fd126a4 + 8ed5b42 commit 33a5aff

25 files changed

+513
-389
lines changed

.github/workflows/ci.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: build
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
test:
9+
name: "Test: Ruby ${{ matrix.ruby }}"
10+
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
ruby: [2.7, "3.0", 3.1, 3.2]
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Set up Ruby
18+
uses: ruby/setup-ruby@v1
19+
with:
20+
ruby-version: ${{ matrix.ruby }}
21+
# runs 'bundle install' and caches installed gems automatically
22+
bundler-cache: true
23+
- name: Ruby Version
24+
run: ruby --version
25+
- name: Run Tests
26+
run: bundle exec rake

.rubocop.yml

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
AllCops:
2+
TargetRubyVersion: 2.7
3+
SuggestExtensions: false
4+
NewCops: enable
5+
Exclude:
6+
- ".git/**/*"
7+
- "docs/**/*"
8+
9+
#
10+
# RuboCop built-in settings.
11+
# For documentation on all settings see: https://docs.rubocop.org/en/stable
12+
#
13+
14+
# Trailing periods.
15+
Layout/DotPosition:
16+
EnforcedStyle: trailing
17+
18+
# Turn on auto-correction of equals alignment.
19+
Layout/EndAlignment:
20+
AutoCorrect: true
21+
22+
# Prevent accidental windows line endings
23+
Layout/EndOfLine:
24+
EnforcedStyle: lf
25+
26+
# Use a table layout for hashes
27+
Layout/HashAlignment:
28+
EnforcedHashRocketStyle: table
29+
EnforcedColonStyle: table
30+
31+
# Soften limits
32+
Layout/LineLength:
33+
Max: 128
34+
Exclude:
35+
- "**/test/**/*"
36+
37+
# Match existing layout
38+
Layout/SpaceInsideHashLiteralBraces:
39+
EnforcedStyle: no_space
40+
41+
# TODO: Soften Limits for phase 1 only
42+
Metrics/AbcSize:
43+
Max: 40
44+
45+
# Support long block lengths for tests
46+
Metrics/BlockLength:
47+
Exclude:
48+
- "test/**/*"
49+
- "**/*/cli.rb"
50+
AllowedMethods:
51+
- "aasm"
52+
- "included"
53+
54+
# Soften limits
55+
Metrics/ClassLength:
56+
Max: 250
57+
Exclude:
58+
- "test/**/*"
59+
60+
# TODO: Soften Limits for phase 1 only
61+
Metrics/CyclomaticComplexity:
62+
Max: 15
63+
64+
# Soften limits
65+
Metrics/MethodLength:
66+
Max: 50
67+
68+
# Soften limits
69+
Metrics/ModuleLength:
70+
Max: 250
71+
72+
Metrics/ParameterLists:
73+
CountKeywordArgs: false
74+
75+
# TODO: Soften Limits for phase 1 only
76+
Metrics/PerceivedComplexity:
77+
Max: 21
78+
79+
# Initialization Vector abbreviation
80+
Naming/MethodParameterName:
81+
AllowedNames: ['iv', '_', 'io', 'ap']
82+
83+
# Does not allow Symbols to load
84+
Security/YAMLLoad:
85+
AutoCorrect: false
86+
87+
# Needed for testing DateTime
88+
Style/DateTime:
89+
Exclude: ["test/**/*"]
90+
91+
# TODO: Soften Limits for phase 1 only
92+
Style/Documentation:
93+
Enabled: false
94+
95+
# One line methods
96+
Style/EmptyMethod:
97+
EnforcedStyle: expanded
98+
99+
# Ruby 3 compatibility feature
100+
Style/FrozenStringLiteralComment:
101+
Enabled: false
102+
103+
Style/NumericPredicate:
104+
AutoCorrect: true
105+
106+
# Incorrectly changes job.fail to job.raise
107+
Style/SignalException:
108+
Enabled: false
109+
110+
# Since English may not be loaded, cannot force its use.
111+
Style/SpecialGlobalVars:
112+
Enabled: false
113+
114+
# Make it easier for developers to move between Elixir and Ruby.
115+
Style/StringLiterals:
116+
EnforcedStyle: double_quotes

.ruby-version

-1
This file was deleted.

.travis.yml

-20
This file was deleted.

Gemfile

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
source 'http://rubygems.org'
1+
source "https://rubygems.org"
22

33
gemspec
44

5-
gem 'rake'
6-
gem 'minitest'
7-
gem 'minitest-reporters'
8-
gem 'bson'
9-
gem 'awesome_print'
10-
gem 'semantic_logger'
5+
gem "amazing_print"
6+
gem "bson"
7+
gem "minitest"
8+
gem "minitest-reporters"
9+
gem "rake"
10+
gem "rubocop"
11+
gem "semantic_logger"

README.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# net_tcp_client
2-
[![Gem Version](https://img.shields.io/gem/v/net_tcp_client.svg)](https://rubygems.org/gems/net_tcp_client) [![Build Status](https://travis-ci.org/rocketjob/net_tcp_client.svg?branch=master)](https://travis-ci.org/rocketjob/net_tcp_client) [![Downloads](https://img.shields.io/gem/dt/net_tcp_client.svg)](https://rubygems.org/gems/net_tcp_client) [![License](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg)](http://opensource.org/licenses/Apache-2.0) ![](https://img.shields.io/badge/status-Production%20Ready-blue.svg) [![Gitter chat](https://img.shields.io/badge/IRC%20(gitter)-Support-brightgreen.svg)](https://gitter.im/rocketjob/support)
2+
[![Gem Version](https://img.shields.io/gem/v/net_tcp_client.svg)](https://rubygems.org/gems/net_tcp_client) [![Build Status](https://github.com/reidmorrison/net_tcp_client/workflows/build/badge.svg)](https://github.com/reidmorrison/net_tcp_client/actions?query=workflow%3Abuild) [![Downloads](https://img.shields.io/gem/dt/net_tcp_client.svg)](https://rubygems.org/gems/net_tcp_client) [![License](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg)](http://opensource.org/licenses/Apache-2.0) ![](https://img.shields.io/badge/status-Production%20Ready-blue.svg)
33

44
Net::TCPClient is a TCP Socket Client with automated failover, load balancing, retries and built-in timeouts.
55

6-
* http://github.com/rocketjob/net_tcp_client
6+
* https://github.com/reidmorrison/net_tcp_client
77

88
## Introduction
99

@@ -36,7 +36,7 @@ prevent a network issue from "hanging" the client program.
3636
require 'net/tcp_client'
3737

3838
Net::TCPClient.connect(server: 'mydomain:3300') do |client|
39-
client.send('Update the database')
39+
client.write('Update the database')
4040
response = client.read(20)
4141
puts "Received: #{response}"
4242
end
@@ -48,7 +48,7 @@ Enable SSL encryption:
4848
require 'net/tcp_client'
4949

5050
Net::TCPClient.connect(server: 'mydomain:3300', ssl: true) do |client|
51-
client.send('Update the database')
51+
client.write('Update the database')
5252
response = client.read(20)
5353
puts "Received: #{response}"
5454
end
@@ -104,7 +104,7 @@ Servers are tried in a Random order.
104104
~~~ruby
105105
tcp_client = Net::TCPClient.new(
106106
servers: ['server1:3300', 'server2:3300', 'server3:3600'],
107-
policy: :ordered
107+
policy: :random
108108
)
109109
~~~
110110

@@ -145,15 +145,15 @@ Example run, the servers could be tried in the following order:
145145
If a connection cannot be established to any servers in the list Net::TCPClient will retry from the
146146
first server. This retry behavior can be controlled using the following options:
147147

148-
* `connect_retry_count` [Fixnum]
148+
* `connect_retry_count` [Integer]
149149
* Number of times to retry connecting when a connection fails
150150
* Default: 10
151151

152152
* `connect_retry_interval` [Float]
153153
* Number of seconds between connection retry attempts after the first failed attempt
154154
* Default: 0.5
155155

156-
* `retry_count` [Fixnum]
156+
* `retry_count` [Integer]
157157
* Number of times to retry when calling #retry_on_connection_failure
158158
* This is independent of :connect_retry_count which still applies with
159159
* connection failures. This retry controls upto how many times to retry the
@@ -184,16 +184,16 @@ Net::TCPClient.connect(
184184
connect_retry_interval: 0.1,
185185
connect_retry_count: 5
186186
) do |client|
187-
# If the connection is lost, create a new one and retry the send
187+
# If the connection is lost, create a new one and retry the write
188188
client.retry_on_connection_failure do
189-
client.send('How many users available?')
189+
client.write('How many users available?')
190190
response = client.read(20)
191191
puts "Received: #{response}"
192192
end
193193
end
194194
~~~
195195

196-
If the connection is lost during either the `send` or the `read` above the
196+
If the connection is lost during either the `write` or the `read` above the
197197
entire block will be re-tried once the connection has been re-stablished.
198198

199199
## Callbacks
@@ -210,7 +210,7 @@ Any time a connection has been established a callback can be called to handle ac
210210
tcp_client = Net::TCPClient.new(
211211
servers: ['server1:3300', 'server2:3300', 'server3:3600'],
212212
on_connect: -> do |client|
213-
client.send('My username and password')
213+
client.write('My username and password')
214214
result = client.read(2)
215215
raise "Authentication failed" if result != 'OK'
216216
end
@@ -224,13 +224,13 @@ tcp_client = Net::TCPClient.new(
224224
servers: ['server1:3300', 'server2:3300', 'server3:3600'],
225225
on_connect: -> do |client|
226226
# Set the sequence number to 0
227-
user_data = 0
227+
client.user_data = 0
228228
end
229229
)
230230

231231
tcp_client.retry_on_connection_failure do
232-
# Send with the sequence number
233-
tcp_client.send("#{tcp_client.user_data} hello")
232+
# Write with the sequence number
233+
tcp_client.write("#{tcp_client.user_data} hello")
234234
result = tcp_client.receive(30)
235235

236236
# Increment sequence number after every call to the server
@@ -250,7 +250,7 @@ test on a daily basis, including connections over the internet between remote da
250250

251251
gem install net_tcp_client
252252

253-
To enable logging add [Semantic Logger](http://rocketjob.github.io/semantic_logger):
253+
To enable logging add [Semantic Logger](https://logger.rocketjob.io/):
254254

255255
gem install semantic_logger
256256

@@ -273,13 +273,13 @@ SemanticLogger.default_level = :trace
273273
SemanticLogger.add_appender(file_name: 'development.log', formatter: :color)
274274
~~~
275275

276-
If running Rails, see: [Semantic Logger Rails](http://rocketjob.github.io/semantic_logger/rails.html)
276+
If running Rails, see: [Semantic Logger Rails](https://logger.rocketjob.io/rails.html)
277277

278278
### Support
279279

280280
Join the [Gitter chat session](https://gitter.im/rocketjob/support) if you have any questions.
281281

282-
Issues / bugs can be reported via [Github issues](https://github.com/rocketjob/net_tcp_client/issues).
282+
Issues / bugs can be reported via [Github issues](https://github.com/reidmorrison/net_tcp_client/issues).
283283

284284
### Upgrading to V2
285285

@@ -303,7 +303,7 @@ Tested and supported on the following Ruby platforms:
303303
- JRuby 1.7.23, 9.0 and above
304304
- Rubinius 2.5 and above
305305

306-
There is a soft dependency on [Semantic Logger](http://github.com/rocketjob/semantic_logger). It will use SemanticLogger only if
306+
There is a soft dependency on [Semantic Logger](https://github.com/reidmorrison/semantic_logger). It will use SemanticLogger only if
307307
it is already available, otherwise any other standard Ruby logger can be used.
308308

309309
### Note
@@ -314,8 +314,8 @@ Be sure to place the `semantic_logger` gem dependency before `net_tcp_client` in
314314

315315
[Reid Morrison](https://github.com/reidmorrison)
316316

317-
[Contributors](https://github.com/rocketjob/net_tcp_client/graphs/contributors)
317+
[Contributors](https://github.com/reidmorrison/net_tcp_client/graphs/contributors)
318318

319319
## Versioning
320320

321-
This project uses [Semantic Versioning](http://semver.org/).
321+
This project uses [Semantic Versioning](https://semver.org/).

Rakefile

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
require 'rake/testtask'
2-
require_relative 'lib/net/tcp_client/version'
1+
require "rake/testtask"
2+
require_relative "lib/net/tcp_client/version"
33

44
task :gem do
5-
system 'gem build net_tcp_client.gemspec'
5+
system "gem build net_tcp_client.gemspec"
66
end
77

8-
task :publish => :gem do
8+
task publish: :gem do
99
system "git tag -a v#{Net::TCPClient::VERSION} -m 'Tagging #{Net::TCPClient::VERSION}'"
10-
system 'git push --tags'
10+
system "git push --tags"
1111
system "gem push net_tcp_client-#{Net::TCPClient::VERSION}.gem"
1212
system "rm net_tcp_client-#{Net::TCPClient::VERSION}.gem"
1313
end
1414

1515
Rake::TestTask.new(:test) do |t|
16-
t.pattern = 'test/**/*_test.rb'
16+
t.pattern = "test/**/*_test.rb"
1717
t.verbose = true
1818
t.warning = true
1919
end
2020

21-
task :default => :test
21+
task default: :test

lib/net/tcp_client.rb

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
require 'socket'
1+
require "socket"
22
# Load SemanticLogger if available
33
begin
4-
require 'semantic_logger'
4+
require "semantic_logger"
55
rescue LoadError
66
end
7-
require 'net/tcp_client/version'
8-
require 'net/tcp_client/address'
9-
require 'net/tcp_client/exceptions'
10-
require 'net/tcp_client/tcp_client'
7+
require "net/tcp_client/version"
8+
require "net/tcp_client/address"
9+
require "net/tcp_client/exceptions"
10+
require "net/tcp_client/tcp_client"
1111

1212
# @formatter:off
1313
module Net
1414
class TCPClient
1515
module Policy
16-
autoload :Base, 'net/tcp_client/policy/base.rb'
17-
autoload :Custom, 'net/tcp_client/policy/custom.rb'
18-
autoload :Ordered, 'net/tcp_client/policy/ordered.rb'
19-
autoload :Random, 'net/tcp_client/policy/random.rb'
16+
autoload :Base, "net/tcp_client/policy/base.rb"
17+
autoload :Custom, "net/tcp_client/policy/custom.rb"
18+
autoload :Ordered, "net/tcp_client/policy/ordered.rb"
19+
autoload :Random, "net/tcp_client/policy/random.rb"
2020
end
2121
end
2222
end

0 commit comments

Comments
 (0)