tcp-server 1.1.3-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: 9bcae7fb08cc3df7627fb5679ed5784a20b53205d60ead5fe401f978080e39e9
4
- data.tar.gz: 4fd6a0775dd11cc06f3ab53f4caeed3efcc85eb59902acbb0b37b7e607cfa3ae
3
+ metadata.gz: 33f9e64d109b0bdcc53bfe8cda1c4d113106cc7a9d1f6e423cfb4fd6a9fcff52
4
+ data.tar.gz: 9663b9e88b11d643b51292a705fbbb0ea8509fc288b175404a76b021c8edc945
5
5
  SHA512:
6
- metadata.gz: 9834bab4ba9000b972100fcff462e7ce21f60b4630dfe2b488a0025ac0c0a844a5e4a585804abdf3e4fc2e1eadc2bb9d4468beff8050a2ae9e5921cb48a64dfb
7
- data.tar.gz: 0d808e91710feef4004b0b52e8139cde6c496202339de4b3ca299cc8f9616f98586e9f9348efe58e07b269caac247fc487ef1066676ccd71a2e90387b52faf34
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
 
@@ -208,7 +208,7 @@ curl --silent --show-error --location --request POST "https://gitlab.com/api/v4/
208
208
  ```
209
209
 
210
210
  [license]: https://gitlab.com/nelsnelson/tcp-server-jruby/blob/master/LICENSE
211
- [asdf]: https://mise.jdx.dev/
211
+ [mise]: https://mise.jdx.dev/
212
212
  [colima]: https://github.com/abiosoft/colima
213
213
  [Netty project]: https://github.com/netty/netty
214
214
  [Java JDK]: https://www.java.com/en/download/
@@ -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.3'.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.3
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-23 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