tcp-server 1.0.3-java → 1.0.6-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 +4 -4
- data/README.md +27 -0
- data/lib/server/channel_initializer.rb +12 -4
- data/lib/server/instance_methods.rb +16 -6
- data/lib/server/modular_handler.rb +8 -11
- data/lib/server/server.rb +1 -6
- data/lib/server/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adb40677b97f1b1ce0fb1fad9308d527d3086c927044f5e71d1e378c5e0d8e25
|
4
|
+
data.tar.gz: 7e489022262138faae081772672bb99ca5eef415f943ff2b9cf96120390cb984
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d8afb5280d5a8bfe5dd234dcb5f0dfb26558543074b917de3c39bd08cd5331319a32bd764400d7183fa8814d8b978a57532306dfb2b7464c28cc58aacc5c732
|
7
|
+
data.tar.gz: 8a6c94c3ee130ea33a8c4e95009b75414d9622916b4277a38664f3f08d3f238d787941c9c0e7ed5c566a2c3efd2b2d064dda83f0cdce513fd95036c08c959e09
|
data/README.md
CHANGED
@@ -173,6 +173,33 @@ Use the GitLab CI Linting API to validate the syntax of a CI definition file.
|
|
173
173
|
jq --null-input --arg yaml "$(<.gitlab/ci/gem.gitlab-ci.yml)" '.content=$yaml' | curl --silent --location https://gitlab.com/api/v4/ci/lint --header "PRIVATE-TOKEN: ${GITLAB_COM_API_PRIVATE_TOKEN}" --header "Content-Type: application/json" --data @- | jq --raw-output '.errors[0]'
|
174
174
|
```
|
175
175
|
|
176
|
+
## CI configuration
|
177
|
+
|
178
|
+
Generate a deploy key.
|
179
|
+
|
180
|
+
```sh
|
181
|
+
ssh-keygen -t ed25519 -C deploy_key
|
182
|
+
```
|
183
|
+
|
184
|
+
Use the GitLab Project-level Variables API to add the deploy key as a ssh private key variable.
|
185
|
+
|
186
|
+
```sh
|
187
|
+
project_path="nelsnelson/$(basename $(pwd))"
|
188
|
+
|
189
|
+
project=$(curl --silent --show-error --location "https://gitlab.com/api/v4/search?scope=projects&search=${project_path}" --header "PRIVATE-TOKEN: ${GITLAB_COM_API_PRIVATE_TOKEN}" | jq --arg project_path "${project_path}" '.[] | select(.path_with_namespace == $project_path)')
|
190
|
+
|
191
|
+
project_id=$(curl --silent --show-error --location "https://gitlab.com/api/v4/search?scope=projects&search=${project_path}" --header "PRIVATE-TOKEN: ${GITLAB_COM_API_PRIVATE_TOKEN}" | jq --arg project_path "${project_path}" '.[] | select(.path_with_namespace == $project_path) | .id')
|
192
|
+
|
193
|
+
# Add the deploy_token as a CI variable:
|
194
|
+
curl --silent --show-error --location --request POST "https://gitlab.com/api/v4/projects/${project_id}/variables" --header "PRIVATE-TOKEN: ${GITLAB_COM_API_PRIVATE_TOKEN}" --form "key=SSH_PRIVATE_KEY" --form "value=$(cat ./deploy_token)" --form "protected=true" | jq
|
195
|
+
```
|
196
|
+
|
197
|
+
Use the Deploy keys API to add a the public deploy key as a deploy key for the project.
|
198
|
+
|
199
|
+
```sh
|
200
|
+
curl --silent --show-error --location --request POST "https://gitlab.com/api/v4/projects/${project_id}/deploy_keys" --header "PRIVATE-TOKEN: ${GITLAB_COM_API_PRIVATE_TOKEN}" --data '{"title": "deploy_key", "key": "$(cat ./deploy_token.pub)", "can_push": "true"}' | jq
|
201
|
+
```
|
202
|
+
|
176
203
|
[license]: https://gitlab.com/nelsnelson/tcp-server-jruby/blob/master/LICENSE
|
177
204
|
[asdf]: https://asdf-vm.com/
|
178
205
|
[Netty project]: https://github.com/netty/netty
|
@@ -30,7 +30,6 @@ module Server
|
|
30
30
|
|
31
31
|
# The ChannelInitializer class
|
32
32
|
class ChannelInitializer < Java::io.netty.channel.ChannelInitializer
|
33
|
-
DefaultHandler = ModularHandler.new
|
34
33
|
FrameDecoderBufferBytesSize = 8192
|
35
34
|
# The encoder and decoder are sharable. If they were not, then
|
36
35
|
# constant definitions could not be used.
|
@@ -39,8 +38,9 @@ module Server
|
|
39
38
|
attr_accessor :user_handlers
|
40
39
|
attr_reader :options
|
41
40
|
|
42
|
-
def initialize(options = {})
|
41
|
+
def initialize(channel_group, options = {})
|
43
42
|
super()
|
43
|
+
@channel_group = channel_group
|
44
44
|
@options = options
|
45
45
|
@user_handlers = []
|
46
46
|
end
|
@@ -58,7 +58,15 @@ module Server
|
|
58
58
|
Encoder
|
59
59
|
)
|
60
60
|
add_user_handlers(pipeline)
|
61
|
-
pipeline.addLast(
|
61
|
+
pipeline.addLast(default_handler)
|
62
|
+
end
|
63
|
+
|
64
|
+
def default_handler
|
65
|
+
@default_handler ||= ::Server::ModularHandler.new(@channel_group)
|
66
|
+
end
|
67
|
+
|
68
|
+
def add_listener(listener)
|
69
|
+
default_handler.add_listener(listener)
|
62
70
|
end
|
63
71
|
|
64
72
|
protected
|
@@ -67,7 +75,7 @@ module Server
|
|
67
75
|
@user_handlers.each do |handler|
|
68
76
|
case handler
|
69
77
|
when Class then pipeline.addLast(handler.new)
|
70
|
-
when Proc then pipeline.addLast(Server::MessageHandler.new(&handler))
|
78
|
+
when Proc then pipeline.addLast(::Server::MessageHandler.new(&handler))
|
71
79
|
else pipeline.addLast(handler)
|
72
80
|
end
|
73
81
|
end
|
@@ -20,28 +20,30 @@ require_relative 'shutdown_hook'
|
|
20
20
|
module Server
|
21
21
|
java_import Java::io.netty.bootstrap.ServerBootstrap
|
22
22
|
java_import Java::io.netty.channel.ChannelOption
|
23
|
+
java_import Java::io.netty.channel.group.DefaultChannelGroup
|
23
24
|
java_import Java::io.netty.channel.nio.NioEventLoopGroup
|
24
25
|
java_import Java::io.netty.handler.logging.LogLevel
|
25
26
|
java_import Java::io.netty.handler.logging.LoggingHandler
|
27
|
+
java_import Java::io.netty.util.concurrent.GlobalEventExecutor
|
26
28
|
|
27
29
|
# The InstanceMethods module
|
28
30
|
module InstanceMethods
|
29
31
|
def configure_handlers(&block)
|
30
|
-
|
32
|
+
add_listener(self)
|
31
33
|
channel_initializer << block if block_given?
|
32
34
|
end
|
33
35
|
|
34
36
|
def bootstrap
|
35
37
|
@bootstrap = ServerBootstrap.new
|
36
38
|
@bootstrap.group(boss_group, worker_group)
|
37
|
-
@bootstrap.channel(
|
39
|
+
@bootstrap.channel(Server::CHANNEL_TYPE)
|
38
40
|
@bootstrap.option(ChannelOption::SO_BACKLOG, 100.to_java(java.lang.Integer))
|
39
41
|
@bootstrap.handler(logging_handler) if options[:log_requests]
|
40
42
|
@bootstrap.childHandler(channel_initializer)
|
41
43
|
end
|
42
44
|
|
43
45
|
def channel_initializer
|
44
|
-
@channel_initializer ||= ::Server::ChannelInitializer.new(@options)
|
46
|
+
@channel_initializer ||= ::Server::ChannelInitializer.new(channel_group, @options)
|
45
47
|
end
|
46
48
|
|
47
49
|
def boss_group
|
@@ -52,6 +54,10 @@ module Server
|
|
52
54
|
@worker_group ||= NioEventLoopGroup.new
|
53
55
|
end
|
54
56
|
|
57
|
+
def channel_group
|
58
|
+
@channel_group ||= DefaultChannelGroup.new('server_channels', GlobalEventExecutor::INSTANCE)
|
59
|
+
end
|
60
|
+
|
55
61
|
def logging_handler
|
56
62
|
@logging_handler ||= LoggingHandler.new(LogLevel::INFO)
|
57
63
|
end
|
@@ -60,7 +66,7 @@ module Server
|
|
60
66
|
# rubocop: disable Metrics/MethodLength
|
61
67
|
def run(port = @options[:port])
|
62
68
|
channel = bootstrap.bind(port).sync().channel()
|
63
|
-
|
69
|
+
channel_group.add(channel)
|
64
70
|
::Server::ShutdownHook.new(self)
|
65
71
|
log.info "Listening on #{channel.local_address}"
|
66
72
|
channel.closeFuture().sync()
|
@@ -77,8 +83,8 @@ module Server
|
|
77
83
|
# rubocop: enable Metrics/MethodLength
|
78
84
|
|
79
85
|
def shutdown
|
80
|
-
|
81
|
-
|
86
|
+
channel_group.disconnect().awaitUninterruptibly()
|
87
|
+
channel_group.close().awaitUninterruptibly()
|
82
88
|
end
|
83
89
|
|
84
90
|
def stop
|
@@ -89,6 +95,10 @@ module Server
|
|
89
95
|
def <<(handler)
|
90
96
|
channel_initializer << handler
|
91
97
|
end
|
98
|
+
|
99
|
+
def add_listener(listener)
|
100
|
+
channel_initializer.add_listener(listener)
|
101
|
+
end
|
92
102
|
end
|
93
103
|
# module ServerInstanceMethods
|
94
104
|
end
|
@@ -18,19 +18,16 @@ require_relative 'listenable'
|
|
18
18
|
# The Server module
|
19
19
|
module Server
|
20
20
|
java_import Java::io.netty.channel.SimpleChannelInboundHandler
|
21
|
-
java_import Java::io.netty.channel.group.DefaultChannelGroup
|
22
|
-
java_import Java::io.netty.util.concurrent.GlobalEventExecutor
|
23
|
-
|
24
|
-
# rubocop: disable Style/IfUnlessModifier
|
25
|
-
unless defined?(::Server::Channels)
|
26
|
-
Channels = DefaultChannelGroup.new('channels', GlobalEventExecutor::INSTANCE)
|
27
|
-
end
|
28
|
-
# rubocop: enable Style/IfUnlessModifier
|
29
21
|
|
30
22
|
# The ModularHandler class notifies listeners about events.
|
31
23
|
class ModularHandler < SimpleChannelInboundHandler
|
32
24
|
include ::Server::Listenable
|
33
25
|
|
26
|
+
def initialize(channel_group)
|
27
|
+
super()
|
28
|
+
@channel_group = channel_group
|
29
|
+
end
|
30
|
+
|
34
31
|
def isSharable
|
35
32
|
true
|
36
33
|
end
|
@@ -49,7 +46,7 @@ module Server
|
|
49
46
|
|
50
47
|
def channelActive(ctx)
|
51
48
|
log.trace "##{__method__} channel: #{ctx.channel}"
|
52
|
-
|
49
|
+
@channel_group.add(ctx.channel)
|
53
50
|
notify :channel_active, ctx
|
54
51
|
super(ctx)
|
55
52
|
end
|
@@ -107,10 +104,10 @@ module Server
|
|
107
104
|
super(ctx, cause) if listeners.nil? || listeners.empty?
|
108
105
|
end
|
109
106
|
|
110
|
-
|
107
|
+
IdentifierTemplate = '#<%<class>s:0x%<id>s>'.freeze
|
111
108
|
|
112
109
|
def to_s
|
113
|
-
format(
|
110
|
+
format(IdentifierTemplate, class: self.class.name, id: object_id.to_s(16))
|
114
111
|
end
|
115
112
|
alias inspect to_s
|
116
113
|
end
|
data/lib/server/server.rb
CHANGED
@@ -18,10 +18,9 @@ require_relative 'listenable'
|
|
18
18
|
|
19
19
|
# The Server module
|
20
20
|
module Server
|
21
|
-
CHANNEL_TYPE = Java::io.netty.channel.socket.nio.NioServerSocketChannel.java_class
|
22
|
-
|
23
21
|
# The Server class sets up the netty server.
|
24
22
|
class Server
|
23
|
+
CHANNEL_TYPE = Java::io.netty.channel.socket.nio.NioServerSocketChannel.java_class
|
25
24
|
include ::Server::InstanceMethods
|
26
25
|
attr_reader :options
|
27
26
|
|
@@ -40,10 +39,6 @@ module Server
|
|
40
39
|
log.debug "Sending response: #{response.inspect}"
|
41
40
|
ctx.writeAndFlush("#{response}\n")
|
42
41
|
end
|
43
|
-
|
44
|
-
def add_listener(listener)
|
45
|
-
::Server::ChannelInitializer::DefaultHandler.add_listener(listener)
|
46
|
-
end
|
47
42
|
# rubocop: enable Metrics/AbcSize
|
48
43
|
end
|
49
44
|
# class Server
|
data/lib/server/version.rb
CHANGED
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.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Nels Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|