tcp-server 1.1.2-java → 1.1.4-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07e7184d3ca0f9e6db19db9d7de0561690ca2afe3aa17d66c29e4883591938f5
4
- data.tar.gz: b70a0d40bddcb3f5fbda8079873612db7f033ce5d9c62c28ab9fd1a1eb9b59de
3
+ metadata.gz: 33f9e64d109b0bdcc53bfe8cda1c4d113106cc7a9d1f6e423cfb4fd6a9fcff52
4
+ data.tar.gz: 9663b9e88b11d643b51292a705fbbb0ea8509fc288b175404a76b021c8edc945
5
5
  SHA512:
6
- metadata.gz: 43b0a8ecb712fa514d73378a08a97dc4320ad7ce7de1420550a2cf4574b8c62ba29e66c1a7e14b4a89d5ff472ca2ef73f434629fc38c2430270b7d58063af25f
7
- data.tar.gz: b09fd364b5304ce1ec7dc1c9cf6f3822ec059eeac9c6d5ca263dd657d9c801c378836ab9a71716f645b3eb0ad4d1d55a905e9357ef50b4be357ad5d71ff82be4
6
+ metadata.gz: dadc64a13e62cf4981b28d1d1b1d8c90748c30ff9164a646ac5cea2a294efca2916389e608b8510733333a1f66add302e43d3a537eab7f665eba2acac45ccf96
7
+ data.tar.gz: 72ff75a438437b1005f8d6bc8d8d3b00e3dcc96b3f4d2f17c86db1800e0e22b4ee46a9ac5621e36998741d181c81b01f6b4e1f12beea52c7237da546061bcefa
data/README.md CHANGED
@@ -26,7 +26,7 @@ docker-compose down
26
26
  Building the image or running the container:
27
27
 
28
28
  ```sh
29
- docker build --squash --tag tcp-server-jruby .
29
+ docker build --tag tcp-server-jruby .
30
30
  docker run --detach --publish 4000:4000 --name tcp-server-jruby tcp-server-jruby
31
31
  ```
32
32
 
@@ -43,35 +43,32 @@ The [mise] CLI tool used to manage multiple runtime versions.
43
43
  See: https://mise.jdx.dev/getting-started.html
44
44
 
45
45
  ```sh
46
- git clone https://github.com/asdf-vm/asdf.git "${HOME}/.asdf" --branch release-v0.10.0
47
- pushd "${HOME}/.asdf"; git fetch origin; popd
48
- source "${HOME}/.asdf/asdf.sh"; source "${HOME}/.asdf/completions/asdf.bash"
46
+ curl https://mise.jdx.dev/install.sh | sh
47
+ ~/.local/bin/mise --version
48
+ mise 2024.x.x
49
49
  ```
50
50
 
51
-
52
- ### Install required runtime software
53
-
54
- Download and install the latest version of the [Java JDK].
51
+ Enable mise activation in future zsh sessions.
55
52
 
56
53
  ```sh
57
- asdf plugin add java
58
- asdf install java openjdk-17.0.2
54
+ echo 'eval "$(~/.local/bin/mise activate zsh)"' >> ~/.zshrc
59
55
  ```
60
56
 
61
57
 
62
- Download and install the latest version of [JRuby].
58
+ ## Install required runtime software
59
+
60
+ Use mise to install the runtime software defined as requirements
61
+ in the .tool-versions file.
63
62
 
64
63
  ```sh
65
- asdf plugin add ruby
66
- asdf plugin update --all
67
- asdf list all ruby
68
- asdf install ruby jruby-9.3.4.0
64
+ mise install
69
65
  ```
70
66
 
71
67
 
72
68
  Install the project dependencies.
73
69
 
74
70
  ```sh
71
+ gem install bundler
75
72
  bundle install
76
73
  ```
77
74
 
@@ -211,7 +208,7 @@ curl --silent --show-error --location --request POST "https://gitlab.com/api/v4/
211
208
  ```
212
209
 
213
210
  [license]: https://gitlab.com/nelsnelson/tcp-server-jruby/blob/master/LICENSE
214
- [asdf]: https://mise.jdx.dev/
211
+ [mise]: https://mise.jdx.dev/
215
212
  [colima]: https://github.com/abiosoft/colima
216
213
  [Netty project]: https://github.com/netty/netty
217
214
  [Java JDK]: https://www.java.com/en/download/
data/lib/logging.rb CHANGED
@@ -156,7 +156,7 @@ module Logging
156
156
  java_import Java::org.apache.logging.log4j.LogManager
157
157
  end
158
158
 
159
- FORWARD_SLASH_PATTERN = %r{/}
159
+ FORWARD_SLASH_PATTERN = %r{/} unless defined?(FORWARD_SLASH_PATTERN)
160
160
 
161
161
  def init_logger(level = :info, logger_name = nil)
162
162
  return init_java_logger(level, logger_name, caller[2]) if defined?(Java)
@@ -33,11 +33,11 @@ module Server
33
33
  @parser.separator 'Options:'
34
34
  end
35
35
 
36
- def validated_port(val, integer_pattern = /^\d+$/)
37
- raise OptionParser::InvalidArgument, "Invalid port: #{v}" unless \
38
- integer_pattern.match?(val.to_s) && val.positive? && val < 65_536
36
+ def validated_port(value, integer_pattern = /^\d+$/)
37
+ raise OptionParser::InvalidArgument, "Invalid port: #{value}" unless \
38
+ integer_pattern.match?(value.to_s) && value.positive? && value < 65_536
39
39
 
40
- val
40
+ value
41
41
  end
42
42
 
43
43
  def port
@@ -97,7 +97,8 @@ module Server
97
97
  def parse_arguments(arguments_parser = ::Server::ArgumentsParser.new)
98
98
  arguments_parser.parser.parse!(ARGV)
99
99
  arguments_parser.options
100
- rescue OptionParser::InvalidOption, OptionParser::AmbiguousOption => e
100
+ rescue OptionParser::InvalidArgument, OptionParser::InvalidOption,
101
+ OptionParser::AmbiguousOption => e
101
102
  abort e.message
102
103
  end
103
104
  end
data/lib/server/config.rb CHANGED
@@ -10,6 +10,7 @@
10
10
  #
11
11
  # =end
12
12
 
13
+ require 'java'
13
14
  require 'netty'
14
15
 
15
16
  require 'logger'
@@ -20,14 +21,16 @@ module Server
20
21
  def server_config
21
22
  @server_config ||= {
22
23
  host: '0.0.0.0',
23
- port: 8080,
24
+ port: Server::DEFAULT_PORT,
24
25
  ssl: false,
25
26
  idle_reading: 5 * 60, # seconds
26
27
  idle_writing: 30, # seconds
28
+ max_queued_incoming_connections: Server::DEFAULT_MAX_QUEUED_INCOMING_CONNECTIONS,
27
29
  log_requests: false,
28
30
  log_level: Logger::INFO,
29
31
  quit_commands: %i[bye cease desist exit leave quit stop terminate],
30
32
  max_frame_length: 8192,
33
+ keep_alive: Server::DEFAULT_KEEP_ALIVE,
31
34
  delimiter: Java::io.netty.handler.codec.Delimiters.lineDelimiter
32
35
  }.freeze
33
36
  end
@@ -28,19 +28,26 @@ module Server
28
28
 
29
29
  # The InstanceMethods module
30
30
  module InstanceMethods
31
+ # rubocop: disable Metrics/AbcSize
32
+ def bootstrap
33
+ @bootstrap = ServerBootstrap.new
34
+ @bootstrap.group(boss_group, worker_group)
35
+ @bootstrap.channel(channel_type)
36
+ @bootstrap.option(ChannelOption::SO_BACKLOG, max_queued_incoming_connections)
37
+ @bootstrap.childOption(ChannelOption::SO_KEEPALIVE, keep_alive) if keep_alive
38
+ @bootstrap.handler(logging_handler) if options.fetch(:log_requests, false)
39
+ @bootstrap.childHandler(channel_initializer)
40
+ end
41
+ # rubocop: enable Metrics/AbcSize
42
+
31
43
  def configure_handlers(*handlers, &block)
32
44
  add_listener(self)
33
45
  channel_initializer << block if block_given?
34
46
  add_listener(*handlers)
35
47
  end
36
48
 
37
- def bootstrap
38
- @bootstrap = ServerBootstrap.new
39
- @bootstrap.group(boss_group, worker_group)
40
- @bootstrap.channel(Server::CHANNEL_TYPE)
41
- @bootstrap.option(ChannelOption::SO_BACKLOG, 100.to_java(java.lang.Integer))
42
- @bootstrap.handler(logging_handler) if options[:log_requests]
43
- @bootstrap.childHandler(channel_initializer)
49
+ def channel_type
50
+ @channel_type ||= Server::CHANNEL_TYPE
44
51
  end
45
52
 
46
53
  def channel_initializer
@@ -65,7 +72,7 @@ module Server
65
72
 
66
73
  # rubocop: disable Metrics/AbcSize
67
74
  # rubocop: disable Metrics/MethodLength
68
- def run(port = @options[:port])
75
+ def run(port = self.port)
69
76
  channel = bootstrap.bind(port).sync().channel()
70
77
  channel_group.add(channel)
71
78
  ::Server::ShutdownHook.new(self)
@@ -83,6 +90,14 @@ module Server
83
90
  # rubocop: enable Metrics/AbcSize
84
91
  # rubocop: enable Metrics/MethodLength
85
92
 
93
+ def port
94
+ @port ||= begin
95
+ value = @options[:port]
96
+ value = DEFAULT_PORT if value.nil?
97
+ value.to_i
98
+ end
99
+ end
100
+
86
101
  def shutdown
87
102
  channel_group.disconnect().awaitUninterruptibly()
88
103
  channel_group.close().awaitUninterruptibly()
@@ -104,6 +119,22 @@ module Server
104
119
  def replace_listeners(*listener)
105
120
  channel_initializer.replace_listeners(*listener)
106
121
  end
122
+
123
+ def keep_alive
124
+ @keep_alive ||= begin
125
+ value = @options[:keep_alive]
126
+ value = DEFAULT_KEEP_ALIVE if value.nil?
127
+ value
128
+ end
129
+ end
130
+
131
+ def max_queued_incoming_connections
132
+ @max_queued_incoming_connections ||= begin
133
+ value = @options[:max_queued_incoming_connections]
134
+ value = DEFAULT_MAX_QUEUED_INCOMING_CONNECTIONS if value.nil?
135
+ value.to_java(java.lang.Integer)
136
+ end
137
+ end
107
138
  end
108
139
  # module ServerInstanceMethods
109
140
  end
data/lib/server/server.rb CHANGED
@@ -21,6 +21,9 @@ module Server
21
21
  # The Server class sets up the netty server.
22
22
  class Server
23
23
  CHANNEL_TYPE = Java::io.netty.channel.socket.nio.NioServerSocketChannel.java_class
24
+ DEFAULT_MAX_QUEUED_INCOMING_CONNECTIONS = 100
25
+ DEFAULT_KEEP_ALIVE = false
26
+ DEFAULT_PORT = 8080
24
27
  include ::Server::InstanceMethods
25
28
  attr_reader :options
26
29
 
@@ -32,9 +35,10 @@ module Server
32
35
 
33
36
  # rubocop: disable Metrics/AbcSize
34
37
  def message_received(ctx, msg)
38
+ return if msg.nil?
39
+ msg.chomp! if msg.respond_to?(:chomp!)
40
+ return if msg.respond_to?(:empty?) && msg.empty?
35
41
  log.trace "##{__method__} channel: #{ctx.channel}, message: #{msg.inspect}"
36
- msg&.chomp!
37
- return if msg.nil? || msg.empty?
38
42
  return ctx.close() if @options[:quit_commands].include?(msg.downcase.to_sym)
39
43
  response = msg.upcase
40
44
  log.debug "Sending response: #{response.inspect}"
@@ -29,7 +29,7 @@ module Server
29
29
  $stdout.write "\r\e[0K"
30
30
  $stdout.flush
31
31
  ::Server.log.info 'Shutting down'
32
- @server.shutdown if server.respond_to?(:shutdown)
32
+ server.shutdown if server.respond_to?(:shutdown)
33
33
  end
34
34
  end
35
35
  end
@@ -12,5 +12,5 @@
12
12
 
13
13
  # The Server module
14
14
  module Server
15
- VERSION = '1.1.2'.freeze
15
+ VERSION = '1.1.4'.freeze
16
16
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tcp-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.4
5
5
  platform: java
6
6
  authors:
7
7
  - Nels Nelson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-19 00:00:00.000000000 Z
11
+ date: 2024-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement