robin 0.1.0-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 +7 -0
- data/CHANGELOG.md +372 -0
- data/COPYING +674 -0
- data/LICENSE +165 -0
- data/README.md +1490 -0
- data/assets/favicon.svg +31 -0
- data/assets/robin-logo.svg +37 -0
- data/assets/robin-mono.svg +12 -0
- data/assets/robin-wordmark.svg +4 -0
- data/assets/robin.svg +34 -0
- data/exe/robin +5 -0
- data/ext/java/robin_resp/Blocking.java +27 -0
- data/ext/java/robin_resp/NativeIO.java +229 -0
- data/ext/java/robin_resp/NativeRESP.java +279 -0
- data/ext/java/robin_resp/NativeSlots.java +133 -0
- data/ext/java/robin_resp/RobinRespService.java +32 -0
- data/lib/active_job/queue_adapters/robin_adapter.rb +3 -0
- data/lib/generators/robin/install/install_generator.rb +39 -0
- data/lib/generators/robin/install/templates/initializer.rb.tt +31 -0
- data/lib/generators/robin/install/templates/robin.yml.tt +25 -0
- data/lib/generators/robin/job/job_generator.rb +78 -0
- data/lib/generators/robin/job/templates/job.rb.tt +13 -0
- data/lib/generators/robin/job/templates/job_spec.rb.tt +21 -0
- data/lib/generators/robin/job/templates/job_test.rb.tt +21 -0
- data/lib/puma/plugin/robin.rb +131 -0
- data/lib/robin/active_job.rb +144 -0
- data/lib/robin/api.rb +777 -0
- data/lib/robin/batch.rb +700 -0
- data/lib/robin/cancellation.rb +62 -0
- data/lib/robin/cli.rb +325 -0
- data/lib/robin/client.rb +372 -0
- data/lib/robin/config.rb +461 -0
- data/lib/robin/cron.rb +325 -0
- data/lib/robin/debounce.rb +108 -0
- data/lib/robin/deploy.rb +65 -0
- data/lib/robin/embedded.rb +53 -0
- data/lib/robin/encryption.rb +147 -0
- data/lib/robin/events.rb +60 -0
- data/lib/robin/expiry.rb +41 -0
- data/lib/robin/fetcher.rb +441 -0
- data/lib/robin/gvl.rb +62 -0
- data/lib/robin/health.rb +76 -0
- data/lib/robin/iterable_job.rb +294 -0
- data/lib/robin/job.rb +258 -0
- data/lib/robin/job_class.rb +157 -0
- data/lib/robin/job_logger.rb +121 -0
- data/lib/robin/launcher.rb +658 -0
- data/lib/robin/leader.rb +86 -0
- data/lib/robin/limiter.rb +639 -0
- data/lib/robin/manager.rb +125 -0
- data/lib/robin/metrics.rb +303 -0
- data/lib/robin/middleware.rb +165 -0
- data/lib/robin/opentelemetry.rb +88 -0
- data/lib/robin/periodic.rb +327 -0
- data/lib/robin/processor.rb +317 -0
- data/lib/robin/profiler.rb +140 -0
- data/lib/robin/progress.rb +46 -0
- data/lib/robin/rails/app_loader.rb +23 -0
- data/lib/robin/rails/current_attributes.rb +88 -0
- data/lib/robin/rails/error_reporter.rb +31 -0
- data/lib/robin/rails/notifications.rb +22 -0
- data/lib/robin/rails/railtie.rb +87 -0
- data/lib/robin/rails/transactional_push.rb +49 -0
- data/lib/robin/rails.rb +23 -0
- data/lib/robin/recovery.rb +135 -0
- data/lib/robin/redis/connection.rb +639 -0
- data/lib/robin/redis/pool.rb +190 -0
- data/lib/robin/redis/resp.rb +77 -0
- data/lib/robin/reliable_push.rb +153 -0
- data/lib/robin/retrier.rb +284 -0
- data/lib/robin/scheduler.rb +102 -0
- data/lib/robin/scripts.rb +331 -0
- data/lib/robin/statsd.rb +135 -0
- data/lib/robin/swarm.rb +319 -0
- data/lib/robin/systemd.rb +47 -0
- data/lib/robin/testing.rb +158 -0
- data/lib/robin/top.rb +178 -0
- data/lib/robin/unique.rb +198 -0
- data/lib/robin/version.rb +5 -0
- data/lib/robin/warmup.rb +94 -0
- data/lib/robin/web/api.rb +580 -0
- data/lib/robin/web/batch_status.rb +44 -0
- data/lib/robin/web/dist/assets/ar-y7v9b75f.js +1 -0
- data/lib/robin/web/dist/assets/ar-y7v9b75f.js.gz +0 -0
- data/lib/robin/web/dist/assets/bricolage-0qmzcpnj.woff2 +0 -0
- data/lib/robin/web/dist/assets/cs-df88mq5e.js +1 -0
- data/lib/robin/web/dist/assets/cs-df88mq5e.js.gz +0 -0
- data/lib/robin/web/dist/assets/da-kemms74g.js +1 -0
- data/lib/robin/web/dist/assets/da-kemms74g.js.gz +0 -0
- data/lib/robin/web/dist/assets/de-z8kkqg65.js +1 -0
- data/lib/robin/web/dist/assets/de-z8kkqg65.js.gz +0 -0
- data/lib/robin/web/dist/assets/es-9ahrrn1s.js +1 -0
- data/lib/robin/web/dist/assets/es-9ahrrn1s.js.gz +0 -0
- data/lib/robin/web/dist/assets/fa-7r0x28nc.js +1 -0
- data/lib/robin/web/dist/assets/fa-7r0x28nc.js.gz +0 -0
- data/lib/robin/web/dist/assets/favicon-1ebfcc0182.svg +31 -0
- data/lib/robin/web/dist/assets/favicon-1ebfcc0182.svg.gz +0 -0
- data/lib/robin/web/dist/assets/fr-r7mqf3d9.js +1 -0
- data/lib/robin/web/dist/assets/fr-r7mqf3d9.js.gz +0 -0
- data/lib/robin/web/dist/assets/he-7t46b6rt.js +1 -0
- data/lib/robin/web/dist/assets/he-7t46b6rt.js.gz +0 -0
- data/lib/robin/web/dist/assets/hi-zj434tx4.js +1 -0
- data/lib/robin/web/dist/assets/hi-zj434tx4.js.gz +0 -0
- data/lib/robin/web/dist/assets/it-pqc2m7gm.js +1 -0
- data/lib/robin/web/dist/assets/it-pqc2m7gm.js.gz +0 -0
- data/lib/robin/web/dist/assets/ja-k9rgm1pj.js +1 -0
- data/lib/robin/web/dist/assets/ja-k9rgm1pj.js.gz +0 -0
- data/lib/robin/web/dist/assets/ko-bxersv91.js +1 -0
- data/lib/robin/web/dist/assets/ko-bxersv91.js.gz +0 -0
- data/lib/robin/web/dist/assets/main-anw3f6ba.css +1 -0
- data/lib/robin/web/dist/assets/main-anw3f6ba.css.gz +0 -0
- data/lib/robin/web/dist/assets/main-pdtvjejb.js +7 -0
- data/lib/robin/web/dist/assets/main-pdtvjejb.js.gz +0 -0
- data/lib/robin/web/dist/assets/main-zz8zzhwn.js +2 -0
- data/lib/robin/web/dist/assets/main-zz8zzhwn.js.gz +0 -0
- data/lib/robin/web/dist/assets/nb-fjnc5064.js +1 -0
- data/lib/robin/web/dist/assets/nb-fjnc5064.js.gz +0 -0
- data/lib/robin/web/dist/assets/nl-9p8b95b6.js +1 -0
- data/lib/robin/web/dist/assets/nl-9p8b95b6.js.gz +0 -0
- data/lib/robin/web/dist/assets/pl-8xsrdn8n.js +1 -0
- data/lib/robin/web/dist/assets/pl-8xsrdn8n.js.gz +0 -0
- data/lib/robin/web/dist/assets/pt-BR-650j7cvg.js +1 -0
- data/lib/robin/web/dist/assets/pt-BR-650j7cvg.js.gz +0 -0
- data/lib/robin/web/dist/assets/robin-ae4a4aedd9.svg +34 -0
- data/lib/robin/web/dist/assets/robin-ae4a4aedd9.svg.gz +0 -0
- data/lib/robin/web/dist/assets/robin-wordmark-5dde5d8e4b.svg +4 -0
- data/lib/robin/web/dist/assets/robin-wordmark-5dde5d8e4b.svg.gz +0 -0
- data/lib/robin/web/dist/assets/ru-a9ftyw3d.js +1 -0
- data/lib/robin/web/dist/assets/ru-a9ftyw3d.js.gz +0 -0
- data/lib/robin/web/dist/assets/sv-j9gqamr1.js +1 -0
- data/lib/robin/web/dist/assets/sv-j9gqamr1.js.gz +0 -0
- data/lib/robin/web/dist/assets/tr-y9z0q51g.js +1 -0
- data/lib/robin/web/dist/assets/tr-y9z0q51g.js.gz +0 -0
- data/lib/robin/web/dist/assets/uk-2dr9ew3p.js +1 -0
- data/lib/robin/web/dist/assets/uk-2dr9ew3p.js.gz +0 -0
- data/lib/robin/web/dist/assets/ur-h25nzq1s.js +1 -0
- data/lib/robin/web/dist/assets/ur-h25nzq1s.js.gz +0 -0
- data/lib/robin/web/dist/assets/vi-9y2ff1bd.js +1 -0
- data/lib/robin/web/dist/assets/vi-9y2ff1bd.js.gz +0 -0
- data/lib/robin/web/dist/assets/zh-CN-tbj9mf98.js +1 -0
- data/lib/robin/web/dist/assets/zh-CN-tbj9mf98.js.gz +0 -0
- data/lib/robin/web/dist/assets/zh-TW-59q8j9vw.js +1 -0
- data/lib/robin/web/dist/assets/zh-TW-59q8j9vw.js.gz +0 -0
- data/lib/robin/web/dist/index.html +19 -0
- data/lib/robin/web/extension.rb +193 -0
- data/lib/robin/web/permissions.rb +40 -0
- data/lib/robin/web/prometheus.rb +79 -0
- data/lib/robin/web/router.rb +150 -0
- data/lib/robin/web/static.rb +110 -0
- data/lib/robin/web.rb +196 -0
- data/lib/robin.rb +261 -0
- data/lib/robin_resp/robin_resp.jar +0 -0
- data/sig/manifest.yaml +9 -0
- data/sig/robin/api.rbs +442 -0
- data/sig/robin/batch.rbs +292 -0
- data/sig/robin/cancellation.rbs +25 -0
- data/sig/robin/cli.rbs +102 -0
- data/sig/robin/client.rbs +118 -0
- data/sig/robin/config.rbs +341 -0
- data/sig/robin/cron.rbs +149 -0
- data/sig/robin/debounce.rbs +36 -0
- data/sig/robin/deploy.rbs +24 -0
- data/sig/robin/embedded.rbs +25 -0
- data/sig/robin/encryption.rbs +49 -0
- data/sig/robin/events.rbs +10 -0
- data/sig/robin/expiry.rbs +17 -0
- data/sig/robin/fetcher.rbs +134 -0
- data/sig/robin/gvl.rbs +39 -0
- data/sig/robin/health.rbs +30 -0
- data/sig/robin/iterable_job.rbs +99 -0
- data/sig/robin/job.rbs +173 -0
- data/sig/robin/job_class.rbs +55 -0
- data/sig/robin/job_logger.rbs +56 -0
- data/sig/robin/launcher.rbs +191 -0
- data/sig/robin/leader.rbs +43 -0
- data/sig/robin/limiter.rbs +317 -0
- data/sig/robin/manager.rbs +54 -0
- data/sig/robin/metrics.rbs +122 -0
- data/sig/robin/middleware.rbs +106 -0
- data/sig/robin/opentelemetry.rbs +51 -0
- data/sig/robin/periodic.rbs +81 -0
- data/sig/robin/processor.rbs +107 -0
- data/sig/robin/profiler.rbs +60 -0
- data/sig/robin/progress.rbs +22 -0
- data/sig/robin/rails/app_loader.rbs +10 -0
- data/sig/robin/rails/current_attributes.rbs +44 -0
- data/sig/robin/rails/error_reporter.rbs +21 -0
- data/sig/robin/rails/notifications.rbs +9 -0
- data/sig/robin/rails/transactional_push.rbs +16 -0
- data/sig/robin/rails.rbs +8 -0
- data/sig/robin/recovery.rbs +29 -0
- data/sig/robin/redis/connection.rbs +224 -0
- data/sig/robin/redis/pool.rbs +89 -0
- data/sig/robin/redis/resp.rbs +29 -0
- data/sig/robin/reliable_push.rbs +77 -0
- data/sig/robin/retrier.rbs +72 -0
- data/sig/robin/scheduler.rbs +40 -0
- data/sig/robin/scripts.rbs +36 -0
- data/sig/robin/statsd.rbs +55 -0
- data/sig/robin/swarm.rbs +133 -0
- data/sig/robin/systemd.rbs +13 -0
- data/sig/robin/testing.rbs +80 -0
- data/sig/robin/top.rbs +79 -0
- data/sig/robin/unique.rbs +72 -0
- data/sig/robin/version.rbs +3 -0
- data/sig/robin/warmup.rbs +44 -0
- data/sig/robin/web/api.rbs +196 -0
- data/sig/robin/web/batch_status.rbs +25 -0
- data/sig/robin/web/extension.rbs +106 -0
- data/sig/robin/web/permissions.rbs +14 -0
- data/sig/robin/web/prometheus.rbs +33 -0
- data/sig/robin/web/router.rbs +53 -0
- data/sig/robin/web/static.rbs +42 -0
- data/sig/robin/web.rbs +140 -0
- data/sig/robin.rbs +116 -0
- data/sig/robin_resp.rbs +55 -0
- metadata +294 -0
data/assets/favicon.svg
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="22 14 468 492" role="img" aria-label="Robin">
|
|
2
|
+
<title>Robin</title>
|
|
3
|
+
<!-- white keyline: invisible on light backgrounds, outlines the bird on dark ones -->
|
|
4
|
+
<g fill="#ffffff" stroke="#ffffff" stroke-width="36" stroke-linejoin="round"><path d="M256 240 L350 236 L398 264 L418 334 L412 416 L392 402 L384 458 L360 436 L338 480 L300 466 L256 472 L212 466 L174 480 L152 436 L128 458 L120 402 L100 416 L94 334 L114 264 L162 236 Z" fill="#ffffff"/><path d="M256 34 L284 86 L322 52 L326 104 L364 152 L370 210 L340 252 L256 268 L172 252 L142 210 L148 152 L186 104 L190 52 L228 86 Z" fill="#ffffff"/></g>
|
|
5
|
+
<!-- folded wings as a cape -->
|
|
6
|
+
<path d="M256 240 L350 236 L398 264 L418 334 L412 416 L392 402 L384 458 L360 436 L338 480 L300 466 L256 472 L212 466 L174 480 L152 436 L128 458 L120 402 L100 416 L94 334 L114 264 L162 236 Z" fill="#232c3d"/>
|
|
7
|
+
<path d="M350 236 L398 264 L418 334 L366 300 Z" fill="#2e384e"/>
|
|
8
|
+
<path d="M162 236 L114 264 L94 334 L146 300 Z" fill="#2e384e"/>
|
|
9
|
+
<path d="M418 334 L412 416 L392 402 L384 458 L360 436 L338 480 L366 300 Z" fill="#1b2231"/>
|
|
10
|
+
<path d="M94 334 L100 416 L120 402 L128 458 L152 436 L174 480 L146 300 Z" fill="#1b2231"/>
|
|
11
|
+
<!-- the red breast is a cut ruby -->
|
|
12
|
+
<path d="M292.7 248.5 L344.7 309.1 L300.3 330.6 L274.4 300.3 Z" fill="#e0244a"/>
|
|
13
|
+
<path d="M344.7 309.1 L344.7 394.9 L300.3 373.4 L300.3 330.6 Z" fill="#e0244a"/>
|
|
14
|
+
<path d="M344.7 394.9 L292.7 455.5 L274.4 403.7 L300.3 373.4 Z" fill="#bc1c3d"/>
|
|
15
|
+
<path d="M292.7 455.5 L219.3 455.5 L237.6 403.7 L274.4 403.7 Z" fill="#bc1c3d"/>
|
|
16
|
+
<path d="M219.3 455.5 L167.3 394.9 L211.7 373.4 L237.6 403.7 Z" fill="#bc1c3d"/>
|
|
17
|
+
<path d="M167.3 394.9 L167.3 309.1 L211.7 330.6 L211.7 373.4 Z" fill="#e0244a"/>
|
|
18
|
+
<path d="M167.3 309.1 L219.3 248.5 L237.6 300.3 L211.7 330.6 Z" fill="#e0244a"/>
|
|
19
|
+
<path d="M219.3 248.5 L292.7 248.5 L274.4 300.3 L237.6 300.3 Z" fill="#ea5470"/>
|
|
20
|
+
<path d="M274.4 300.3 L300.3 330.6 L300.3 373.4 L274.4 403.7 L237.6 403.7 L211.7 373.4 L211.7 330.6 L237.6 300.3 Z" fill="#ea5470"/>
|
|
21
|
+
<!-- head with a crest -->
|
|
22
|
+
<path d="M256 34 L284 86 L322 52 L326 104 L364 152 L370 210 L340 252 L256 268 L172 252 L142 210 L148 152 L186 104 L190 52 L228 86 Z" fill="#232c3d"/>
|
|
23
|
+
<path d="M256 34 L284 86 L322 52 L326 104 L256 132 L186 104 L190 52 L228 86 Z" fill="#3a4660"/>
|
|
24
|
+
<path d="M364 152 L370 210 L340 252 L316 196 Z" fill="#151b27"/>
|
|
25
|
+
<path d="M148 152 L142 210 L172 252 L196 196 Z" fill="#151b27"/>
|
|
26
|
+
<!-- domino mask -->
|
|
27
|
+
<path d="M256 170 L292 148 L340 144 L392 116 L376 166 L344 198 L298 200 L256 186 L214 200 L168 198 L136 166 L120 116 L172 144 L220 148 Z" fill="#07090d"/>
|
|
28
|
+
<path d="M270 178 L328 160 L352 164 L334 186 L286 192 Z" fill="#ffffff"/>
|
|
29
|
+
<path d="M242 178 L184 160 L160 164 L178 186 L226 192 Z" fill="#ffffff"/>
|
|
30
|
+
<path d="M256 190 L276 210 L256 268 L236 210 Z" fill="#f6a723"/>
|
|
31
|
+
</svg>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="64 16 1007 532" role="img" aria-label="Robin">
|
|
2
|
+
<title>Robin</title>
|
|
3
|
+
<g transform="translate(0 0)">
|
|
4
|
+
<!-- white keyline: invisible on light backgrounds, outlines the bird on dark ones -->
|
|
5
|
+
<g fill="#ffffff" stroke="#ffffff" stroke-width="26" stroke-linejoin="round"><path d="M228 462 L256 530 L284 462 Z" fill="#232c3d"/><path d="M281 460 L291 460 L290 500 L308 512 L306 518 L288 508 L286 520 L284 508 L268 518 L266 512 L282 500 Z" fill="#f6a723"/><path d="M231 460 L221 460 L222 500 L204 512 L206 518 L224 508 L226 520 L228 508 L244 518 L246 512 L230 500 Z" fill="#f6a723"/><path d="M256 240 L350 236 L398 264 L418 334 L412 416 L392 402 L384 458 L360 436 L338 480 L300 466 L256 472 L212 466 L174 480 L152 436 L128 458 L120 402 L100 416 L94 334 L114 264 L162 236 Z" fill="#ffffff"/><path d="M256 34 L284 86 L322 52 L326 104 L364 152 L370 210 L340 252 L256 268 L172 252 L142 210 L148 152 L186 104 L190 52 L228 86 Z" fill="#ffffff"/></g>
|
|
6
|
+
<path d="M228 462 L256 530 L284 462 Z" fill="#232c3d"/>
|
|
7
|
+
<path d="M281 460 L291 460 L290 500 L308 512 L306 518 L288 508 L286 520 L284 508 L268 518 L266 512 L282 500 Z" fill="#f6a723"/>
|
|
8
|
+
<path d="M231 460 L221 460 L222 500 L204 512 L206 518 L224 508 L226 520 L228 508 L244 518 L246 512 L230 500 Z" fill="#f6a723"/>
|
|
9
|
+
<!-- folded wings as a cape -->
|
|
10
|
+
<path d="M256 240 L350 236 L398 264 L418 334 L412 416 L392 402 L384 458 L360 436 L338 480 L300 466 L256 472 L212 466 L174 480 L152 436 L128 458 L120 402 L100 416 L94 334 L114 264 L162 236 Z" fill="#232c3d"/>
|
|
11
|
+
<path d="M350 236 L398 264 L418 334 L366 300 Z" fill="#2e384e"/>
|
|
12
|
+
<path d="M162 236 L114 264 L94 334 L146 300 Z" fill="#2e384e"/>
|
|
13
|
+
<path d="M418 334 L412 416 L392 402 L384 458 L360 436 L338 480 L366 300 Z" fill="#1b2231"/>
|
|
14
|
+
<path d="M94 334 L100 416 L120 402 L128 458 L152 436 L174 480 L146 300 Z" fill="#1b2231"/>
|
|
15
|
+
<!-- the red breast is a cut ruby -->
|
|
16
|
+
<path d="M292.7 248.5 L344.7 309.1 L300.3 330.6 L274.4 300.3 Z" fill="#e0244a"/>
|
|
17
|
+
<path d="M344.7 309.1 L344.7 394.9 L300.3 373.4 L300.3 330.6 Z" fill="#e0244a"/>
|
|
18
|
+
<path d="M344.7 394.9 L292.7 455.5 L274.4 403.7 L300.3 373.4 Z" fill="#bc1c3d"/>
|
|
19
|
+
<path d="M292.7 455.5 L219.3 455.5 L237.6 403.7 L274.4 403.7 Z" fill="#bc1c3d"/>
|
|
20
|
+
<path d="M219.3 455.5 L167.3 394.9 L211.7 373.4 L237.6 403.7 Z" fill="#bc1c3d"/>
|
|
21
|
+
<path d="M167.3 394.9 L167.3 309.1 L211.7 330.6 L211.7 373.4 Z" fill="#e0244a"/>
|
|
22
|
+
<path d="M167.3 309.1 L219.3 248.5 L237.6 300.3 L211.7 330.6 Z" fill="#e0244a"/>
|
|
23
|
+
<path d="M219.3 248.5 L292.7 248.5 L274.4 300.3 L237.6 300.3 Z" fill="#ea5470"/>
|
|
24
|
+
<path d="M274.4 300.3 L300.3 330.6 L300.3 373.4 L274.4 403.7 L237.6 403.7 L211.7 373.4 L211.7 330.6 L237.6 300.3 Z" fill="#ea5470"/>
|
|
25
|
+
<!-- head with a crest -->
|
|
26
|
+
<path d="M256 34 L284 86 L322 52 L326 104 L364 152 L370 210 L340 252 L256 268 L172 252 L142 210 L148 152 L186 104 L190 52 L228 86 Z" fill="#232c3d"/>
|
|
27
|
+
<path d="M256 34 L284 86 L322 52 L326 104 L256 132 L186 104 L190 52 L228 86 Z" fill="#3a4660"/>
|
|
28
|
+
<path d="M364 152 L370 210 L340 252 L316 196 Z" fill="#151b27"/>
|
|
29
|
+
<path d="M148 152 L142 210 L172 252 L196 196 Z" fill="#151b27"/>
|
|
30
|
+
<!-- domino mask -->
|
|
31
|
+
<path d="M256 170 L292 148 L340 144 L392 116 L376 166 L344 198 L298 200 L256 186 L214 200 L168 198 L136 166 L120 116 L172 144 L220 148 Z" fill="#07090d"/>
|
|
32
|
+
<path d="M270 178 L328 160 L352 164 L334 186 L286 192 Z" fill="#ffffff"/>
|
|
33
|
+
<path d="M242 178 L184 160 L160 164 L178 186 L226 192 Z" fill="#ffffff"/>
|
|
34
|
+
<path d="M256 190 L276 210 L256 268 L236 210 Z" fill="#f6a723"/>
|
|
35
|
+
</g>
|
|
36
|
+
<g transform="translate(470 196) scale(0.78)"><path d="M0 0 L114 0 L140 45.03 L140 74.97 L114 120 L160.19 200 L114.19 200 L68 120 L46 120 L46 200 L0 200 Z M46 46 L87.44 46 L94 57.36 L94 62.64 L87.44 74 L46 74 Z M196.19 0 L294.19 0 L320.19 45.03 L320.19 154.97 L294.19 200 L196.19 200 L170.19 154.97 L170.19 45.03 Z M230.49 40 L259.89 40 L274.19 64.77 L274.19 135.23 L259.89 160 L230.49 160 L216.19 135.23 L216.19 64.77 Z M344.19 0 L458.19 0 L484.19 45.03 L484.19 75.75 L470.19 100 L484.19 124.25 L484.19 154.97 L458.19 200 L344.19 200 Z M390.19 46 L431.63 46 L438.19 57.36 L438.19 63.43 L430.35 77 L390.19 77 Z M390.19 123 L430.35 123 L438.19 136.57 L438.19 142.64 L431.63 154 L390.19 154 Z M508.19 34.53 L528.12 0 L554.19 0 L554.19 200 L508.19 200 Z M578.19 0 L624.19 0 L693.66 120.33 L693.66 0 L739.66 0 L739.66 200 L693.66 200 L624.19 79.67 L624.19 200 L578.19 200 Z" fill="#e0244a" fill-rule="evenodd"/></g>
|
|
37
|
+
</svg>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="64 16 384 532" role="img" aria-label="Robin">
|
|
2
|
+
<title>Robin</title>
|
|
3
|
+
<defs>
|
|
4
|
+
<mask id="robin-cut" maskUnits="userSpaceOnUse" x="0" y="0" width="512" height="560">
|
|
5
|
+
<rect width="512" height="560" fill="#fff"/>
|
|
6
|
+
<path d="M270 178 L328 160 L352 164 L334 186 L286 192 Z"/><path d="M242 178 L184 160 L160 164 L178 186 L226 192 Z"/><path d="M256 190 L276 210 L256 268 L236 210 Z"/>
|
|
7
|
+
</mask>
|
|
8
|
+
</defs>
|
|
9
|
+
<g fill="currentColor" mask="url(#robin-cut)">
|
|
10
|
+
<path d="M256 240 L350 236 L398 264 L418 334 L412 416 L392 402 L384 458 L360 436 L338 480 L300 466 L256 472 L212 466 L174 480 L152 436 L128 458 L120 402 L100 416 L94 334 L114 264 L162 236 Z"/><path d="M256 34 L284 86 L322 52 L326 104 L364 152 L370 210 L340 252 L256 268 L172 252 L142 210 L148 152 L186 104 L190 52 L228 86 Z"/><path d="M256 170 L292 148 L340 144 L392 116 L376 166 L344 198 L298 200 L256 186 L214 200 L168 198 L136 166 L120 116 L172 144 L220 148 Z"/><path d="M228 462 L256 530 L284 462 Z"/><path d="M281 460 L291 460 L290 500 L308 512 L306 518 L288 508 L286 520 L284 508 L268 518 L266 512 L282 500 Z"/><path d="M231 460 L221 460 L222 500 L204 512 L206 518 L224 508 L226 520 L228 508 L244 518 L246 512 L230 500 Z"/>
|
|
11
|
+
</g>
|
|
12
|
+
</svg>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-6 -6 752 212" role="img" aria-label="Robin">
|
|
2
|
+
<title>Robin</title>
|
|
3
|
+
<path d="M0 0 L114 0 L140 45.03 L140 74.97 L114 120 L160.19 200 L114.19 200 L68 120 L46 120 L46 200 L0 200 Z M46 46 L87.44 46 L94 57.36 L94 62.64 L87.44 74 L46 74 Z M196.19 0 L294.19 0 L320.19 45.03 L320.19 154.97 L294.19 200 L196.19 200 L170.19 154.97 L170.19 45.03 Z M230.49 40 L259.89 40 L274.19 64.77 L274.19 135.23 L259.89 160 L230.49 160 L216.19 135.23 L216.19 64.77 Z M344.19 0 L458.19 0 L484.19 45.03 L484.19 75.75 L470.19 100 L484.19 124.25 L484.19 154.97 L458.19 200 L344.19 200 Z M390.19 46 L431.63 46 L438.19 57.36 L438.19 63.43 L430.35 77 L390.19 77 Z M390.19 123 L430.35 123 L438.19 136.57 L438.19 142.64 L431.63 154 L390.19 154 Z M508.19 34.53 L528.12 0 L554.19 0 L554.19 200 L508.19 200 Z M578.19 0 L624.19 0 L693.66 120.33 L693.66 0 L739.66 0 L739.66 200 L693.66 200 L624.19 79.67 L624.19 200 L578.19 200 Z" fill="#e0244a" fill-rule="evenodd"/>
|
|
4
|
+
</svg>
|
data/assets/robin.svg
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="64 16 384 532" role="img" aria-label="Robin">
|
|
2
|
+
<title>Robin</title>
|
|
3
|
+
<!-- white keyline: invisible on light backgrounds, outlines the bird on dark ones -->
|
|
4
|
+
<g fill="#ffffff" stroke="#ffffff" stroke-width="26" stroke-linejoin="round"><path d="M228 462 L256 530 L284 462 Z" fill="#232c3d"/><path d="M281 460 L291 460 L290 500 L308 512 L306 518 L288 508 L286 520 L284 508 L268 518 L266 512 L282 500 Z" fill="#f6a723"/><path d="M231 460 L221 460 L222 500 L204 512 L206 518 L224 508 L226 520 L228 508 L244 518 L246 512 L230 500 Z" fill="#f6a723"/><path d="M256 240 L350 236 L398 264 L418 334 L412 416 L392 402 L384 458 L360 436 L338 480 L300 466 L256 472 L212 466 L174 480 L152 436 L128 458 L120 402 L100 416 L94 334 L114 264 L162 236 Z" fill="#ffffff"/><path d="M256 34 L284 86 L322 52 L326 104 L364 152 L370 210 L340 252 L256 268 L172 252 L142 210 L148 152 L186 104 L190 52 L228 86 Z" fill="#ffffff"/></g>
|
|
5
|
+
<path d="M228 462 L256 530 L284 462 Z" fill="#232c3d"/>
|
|
6
|
+
<path d="M281 460 L291 460 L290 500 L308 512 L306 518 L288 508 L286 520 L284 508 L268 518 L266 512 L282 500 Z" fill="#f6a723"/>
|
|
7
|
+
<path d="M231 460 L221 460 L222 500 L204 512 L206 518 L224 508 L226 520 L228 508 L244 518 L246 512 L230 500 Z" fill="#f6a723"/>
|
|
8
|
+
<!-- folded wings as a cape -->
|
|
9
|
+
<path d="M256 240 L350 236 L398 264 L418 334 L412 416 L392 402 L384 458 L360 436 L338 480 L300 466 L256 472 L212 466 L174 480 L152 436 L128 458 L120 402 L100 416 L94 334 L114 264 L162 236 Z" fill="#232c3d"/>
|
|
10
|
+
<path d="M350 236 L398 264 L418 334 L366 300 Z" fill="#2e384e"/>
|
|
11
|
+
<path d="M162 236 L114 264 L94 334 L146 300 Z" fill="#2e384e"/>
|
|
12
|
+
<path d="M418 334 L412 416 L392 402 L384 458 L360 436 L338 480 L366 300 Z" fill="#1b2231"/>
|
|
13
|
+
<path d="M94 334 L100 416 L120 402 L128 458 L152 436 L174 480 L146 300 Z" fill="#1b2231"/>
|
|
14
|
+
<!-- the red breast is a cut ruby -->
|
|
15
|
+
<path d="M292.7 248.5 L344.7 309.1 L300.3 330.6 L274.4 300.3 Z" fill="#e0244a"/>
|
|
16
|
+
<path d="M344.7 309.1 L344.7 394.9 L300.3 373.4 L300.3 330.6 Z" fill="#e0244a"/>
|
|
17
|
+
<path d="M344.7 394.9 L292.7 455.5 L274.4 403.7 L300.3 373.4 Z" fill="#bc1c3d"/>
|
|
18
|
+
<path d="M292.7 455.5 L219.3 455.5 L237.6 403.7 L274.4 403.7 Z" fill="#bc1c3d"/>
|
|
19
|
+
<path d="M219.3 455.5 L167.3 394.9 L211.7 373.4 L237.6 403.7 Z" fill="#bc1c3d"/>
|
|
20
|
+
<path d="M167.3 394.9 L167.3 309.1 L211.7 330.6 L211.7 373.4 Z" fill="#e0244a"/>
|
|
21
|
+
<path d="M167.3 309.1 L219.3 248.5 L237.6 300.3 L211.7 330.6 Z" fill="#e0244a"/>
|
|
22
|
+
<path d="M219.3 248.5 L292.7 248.5 L274.4 300.3 L237.6 300.3 Z" fill="#ea5470"/>
|
|
23
|
+
<path d="M274.4 300.3 L300.3 330.6 L300.3 373.4 L274.4 403.7 L237.6 403.7 L211.7 373.4 L211.7 330.6 L237.6 300.3 Z" fill="#ea5470"/>
|
|
24
|
+
<!-- head with a crest -->
|
|
25
|
+
<path d="M256 34 L284 86 L322 52 L326 104 L364 152 L370 210 L340 252 L256 268 L172 252 L142 210 L148 152 L186 104 L190 52 L228 86 Z" fill="#232c3d"/>
|
|
26
|
+
<path d="M256 34 L284 86 L322 52 L326 104 L256 132 L186 104 L190 52 L228 86 Z" fill="#3a4660"/>
|
|
27
|
+
<path d="M364 152 L370 210 L340 252 L316 196 Z" fill="#151b27"/>
|
|
28
|
+
<path d="M148 152 L142 210 L172 252 L196 196 Z" fill="#151b27"/>
|
|
29
|
+
<!-- domino mask -->
|
|
30
|
+
<path d="M256 170 L292 148 L340 144 L392 116 L376 166 L344 198 L298 200 L256 186 L214 200 L168 198 L136 166 L120 116 L172 144 L220 148 Z" fill="#07090d"/>
|
|
31
|
+
<path d="M270 178 L328 160 L352 164 L334 186 L286 192 Z" fill="#ffffff"/>
|
|
32
|
+
<path d="M242 178 L184 160 L160 164 L178 186 L226 192 Z" fill="#ffffff"/>
|
|
33
|
+
<path d="M256 190 L276 210 L256 268 L236 210 Z" fill="#f6a723"/>
|
|
34
|
+
</svg>
|
data/exe/robin
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Blocking.java - waiting the way JRuby's own blocking calls do.
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) Robin contributors. Licensed under the LGPL-3.0.
|
|
5
|
+
*/
|
|
6
|
+
package robin_resp;
|
|
7
|
+
|
|
8
|
+
import org.jruby.RubyThread;
|
|
9
|
+
import org.jruby.runtime.ThreadContext;
|
|
10
|
+
|
|
11
|
+
/** Runs blocking tasks so Thread#raise and Thread#kill can interrupt them. */
|
|
12
|
+
final class Blocking {
|
|
13
|
+
private Blocking() {}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The task's result. JRuby calls the task's wakeup for Thread#raise or Thread#kill, then raises
|
|
17
|
+
* the Ruby exception once the task returns. When a Java interrupt cuts the task short with no
|
|
18
|
+
* Ruby exception behind it (Thread#wakeup), the result is ifInterrupted.
|
|
19
|
+
*/
|
|
20
|
+
static <D, R> R run(ThreadContext context, D data, RubyThread.Task<D, R> task, R ifInterrupted) {
|
|
21
|
+
try {
|
|
22
|
+
return context.getThread().executeTask(context, data, task);
|
|
23
|
+
} catch (InterruptedException e) {
|
|
24
|
+
return ifInterrupted;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* NativeIO.java - the JRuby counterpart of robin_resp.c's socket reader.
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) Robin contributors. Licensed under the LGPL-3.0.
|
|
5
|
+
*/
|
|
6
|
+
package robin_resp;
|
|
7
|
+
|
|
8
|
+
import static org.jruby.api.Convert.asBoolean;
|
|
9
|
+
import static org.jruby.api.Convert.castAsString;
|
|
10
|
+
import static org.jruby.api.Convert.toDouble;
|
|
11
|
+
|
|
12
|
+
import java.io.IOException;
|
|
13
|
+
import java.lang.ref.Cleaner;
|
|
14
|
+
import java.nio.ByteBuffer;
|
|
15
|
+
import java.nio.channels.ReadableByteChannel;
|
|
16
|
+
import java.nio.channels.SelectableChannel;
|
|
17
|
+
import java.nio.channels.SelectionKey;
|
|
18
|
+
import java.nio.channels.Selector;
|
|
19
|
+
import org.jruby.RubyFixnum;
|
|
20
|
+
import org.jruby.RubyIO;
|
|
21
|
+
import org.jruby.RubyString;
|
|
22
|
+
import org.jruby.RubyThread;
|
|
23
|
+
import org.jruby.anno.JRubyMethod;
|
|
24
|
+
import org.jruby.anno.JRubyModule;
|
|
25
|
+
import org.jruby.runtime.ThreadContext;
|
|
26
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
|
27
|
+
import org.jruby.runtime.builtin.InternalVariables;
|
|
28
|
+
import org.jruby.util.io.ChannelFD;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Robin::Redis::NativeIO: reads replies off a socket.
|
|
32
|
+
*
|
|
33
|
+
* <p>Each socket gets a selector of its own, made the first time a read has to wait and kept (with
|
|
34
|
+
* the socket registered on it) until the socket is garbage collected. Waiting is then a single
|
|
35
|
+
* select, with no registering, cancelling or blocking-mode changes per wait, and any number of
|
|
36
|
+
* threads wait in parallel.
|
|
37
|
+
*/
|
|
38
|
+
@JRubyModule(name = "Robin::Redis::NativeIO")
|
|
39
|
+
public final class NativeIO {
|
|
40
|
+
/** Bytes per read: plenty for a typical reply; longer ones take more reads. */
|
|
41
|
+
static final int READ_CHUNK = 16384;
|
|
42
|
+
|
|
43
|
+
/** Where a socket's Reader is kept (an internal variable of its IO). */
|
|
44
|
+
static final String READER = "robin_resp_reader";
|
|
45
|
+
|
|
46
|
+
/** What Reader#fill returns at the end of the stream. */
|
|
47
|
+
static final int END = -1;
|
|
48
|
+
|
|
49
|
+
/** What Reader#fill returns when nothing arrived in time. */
|
|
50
|
+
static final int TIMED_OUT = -2;
|
|
51
|
+
|
|
52
|
+
private static final Cleaner CLEANER = Cleaner.create();
|
|
53
|
+
|
|
54
|
+
private NativeIO() {}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Robin::Redis::NativeIO.fill(io, buffer, timeout) -> Integer, nil or false
|
|
58
|
+
*
|
|
59
|
+
* <p>Appends what arrives on io within timeout seconds to buffer and returns how many bytes that
|
|
60
|
+
* was; nil when the server closed the connection, false when nothing arrived in time. A failed
|
|
61
|
+
* read raises IOError or SystemCallError. Thread#raise and Thread#kill interrupt the wait; other
|
|
62
|
+
* interruptions don't.
|
|
63
|
+
*/
|
|
64
|
+
@JRubyMethod(name = "fill", module = true)
|
|
65
|
+
public static IRubyObject fill(
|
|
66
|
+
ThreadContext context,
|
|
67
|
+
IRubyObject self,
|
|
68
|
+
IRubyObject io,
|
|
69
|
+
IRubyObject buffer,
|
|
70
|
+
IRubyObject timeout) {
|
|
71
|
+
RubyString buf = castAsString(context, buffer);
|
|
72
|
+
long millis = timeoutMillis(toDouble(context, timeout));
|
|
73
|
+
Reader reader = reader(context, io);
|
|
74
|
+
int count;
|
|
75
|
+
try {
|
|
76
|
+
count = reader.fill(context, buf, millis);
|
|
77
|
+
} catch (IOException e) {
|
|
78
|
+
throw context.runtime.newIOErrorFromException(e);
|
|
79
|
+
}
|
|
80
|
+
switch (count) {
|
|
81
|
+
case TIMED_OUT:
|
|
82
|
+
return context.fals;
|
|
83
|
+
case END:
|
|
84
|
+
return context.nil;
|
|
85
|
+
default:
|
|
86
|
+
return RubyFixnum.newFixnum(context.runtime, count);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Robin::Redis::NativeIO.stale?(io) -> true or false
|
|
92
|
+
*
|
|
93
|
+
* <p>Whether a connection between commands can't be used: the server closed it, it failed, or it
|
|
94
|
+
* holds bytes nothing asked for. Doesn't wait, so it's cheap enough to run before every command.
|
|
95
|
+
* A byte it had to read to find out is kept for the next fill.
|
|
96
|
+
*/
|
|
97
|
+
@JRubyMethod(name = "stale?", module = true)
|
|
98
|
+
public static IRubyObject stale(ThreadContext context, IRubyObject self, IRubyObject io) {
|
|
99
|
+
boolean stale;
|
|
100
|
+
try {
|
|
101
|
+
stale = reader(context, io).stale();
|
|
102
|
+
} catch (IOException | RuntimeException e) {
|
|
103
|
+
stale = true;
|
|
104
|
+
}
|
|
105
|
+
return asBoolean(context, stale);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Seconds to whole milliseconds, rounded up (so a short wait isn't none), from 0 to 2^31-1. */
|
|
109
|
+
static long timeoutMillis(double seconds) {
|
|
110
|
+
return (long) Math.ceil(Math.min(Math.max(seconds * 1000.0, 0), Integer.MAX_VALUE));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The io's Reader, made on first use. Raises IOError for a closed io. */
|
|
114
|
+
static Reader reader(ThreadContext context, IRubyObject io) {
|
|
115
|
+
RubyIO rubyIO = RubyIO.convertToIO(context, io);
|
|
116
|
+
InternalVariables variables = rubyIO.getInternalVariables();
|
|
117
|
+
if (variables.getInternalVariable(READER) instanceof Reader reader) {
|
|
118
|
+
return reader;
|
|
119
|
+
}
|
|
120
|
+
Reader reader = new Reader(rubyIO.getOpenFileChecked().fd());
|
|
121
|
+
variables.setInternalVariable(READER, reader);
|
|
122
|
+
CLEANER.register(rubyIO, reader::close);
|
|
123
|
+
return reader;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Reads from one channel, waiting with a selector of its own. */
|
|
127
|
+
static final class Reader implements RubyThread.Task<Reader, Void> {
|
|
128
|
+
final ReadableByteChannel channel;
|
|
129
|
+
final SelectableChannel selectable;
|
|
130
|
+
private final byte[] chunk = new byte[READ_CHUNK];
|
|
131
|
+
private final ByteBuffer chunkBuffer = ByteBuffer.wrap(chunk);
|
|
132
|
+
Selector selector;
|
|
133
|
+
private long waitMillis;
|
|
134
|
+
|
|
135
|
+
/** A byte stale? had to read, or -1. */
|
|
136
|
+
int pending = -1;
|
|
137
|
+
|
|
138
|
+
Reader(ChannelFD fd) {
|
|
139
|
+
channel = fd.chRead;
|
|
140
|
+
selectable = fd.chSelect;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** Bytes appended, END at the end of the stream, or TIMED_OUT. */
|
|
144
|
+
int fill(ThreadContext context, RubyString buf, long millis) throws IOException {
|
|
145
|
+
if (pending >= 0) {
|
|
146
|
+
buf.cat((byte) pending);
|
|
147
|
+
pending = -1;
|
|
148
|
+
return 1 + Math.max(read(buf), 0);
|
|
149
|
+
}
|
|
150
|
+
// A file's read never comes back empty, so files never wait.
|
|
151
|
+
long deadline = System.nanoTime() + (millis * 1_000_000);
|
|
152
|
+
int count = read(buf);
|
|
153
|
+
while (count == 0) {
|
|
154
|
+
long remaining = Math.max(Math.ceilDiv(deadline - System.nanoTime(), 1_000_000), 0);
|
|
155
|
+
if (remaining == 0) {
|
|
156
|
+
return TIMED_OUT;
|
|
157
|
+
}
|
|
158
|
+
await(context, remaining);
|
|
159
|
+
count = read(buf);
|
|
160
|
+
}
|
|
161
|
+
return count;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Whether there's anything to read (or the stream ended), without waiting. */
|
|
165
|
+
boolean stale() throws IOException {
|
|
166
|
+
if (pending >= 0 || selectable == null) {
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
chunkBuffer.clear().limit(1);
|
|
170
|
+
int count = nonBlocking().read(chunkBuffer);
|
|
171
|
+
if (count > 0) {
|
|
172
|
+
pending = chunk[0] & 0xff;
|
|
173
|
+
}
|
|
174
|
+
return count != 0;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Appends what's there now (without waiting) and returns its size, or END. */
|
|
178
|
+
private int read(RubyString buf) throws IOException {
|
|
179
|
+
chunkBuffer.clear();
|
|
180
|
+
int count = nonBlocking().read(chunkBuffer);
|
|
181
|
+
buf.cat(chunk, 0, Math.max(count, 0));
|
|
182
|
+
return count;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The channel, made non-blocking if it can be (a socket's always can). */
|
|
186
|
+
private ReadableByteChannel nonBlocking() throws IOException {
|
|
187
|
+
if (selectable != null) {
|
|
188
|
+
selectable.configureBlocking(false);
|
|
189
|
+
}
|
|
190
|
+
return channel;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Waits up to millis for something to read; Thread#raise and Thread#kill interrupt it. */
|
|
194
|
+
private void await(ThreadContext context, long millis) throws IOException {
|
|
195
|
+
if (selector == null) {
|
|
196
|
+
selector = selectable.provider().openSelector();
|
|
197
|
+
selectable.register(selector, SelectionKey.OP_READ);
|
|
198
|
+
}
|
|
199
|
+
waitMillis = millis;
|
|
200
|
+
Blocking.run(context, this, this, null);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
@Override
|
|
204
|
+
public Void run(ThreadContext context, Reader reader) {
|
|
205
|
+
try {
|
|
206
|
+
selector.select(waitMillis);
|
|
207
|
+
} catch (IOException e) {
|
|
208
|
+
throw context.runtime.newIOErrorFromException(e);
|
|
209
|
+
}
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
@Override
|
|
214
|
+
public void wakeup(RubyThread thread, Reader reader) {
|
|
215
|
+
selector.wakeup();
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Closes the selector, if any (when the socket is garbage collected). */
|
|
219
|
+
void close() {
|
|
220
|
+
try {
|
|
221
|
+
if (selector != null) {
|
|
222
|
+
selector.close();
|
|
223
|
+
}
|
|
224
|
+
} catch (IOException e) {
|
|
225
|
+
// Nothing to do: the selector's file descriptor is gone either way.
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* NativeRESP.java - the JRuby counterpart of robin_resp.c's parser, plus a
|
|
3
|
+
* command encoder.
|
|
4
|
+
*
|
|
5
|
+
* Copyright (C) Robin contributors. Licensed under the LGPL-3.0.
|
|
6
|
+
*/
|
|
7
|
+
package robin_resp;
|
|
8
|
+
|
|
9
|
+
import static org.jruby.api.Convert.castAsArray;
|
|
10
|
+
import static org.jruby.api.Convert.castAsString;
|
|
11
|
+
import static org.jruby.api.Convert.toLong;
|
|
12
|
+
import static org.jruby.api.Create.newArray;
|
|
13
|
+
import static org.jruby.api.Create.newString;
|
|
14
|
+
import static org.jruby.api.Error.argumentError;
|
|
15
|
+
|
|
16
|
+
import java.math.BigInteger;
|
|
17
|
+
import java.nio.charset.StandardCharsets;
|
|
18
|
+
import org.jcodings.specific.UTF8Encoding;
|
|
19
|
+
import org.jruby.RubyArray;
|
|
20
|
+
import org.jruby.RubyBignum;
|
|
21
|
+
import org.jruby.RubyClass;
|
|
22
|
+
import org.jruby.RubyFixnum;
|
|
23
|
+
import org.jruby.RubyString;
|
|
24
|
+
import org.jruby.anno.JRubyMethod;
|
|
25
|
+
import org.jruby.anno.JRubyModule;
|
|
26
|
+
import org.jruby.exceptions.RaiseException;
|
|
27
|
+
import org.jruby.runtime.ThreadContext;
|
|
28
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
|
29
|
+
import org.jruby.util.ByteList;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Robin::Redis::NativeRESP: a drop-in replacement for the pure-Ruby Robin::Redis::RESP (RESP2),
|
|
33
|
+
* with identical results for well-formed replies.
|
|
34
|
+
*
|
|
35
|
+
* <ul>
|
|
36
|
+
* <li>{@code parse(buf, pos)} returns {@code [value, next_pos]} when buf holds a complete reply
|
|
37
|
+
* at pos, nil when more bytes are needed;
|
|
38
|
+
* <li>error replies become Robin::Redis::CommandError instances (returned, not raised);
|
|
39
|
+
* <li>strings are tagged UTF-8;
|
|
40
|
+
* <li>an unknown type byte or a malformed integer line raises Robin::Redis::ProtocolError;
|
|
41
|
+
* <li>{@code encode(args, out = "".b)} appends a command to out. Strings and Integers go out as
|
|
42
|
+
* their bytes and digits; anything else as its to_s.
|
|
43
|
+
* </ul>
|
|
44
|
+
*/
|
|
45
|
+
@JRubyModule(name = "Robin::Redis::NativeRESP")
|
|
46
|
+
public final class NativeRESP {
|
|
47
|
+
static final int MAX_DEPTH = 512;
|
|
48
|
+
|
|
49
|
+
private static final byte[] CRLF = {'\r', '\n'};
|
|
50
|
+
|
|
51
|
+
private NativeRESP() {}
|
|
52
|
+
|
|
53
|
+
/** Robin::Redis::NativeRESP.parse(buf, pos) -> [value, next_pos] or nil */
|
|
54
|
+
@JRubyMethod(name = "parse", module = true)
|
|
55
|
+
public static IRubyObject parse(
|
|
56
|
+
ThreadContext context, IRubyObject self, IRubyObject buf, IRubyObject pos) {
|
|
57
|
+
long start = toLong(context, pos);
|
|
58
|
+
ByteList bytes = castAsString(context, buf).getByteList();
|
|
59
|
+
if (start < 0) {
|
|
60
|
+
throw argumentError(context, "negative offset");
|
|
61
|
+
}
|
|
62
|
+
Parser parser = new Parser(context, bytes);
|
|
63
|
+
IRubyObject value = parser.parseAt(start);
|
|
64
|
+
if (value == null) {
|
|
65
|
+
return context.nil;
|
|
66
|
+
}
|
|
67
|
+
return newArray(context, value, RubyFixnum.newFixnum(context.runtime, parser.next));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Robin::Redis::NativeRESP.encode(args, out = "".b) -> out */
|
|
71
|
+
@JRubyMethod(name = "encode", module = true)
|
|
72
|
+
public static IRubyObject encode(ThreadContext context, IRubyObject self, IRubyObject args) {
|
|
73
|
+
return encode(context, self, args, RubyString.newEmptyBinaryString(context.runtime));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@JRubyMethod(name = "encode", module = true)
|
|
77
|
+
public static IRubyObject encode(
|
|
78
|
+
ThreadContext context, IRubyObject self, IRubyObject args, IRubyObject out) {
|
|
79
|
+
RubyArray<?> list = castAsArray(context, args, "Array");
|
|
80
|
+
RubyString target = castAsString(context, out);
|
|
81
|
+
int count = list.size();
|
|
82
|
+
ByteList encoded = new ByteList();
|
|
83
|
+
header(encoded, '*', count);
|
|
84
|
+
for (int i = 0; i < count; i++) {
|
|
85
|
+
ByteList arg = argument(context, list.eltOk(i));
|
|
86
|
+
header(encoded, '$', arg.realSize());
|
|
87
|
+
encoded.append(arg);
|
|
88
|
+
encoded.append(CRLF);
|
|
89
|
+
}
|
|
90
|
+
target.cat(encoded);
|
|
91
|
+
return target;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Appends a type byte, a number and CRLF. */
|
|
95
|
+
private static void header(ByteList out, char type, long number) {
|
|
96
|
+
out.append(type);
|
|
97
|
+
out.append(digits(number));
|
|
98
|
+
out.append(CRLF);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private static byte[] digits(long value) {
|
|
102
|
+
return Long.toString(value).getBytes(StandardCharsets.US_ASCII);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** What arg.to_s would give, without calling Ruby for Strings and Integers. */
|
|
106
|
+
private static ByteList argument(ThreadContext context, IRubyObject arg) {
|
|
107
|
+
if (arg instanceof RubyString string) {
|
|
108
|
+
return string.getByteList();
|
|
109
|
+
}
|
|
110
|
+
if (arg instanceof RubyFixnum fixnum) {
|
|
111
|
+
return new ByteList(digits(fixnum.getValue()), false);
|
|
112
|
+
}
|
|
113
|
+
return castAsString(context, arg.callMethod(context, "to_s")).getByteList();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** One parse: the buffer and where the last complete value ended. */
|
|
117
|
+
static final class Parser {
|
|
118
|
+
private final ThreadContext context;
|
|
119
|
+
private final byte[] bytes;
|
|
120
|
+
private final int begin;
|
|
121
|
+
private final long length;
|
|
122
|
+
private int depth;
|
|
123
|
+
long next;
|
|
124
|
+
|
|
125
|
+
Parser(ThreadContext context, ByteList buf) {
|
|
126
|
+
this.context = context;
|
|
127
|
+
this.bytes = buf.unsafeBytes();
|
|
128
|
+
this.begin = buf.begin();
|
|
129
|
+
this.length = buf.realSize();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** The value at pos (setting next past it), or null if incomplete. */
|
|
133
|
+
IRubyObject parseAt(long pos) {
|
|
134
|
+
long eol = findCrlf(pos);
|
|
135
|
+
if (eol < 0) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
long line = pos + 1;
|
|
139
|
+
long lineLength = eol - line;
|
|
140
|
+
long body = eol + 2;
|
|
141
|
+
switch (bytes[begin + (int) pos]) {
|
|
142
|
+
case '+':
|
|
143
|
+
next = body;
|
|
144
|
+
return utf8(line, lineLength);
|
|
145
|
+
case '-':
|
|
146
|
+
next = body;
|
|
147
|
+
return context
|
|
148
|
+
.runtime
|
|
149
|
+
.getClassFromPath("Robin::Redis::CommandError")
|
|
150
|
+
.callMethod(context, "new", utf8(line, lineLength));
|
|
151
|
+
case ':':
|
|
152
|
+
next = body;
|
|
153
|
+
return integer(line, lineLength);
|
|
154
|
+
case '$':
|
|
155
|
+
return bulk(length(line, lineLength), body);
|
|
156
|
+
case '*':
|
|
157
|
+
return array(length(line, lineLength), body);
|
|
158
|
+
default:
|
|
159
|
+
throw protocolError("unknown RESP type byte");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
private IRubyObject bulk(long size, long body) {
|
|
164
|
+
if (size < 0) {
|
|
165
|
+
next = body;
|
|
166
|
+
return context.nil;
|
|
167
|
+
}
|
|
168
|
+
if (size > length - body - 2) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
next = body + size + 2;
|
|
172
|
+
return utf8(body, size);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
private IRubyObject array(long count, long body) {
|
|
176
|
+
if (count < 0) {
|
|
177
|
+
next = body;
|
|
178
|
+
return context.nil;
|
|
179
|
+
}
|
|
180
|
+
// Each element needs at least 3 bytes; a count larger than what's
|
|
181
|
+
// left can't be complete yet. Avoids huge allocations.
|
|
182
|
+
if (count > (length - body) / 3) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
if (depth == MAX_DEPTH) {
|
|
186
|
+
throw protocolError("RESP reply nested too deeply");
|
|
187
|
+
}
|
|
188
|
+
depth++;
|
|
189
|
+
IRubyObject[] items = new IRubyObject[(int) count];
|
|
190
|
+
long pos = body;
|
|
191
|
+
for (int i = 0; i < count; i++) {
|
|
192
|
+
IRubyObject item = parseAt(pos);
|
|
193
|
+
if (item == null) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
items[i] = item;
|
|
197
|
+
pos = next;
|
|
198
|
+
}
|
|
199
|
+
depth--;
|
|
200
|
+
next = pos;
|
|
201
|
+
return RubyArray.newArrayMayCopy(context.runtime, items);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Index of the first CRLF at or after pos, or -1. */
|
|
205
|
+
private long findCrlf(long pos) {
|
|
206
|
+
for (long i = pos; i < length - 1; i++) {
|
|
207
|
+
if (bytes[begin + (int) i] == '\r' && bytes[begin + (int) i + 1] == '\n') {
|
|
208
|
+
return i;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return -1;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** The Integer for a line of the form -?[0-9]+. */
|
|
215
|
+
private IRubyObject integer(long line, long lineLength) {
|
|
216
|
+
int from = begin + (int) line;
|
|
217
|
+
int to = from + (int) lineLength;
|
|
218
|
+
int first = firstDigit(from, to);
|
|
219
|
+
try {
|
|
220
|
+
long value = digits(first, to);
|
|
221
|
+
return RubyFixnum.newFixnum(context.runtime, first == from ? value : -value);
|
|
222
|
+
} catch (ArithmeticException tooLong) {
|
|
223
|
+
String text = new String(bytes, from, to - from, StandardCharsets.US_ASCII);
|
|
224
|
+
return RubyBignum.bignorm(context.runtime, new BigInteger(text));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* A length or count. Long.MAX_VALUE when too large for a long (more than any buffer holds, so
|
|
230
|
+
* never complete); every negative becomes -1.
|
|
231
|
+
*/
|
|
232
|
+
private long length(long line, long lineLength) {
|
|
233
|
+
int from = begin + (int) line;
|
|
234
|
+
int to = from + (int) lineLength;
|
|
235
|
+
int first = firstDigit(from, to);
|
|
236
|
+
boolean negative = first != from;
|
|
237
|
+
try {
|
|
238
|
+
long value = digits(first, to);
|
|
239
|
+
return Math.max(negative ? -value : value, -1);
|
|
240
|
+
} catch (ArithmeticException tooLong) {
|
|
241
|
+
return negative ? -1 : Long.MAX_VALUE;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** Where the digits of -?[0-9]+ in bytes[from, to) start. (A CRLF always follows.) */
|
|
246
|
+
private int firstDigit(int from, int to) {
|
|
247
|
+
int first = bytes[from] == '-' ? from + 1 : from;
|
|
248
|
+
if (first == to) {
|
|
249
|
+
throw protocolError("invalid integer in RESP reply");
|
|
250
|
+
}
|
|
251
|
+
for (int i = first; i < to; i++) {
|
|
252
|
+
if (bytes[i] < '0' || bytes[i] > '9') {
|
|
253
|
+
throw protocolError("invalid integer in RESP reply");
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return first;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** The value of the digits in bytes[from, to); ArithmeticException past Long.MAX_VALUE. */
|
|
260
|
+
private long digits(int from, int to) {
|
|
261
|
+
long value = 0;
|
|
262
|
+
for (int i = from; i < to; i++) {
|
|
263
|
+
value = Math.addExact(Math.multiplyExact(value, 10), bytes[i] - '0');
|
|
264
|
+
}
|
|
265
|
+
return value;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
private RubyString utf8(long from, long size) {
|
|
269
|
+
ByteList copy =
|
|
270
|
+
new ByteList(bytes, begin + (int) from, (int) size, UTF8Encoding.INSTANCE, true);
|
|
271
|
+
return newString(context, copy);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
private RaiseException protocolError(String message) {
|
|
275
|
+
RubyClass error = (RubyClass) context.runtime.getClassFromPath("Robin::Redis::ProtocolError");
|
|
276
|
+
return RaiseException.from(context.runtime, error, message);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|