├── .gitignore ├── .travis.yml ├── LICENSE ├── artifactory.gradle ├── bintray.gradle ├── build.gradle ├── ci └── travis.sh ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main └── scala │ └── io │ └── rsocket │ └── transport │ └── akka │ ├── TcpDuplexConnection.scala │ ├── WebsocketDuplexConnection.scala │ ├── client │ ├── TcpClientTransport.scala │ └── WebsocketClientTransport.scala │ └── server │ ├── HttpServerBindingCloseable.scala │ ├── TcpServerBindingCloseable.scala │ ├── TcpServerTransport.scala │ └── WebsocketServerTransport.scala └── test ├── java └── io │ └── rsocket │ └── transport │ └── akka │ ├── NettyTcpPing.java │ ├── NettyTcpPongServer.java │ ├── TcpPing.java │ ├── TcpPongServer.java │ ├── TcpTransportTest.java │ └── WebsocketTransportTest.java └── resources └── logback-test.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled source # 2 | ################### 3 | *.com 4 | *.class 5 | *.dll 6 | *.exe 7 | *.o 8 | *.so 9 | 10 | # Packages # 11 | ############ 12 | # it's better to unpack these files and commit the raw source 13 | # git has its own built in compression methods 14 | *.7z 15 | *.dmg 16 | *.gz 17 | *.iso 18 | *.jar 19 | *.rar 20 | *.tar 21 | *.zip 22 | 23 | # Logs and databases # 24 | ###################### 25 | *.log 26 | 27 | # OS generated files # 28 | ###################### 29 | .DS_Store* 30 | ehthumbs.db 31 | Icon? 32 | Thumbs.db 33 | 34 | # Editor Files # 35 | ################ 36 | *~ 37 | *.swp 38 | 39 | # Gradle Files # 40 | ################ 41 | .gradle 42 | .ivy2 43 | .ivy2.cache 44 | .m2 45 | 46 | # Build output directies 47 | /target 48 | */target 49 | /build 50 | */build 51 | 52 | # IntelliJ specific files/directories 53 | out 54 | .idea 55 | *.ipr 56 | *.iws 57 | *.iml 58 | atlassian-ide-plugin.xml 59 | 60 | # Eclipse specific files/directories 61 | .classpath 62 | .project 63 | .settings 64 | .metadata 65 | 66 | # NetBeans specific files/directories 67 | .nbattrs 68 | /bin 69 | 70 | #.gitignore in subdirectory 71 | .gitignore 72 | 73 | ### infer ### 74 | # infer- http://fbinfer.com/ 75 | infer-out 76 | */infer-out 77 | .inferConfig 78 | */.inferConfig 79 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: openjdk8 3 | script: ci/travis.sh 4 | before_cache: 5 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 6 | notifications: 7 | email: false 8 | cache: 9 | directories: 10 | - $HOME/.gradle/caches/ 11 | - $HOME/.gradle/wrapper/ 12 | env: 13 | global: 14 | - secure: SZNz4YBQxkIe3RbOD7fUSS8LRDw5s0TfINUawUK2iUhUZ7v1Gccn3XQL82zpKHZ3a0n+5DyX5AZQwVBJ9sPVHStU175MOQMalAvy2Xzb+v+trrMO0qEm6/zi7pScHgpk65yeOjnOnAk6rDI1CGiDp4Hgq80O0n/9EaM418VPqtw3xkNTPyRE2+hvFzI4b/ioK6UazSUO/K6iijc5kSgo/F3ngirSHVvApklDD1Lgg/5/lAwFWjpOUErC69T6RCmcOH9V9Y2cXtvblbZYcAMG5fU3s8Tj+PUqBqRR+wONQIQbHEukNgZ+NTl5pdrFi1K0xYtmN0W1ziN9ibRepgcTBZ6qzTLCzTLeIDjVG2LBDEenWqX/AZrnpOh+RWM0HuQdwMuO5S7Suy5b0Hty/NfpZkRKmrs5BpD7wjUGfiPwvJhVnOhkYb5JVNzob0eahDKbPZuBHQ36Sg0OYNj/U1ySMf2dcWUH0xEfZaRDpPK1bJ6c2Q7WMfpmi1MJeqpAHm/9kCtThxnyOoTXG6Zt46mrLIgh5Mo6PLcItpuX2OA9QsQ/zUOdILqAfLABv2nfvZwlTOvocxwV/i2hRB9+Si/wJ92qBtiHBNUugG3ZB+qLeF1+6EvOkZwjXLUmVFlt53Fr/RvdPI8sXGRDGsw690/LgbbSTkuiL9bZj09TO9Dv/to= 15 | - secure: p6QO5YHrZkQfoqqWwogmsILooHEAJiY3JFPQkkGUYxbKPqOQblEoi5YywSXT0InCTyl63Igs0He3Zq0f/avlM6vS2Qf1U8i78ASPUGFlFSfnAl7Z35e/zndB0tkmWN78C2CfeVjDjzbtUxoRFHjF7JMD9oi7JF69Nqk+Sey7wNP3bWNrF+teX241srjr4VfgFHPRzvw+Z72mVQgQvVae3UyqVokNLZpeynMiEMNRITkAnlrbvOD2yfiPUXIiN14u14nyZDd7knL2u3SB3Pn7khDHrDE4sp3DkWkDV1MRg7yJPD611NZIi1pkYEn+6mp20IQk3djoOfv6nlgKqQsIMn/yApTRu/TmLWim+PAyuEvRhUu94EJeRXCnYaU2Rwr4jJQrAaQdH/HpGI6Jvv+mPpNJAdHDJA+pEe+te0sTXmXOnax08vYlImwaYTEKpxXbMOpEHfA2wyUOPvI7+BghghgJQdttrMCVRImkUDdes/FAUrhBmGA2VuvZZads6XWV+uYAEQ9Mfp1Um1g64MZGWE9c8DjCTOHkd4gsJ9vYu6j58zTKPh7gHgbWfkVgJc0I181PLPtxA8K4fHjsGao/EgLyxxpmjkwvGpqpBC7//ACnG7it25N6cZPItqUpWxr5U/5GpqIdPS9/Enmy74BV0V7TOOUMgB+IVrYiKISg7LY= 16 | - secure: hoqOLR6bdaQRmeAOoMmAZjFEHJR20budXBzyJlpERwDqwZYNWibMrEt1tNzYO8FFaoMOpL1hoOur531PiUtv8XUBHfVvP/3F98slybVMb3h65VsbiHSSGAioL1FNpK8kLepdbKGXhiBb3YCzzcwZOf+XGUJ1RS/YTY86PHrG5UNMpsnnoN8MhM3/5jUN08zFnZ9pv9iB+HFz+baKpPsT3KIRXyy4lEGcT/2clQBlXUSm5zlGmkUjV5BB/Gu6a7Syxglcs68YBmeDzZyMtv4QmGNRwtQxXUpdFZZsF/0AYfuRsNqmY+nQLXkUiJoMHsOyXJ9QaaR2OW8sjF8VXAbzQXq8U+q2hKdzv9yuOuCZTbSkmsVdE07ybpeYIi9vUOb0kMq4p2MAAiMnBvOzTf8haMehWW77q3Enf5Qkgi1wlO2yFDh6cfGDzrEZtMx84jknO56tQtwI3D8qhJGQcmIg0VVhMHByA+8WsgLogI2aQa8eoOAkKPOQFIKvUe8RzmRJmtTa+b4kNVKe/8Aqod9fGI9v4ad3Lm1ST0dydyZtsnS/szfDqIMgjW86flFjfOdfIpTxArpJXP2vLj6XvJW431fGCc+FDTM2MWkxLcJa5uFldv7YrR7TGse2uCjpXcDJGjjBuyvzKsr8pf4LQI9DgMgtVBR8+6oOZAdbNwNgwRE= 17 | - secure: gfaScK695GTgzzrJ0ZLpyuUt+icFw5keAuylA4BNXThJaPBm5tUNbddKAFJSkwJOYVHCxl1A6y7Ad+7mCTpLi2rBC47LeelDtTIQa0qPoyJypCczOdBbYzE03XAQzHpZ3vOlo0sQxlHeNyLD+aXeniSF3nSNbX86thNSydPSu7fl2b8e23+cd4t3FrFkoqw5mg8BCkgt3q40GeVBcA4PzOhm+nwX2w/KgZxCwj/5bAut1y3TffVN0D+F25O/UV6ezNSwBvt2cm2lFqn+rEYoN1WdsWYnhXnrslpbF57Jn6tJTnLEdL/HsPK+UaYguOswdGdM+SJ4ldRYPKIO0xDJB+DRNLr6X3fgzRNxH/StG3aRsPdTxr/rkzM33RrsqdzT+UX5R9uUp12tLxYmmnDkv91/mc0HIYQh9jzUxLMMnGc+wp2OjBbYwM9MWymXUQztvNOueKdTb3vzkxjcb3dt1yLlXB9zRnIx4qhTOSThqzR5UeOGYenehsu6vvcCImWCH3FWrX2RMbTxR1HKvNEJSUysm5Ivx89rHbhZNYMci2Nn51bhxPbiJsJzoMLqJwyz6w+uog/AqfgVG4nls552USgavM+K7VhotNjPTAo57lExOC6PRew8AQ4zzzTP0u4nm3BKBqVetbjNfOzhoMHebxoHDigQw6azkcK6M3v4Gx4= 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /artifactory.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | if (project.hasProperty('bintrayUser') && project.hasProperty('bintrayKey')) { 18 | 19 | plugins.withId('com.jfrog.artifactory') { 20 | artifactory { 21 | publish { 22 | contextUrl = 'https://oss.jfrog.org' 23 | 24 | repository { 25 | repoKey = 'oss-snapshot-local' 26 | 27 | // Credentials for oss.jfrog.org are a user's Bintray credentials 28 | username = project.property('bintrayUser') 29 | password = project.property('bintrayKey') 30 | } 31 | 32 | defaults { 33 | publications('maven') 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /bintray.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | if (project.hasProperty('bintrayUser') && project.hasProperty('bintrayKey') && 18 | project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')) { 19 | 20 | plugins.withId('com.jfrog.bintray') { 21 | bintray { 22 | user = project.property('bintrayUser') 23 | key = project.property('bintrayKey') 24 | 25 | publications = ['maven'] 26 | publish = true 27 | 28 | pkg { 29 | repo = 'RSocket' 30 | name = 'rsocket-transport-akka' 31 | licenses = ['Apache-2.0'] 32 | 33 | issueTrackerUrl = 'https://github.com/rsocket/rsocket-transport-akka/issues' 34 | websiteUrl = 'https://github.com/rsocket/rsocket-transport-akka' 35 | vcsUrl = 'https://github.com/rsocket/rsocket-transport-akka.git' 36 | 37 | githubRepo = 'rsocket/rsocket-transport-akka' //Optional Github repository 38 | githubReleaseNotesFile = 'README.md' //Optional Github readme file 39 | 40 | version { 41 | name = project.version 42 | released = new Date() 43 | vcsTag = project.version 44 | 45 | gpg { 46 | sign = true 47 | } 48 | 49 | mavenCentralSync { 50 | user = project.property('sonatypeUsername') 51 | password = project.property('sonatypePassword') 52 | } 53 | } 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'scala' 3 | id 'maven-publish' 4 | id 'com.jfrog.artifactory' version '4.7.3' 5 | id 'com.jfrog.bintray' version '1.8.4' 6 | id 'com.adtran.scala-multiversion-plugin' version '1.0.35' 7 | } 8 | 9 | group = 'io.rsocket' 10 | description = 'Akka RSocket transport implementations (TCP, Websocket)' 11 | 12 | repositories { 13 | jcenter() 14 | } 15 | 16 | ext { 17 | rsocketVersion = "1.0.0-RC5" 18 | akkaHttpVersion = "10.1.8" 19 | akkaStreamVersion = "2.5.23" 20 | junitVersion = "5.1.0" 21 | } 22 | 23 | configurations { 24 | scalaAnt 25 | } 26 | 27 | dependencies { 28 | zinc "com.typesafe.zinc:zinc:0.3.15" 29 | 30 | compile "org.scala-lang:scala-library:%scala-version%" 31 | compile "io.rsocket:rsocket-core:$rsocketVersion" 32 | compile "com.typesafe.akka:akka-http_%%:$akkaHttpVersion" 33 | compile "com.typesafe.akka:akka-stream_%%:$akkaStreamVersion" 34 | 35 | testCompile "io.rsocket:rsocket-test:$rsocketVersion" 36 | testCompile "io.rsocket:rsocket-transport-netty:$rsocketVersion" 37 | 38 | if (scalaVersion.startsWith("2.11")) { 39 | testCompile "com.typesafe.akka:akka-actor-testkit-typed_%%:2.5.21" 40 | } else { 41 | testCompile "com.typesafe.akka:akka-actor-testkit-typed_%%:$akkaStreamVersion" 42 | } 43 | 44 | testRuntimeOnly 'ch.qos.logback:logback-classic:1.2.3' 45 | testRuntimeOnly "com.typesafe.akka:akka-slf4j_%%:$akkaStreamVersion" 46 | testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion" 47 | 48 | scalaAnt 'com.sandinh:scala-ant_2.13:2.13.1' 49 | } 50 | 51 | scaladoc { 52 | scalaClasspath += scalaVersion.startsWith("2.13") ? configurations.scalaAnt : layout.files() 53 | } 54 | 55 | sourceCompatibility = 1.8 56 | targetCompatibility = 1.8 57 | 58 | task sourcesJar(type: Jar, dependsOn: classes) { 59 | classifier = 'sources' 60 | from sourceSets.main.allSource 61 | } 62 | 63 | task scaladocJar(type: Jar, dependsOn: scaladoc) { 64 | classifier = 'javadoc' 65 | from scaladoc.destinationDir 66 | } 67 | 68 | artifacts { 69 | archives jar 70 | archives sourcesJar 71 | archives scaladocJar 72 | } 73 | 74 | plugins.withType(MavenPublishPlugin) { 75 | publishing { 76 | publications { 77 | maven(MavenPublication) { 78 | groupId project.group 79 | artifactId archivesBaseName 80 | 81 | from components.java 82 | 83 | artifact sourcesJar 84 | artifact scaladocJar 85 | 86 | pom.withXml { 87 | asNode().':version' + { 88 | resolveStrategy = DELEGATE_FIRST 89 | 90 | name project.name 91 | description project.description 92 | url 'http://rsocket.io' 93 | 94 | licenses { 95 | license { 96 | name 'The Apache Software License, Version 2.0' 97 | url 'http://www.apache.org/license/LICENSE-2.0.txt' 98 | } 99 | } 100 | 101 | developers { 102 | developer { 103 | id 'rdegnan' 104 | name 'Ryland Degnan' 105 | email 'ryland@netifi.com' 106 | } 107 | } 108 | 109 | scm { 110 | connection 'scm:git:git@github.com:rsocket/rsocket-transport-akka.git' 111 | developerConnection 'scm:git:git@github.com:rsocket/rsocket-transport-akka.git' 112 | url 'https://github.com/rsocket/rsocket-transport-akka' 113 | } 114 | } 115 | } 116 | } 117 | } 118 | } 119 | } 120 | 121 | apply from: 'artifactory.gradle' 122 | apply from: 'bintray.gradle' 123 | 124 | ScalaCompileOptions.metaClass.daemonServer = true 125 | ScalaCompileOptions.metaClass.fork = true 126 | ScalaCompileOptions.metaClass.useAnt = false 127 | ScalaCompileOptions.metaClass.useCompileDaemon = false 128 | 129 | project.tasks.scaladoc.scalaDocOptions.additionalParameters = ["-no-link-warnings"] 130 | project.tasks.compileScala.scalaCompileOptions.additionalParameters = ["-target:jvm-1.8"] 131 | project.tasks.compileTestScala.scalaCompileOptions.additionalParameters = ["-target:jvm-1.8"] 132 | 133 | test { 134 | useJUnitPlatform() 135 | 136 | maxParallelForks = 1 137 | } 138 | -------------------------------------------------------------------------------- /ci/travis.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then 4 | 5 | echo -e "Building PR #$TRAVIS_PULL_REQUEST [$TRAVIS_PULL_REQUEST_SLUG/$TRAVIS_PULL_REQUEST_BRANCH => $TRAVIS_REPO_SLUG/$TRAVIS_BRANCH]" 6 | ./gradlew build 7 | 8 | elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" == "" ] && [ "$bintrayUser" != "" ] ; then 9 | 10 | echo -e "Building Snapshot $TRAVIS_REPO_SLUG/$TRAVIS_BRANCH" 11 | ./gradlew \ 12 | -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" \ 13 | -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" \ 14 | build artifactoryPublish --stacktrace 15 | 16 | elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" != "" ] && [ "$bintrayUser" != "" ] ; then 17 | 18 | echo -e "Building Tag $TRAVIS_REPO_SLUG/$TRAVIS_TAG" 19 | ./gradlew \ 20 | -Pversion="$TRAVIS_TAG" \ 21 | -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" \ 22 | -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" \ 23 | build bintrayUpload --stacktrace 24 | 25 | else 26 | 27 | echo -e "Building $TRAVIS_REPO_SLUG/$TRAVIS_BRANCH" 28 | ./gradlew build 29 | 30 | fi 31 | 32 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version=0.2.0 2 | scalaVersions=2.11.12, 2.12.10, 2.13.1 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rsocket/rsocket-transport-akka/ea89bb5d3352006ecc0df67723f69871f105cb32/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'rsocket-transport-akka' 2 | -------------------------------------------------------------------------------- /src/main/scala/io/rsocket/transport/akka/TcpDuplexConnection.scala: -------------------------------------------------------------------------------- 1 | package io.rsocket.transport.akka 2 | 3 | import akka.actor.ActorSystem 4 | import akka.stream.Materializer 5 | import akka.util.ByteString 6 | import io.netty.buffer.{ByteBuf, ByteBufAllocator, Unpooled} 7 | import io.rsocket.frame.FrameLengthFlyweight 8 | import io.rsocket.internal.BaseDuplexConnection 9 | import org.reactivestreams.{Publisher, Subscriber} 10 | import reactor.core.publisher.{Flux, Mono} 11 | 12 | import scala.compat.java8.FunctionConverters._ 13 | 14 | class TcpDuplexConnection(val in: Publisher[ByteString], 15 | val out: Subscriber[ByteString], 16 | val encodeLength: Boolean = true, 17 | val allocator: ByteBufAllocator = ByteBufAllocator.DEFAULT)(implicit system: ActorSystem, m: Materializer) 18 | extends BaseDuplexConnection { 19 | 20 | override def doOnClose(): Unit = { 21 | out.onComplete() 22 | } 23 | 24 | override def receive(): Flux[ByteBuf] = { 25 | Flux.from(in).map(asJavaFunction(decode)) 26 | } 27 | 28 | override def send(frame: Publisher[ByteBuf]): Mono[Void] = { 29 | Flux.from(frame) 30 | .concatMap(asJavaFunction(sendOne)) 31 | .then() 32 | } 33 | 34 | override def sendOne(frame: ByteBuf): Mono[Void] = { 35 | Mono.fromRunnable(new Runnable { 36 | override def run(): Unit = { 37 | val encoded = encode(frame) 38 | val buf = ByteString(encoded.nioBuffer()) 39 | encoded.release() 40 | out.onNext(buf) 41 | } 42 | }) 43 | } 44 | 45 | private def encode(frame: ByteBuf): ByteBuf = { 46 | if (encodeLength) { 47 | FrameLengthFlyweight.encode(allocator, frame.readableBytes(), frame) 48 | } else { 49 | frame 50 | } 51 | } 52 | 53 | private def decode(data: ByteString): ByteBuf = { 54 | val frame = Unpooled.wrappedBuffer(data.asByteBuffer) 55 | if (encodeLength) { 56 | FrameLengthFlyweight.frame(frame).retain() 57 | } else { 58 | frame 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /src/main/scala/io/rsocket/transport/akka/WebsocketDuplexConnection.scala: -------------------------------------------------------------------------------- 1 | package io.rsocket.transport.akka 2 | 3 | import akka.actor.ActorSystem 4 | import akka.http.scaladsl.model.ws.{BinaryMessage, Message} 5 | import akka.stream.Materializer 6 | import akka.util.ByteString 7 | import io.netty.buffer.{ByteBuf, Unpooled} 8 | import io.rsocket.internal.BaseDuplexConnection 9 | import org.reactivestreams.{Publisher, Subscriber} 10 | import reactor.core.publisher.{Flux, Mono} 11 | 12 | import scala.compat.java8.FutureConverters._ 13 | import scala.compat.java8.FunctionConverters._ 14 | 15 | class WebsocketDuplexConnection(val in: Publisher[Message], 16 | val out: Subscriber[Message])(implicit system: ActorSystem, m: Materializer) 17 | extends BaseDuplexConnection { 18 | 19 | override def doOnClose(): Unit = { 20 | out.onComplete() 21 | } 22 | 23 | override def receive(): Flux[ByteBuf] = { 24 | Flux.from(in) 25 | .concatMap(asJavaFunction[Message, Mono[ByteString]]({ 26 | case BinaryMessage.Strict(data) => Mono.just(data) 27 | case BinaryMessage.Streamed(stream) => Mono.fromCompletionStage(stream.runReduce(_ ++ _).toJava) 28 | case _ => Mono.error(new IllegalStateException("Expected BinaryMessage")) 29 | })) 30 | .map(asJavaFunction(data => Unpooled.wrappedBuffer(data.asByteBuffer))) 31 | } 32 | 33 | override def send(frame: Publisher[ByteBuf]): Mono[Void] = 34 | Flux.from(frame) 35 | .concatMap(asJavaFunction(sendOne)) 36 | .then() 37 | 38 | override def sendOne(frame: ByteBuf): Mono[Void] = { 39 | Mono.fromRunnable(new Runnable { 40 | override def run(): Unit = { 41 | val buf = ByteString(frame.nioBuffer()) 42 | frame.release() 43 | out.onNext(BinaryMessage(buf)) 44 | } 45 | }) 46 | } 47 | } -------------------------------------------------------------------------------- /src/main/scala/io/rsocket/transport/akka/client/TcpClientTransport.scala: -------------------------------------------------------------------------------- 1 | package io.rsocket.transport.akka.client 2 | 3 | import java.nio.ByteOrder 4 | 5 | import akka.actor.ActorSystem 6 | import akka.stream.Materializer 7 | import akka.stream.scaladsl.{Flow, Framing, Keep, Sink, Source, Tcp} 8 | import akka.util.ByteString 9 | import io.netty.buffer.ByteBufAllocator 10 | import io.rsocket.DuplexConnection 11 | import io.rsocket.fragmentation.FragmentationDuplexConnection 12 | import io.rsocket.frame.FrameLengthFlyweight.{FRAME_LENGTH_MASK, FRAME_LENGTH_SIZE} 13 | import io.rsocket.transport.ClientTransport 14 | import io.rsocket.transport.akka.TcpDuplexConnection 15 | import reactor.core.publisher.{Mono, UnicastProcessor} 16 | 17 | import scala.compat.java8.FutureConverters._ 18 | 19 | class TcpClientTransport(val host: String, val port: Int)(implicit system: ActorSystem, m: Materializer) 20 | extends ClientTransport { 21 | override def connect(mtu: Int): Mono[DuplexConnection] = { 22 | val isError = FragmentationDuplexConnection.checkMtu[DuplexConnection](mtu) 23 | if (isError != null) { 24 | isError 25 | } else { 26 | val processor = UnicastProcessor.create[ByteString] 27 | val (response, connection) = Tcp().outgoingConnection(host, port) 28 | .via(Framing.lengthField(FRAME_LENGTH_SIZE, 0, FRAME_LENGTH_MASK, ByteOrder.BIG_ENDIAN)) 29 | .joinMat( 30 | Flow.fromSinkAndSourceMat(Sink.asPublisher[ByteString](fanout = false), Source.fromPublisher(processor)) 31 | ((in, _) => { 32 | if (mtu > 0) { 33 | new FragmentationDuplexConnection( 34 | new TcpDuplexConnection(in, processor, false), 35 | ByteBufAllocator.DEFAULT, 36 | mtu, 37 | true, 38 | "client") 39 | } else { 40 | new TcpDuplexConnection(in, processor) 41 | } 42 | }))(Keep.both) 43 | .run() 44 | 45 | Mono.fromCompletionStage(response.toJava).thenReturn(connection) 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/scala/io/rsocket/transport/akka/client/WebsocketClientTransport.scala: -------------------------------------------------------------------------------- 1 | package io.rsocket.transport.akka.client 2 | 3 | import akka.actor.ActorSystem 4 | import akka.http.scaladsl.Http 5 | import akka.http.scaladsl.model.ws.{Message, WebSocketRequest} 6 | import akka.stream.Materializer 7 | import akka.stream.scaladsl.{Flow, Sink, Source} 8 | import io.netty.buffer.ByteBufAllocator 9 | import io.rsocket.DuplexConnection 10 | import io.rsocket.fragmentation.FragmentationDuplexConnection 11 | import io.rsocket.transport.ClientTransport 12 | import io.rsocket.transport.akka.WebsocketDuplexConnection 13 | import reactor.core.publisher.{Mono, UnicastProcessor} 14 | 15 | import scala.compat.java8.FutureConverters._ 16 | 17 | class WebsocketClientTransport(val request: WebSocketRequest)(implicit system: ActorSystem, m: Materializer) 18 | extends ClientTransport { 19 | override def connect(mtu: Int): Mono[DuplexConnection] = { 20 | val processor = UnicastProcessor.create[Message] 21 | val (response, connection) = Http().singleWebSocketRequest(request, 22 | Flow.fromSinkAndSourceMat(Sink.asPublisher[Message](fanout = false), Source.fromPublisher(processor)) 23 | ((in, _) => { 24 | if (mtu > 0) { 25 | new FragmentationDuplexConnection( 26 | new WebsocketDuplexConnection(in, processor), 27 | ByteBufAllocator.DEFAULT, 28 | mtu, 29 | false, 30 | "client") 31 | } else { 32 | new WebsocketDuplexConnection(in, processor) 33 | } 34 | })) 35 | 36 | Mono.fromCompletionStage(response.toJava).thenReturn(connection) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/scala/io/rsocket/transport/akka/server/HttpServerBindingCloseable.scala: -------------------------------------------------------------------------------- 1 | package io.rsocket.transport.akka.server 2 | 3 | import java.net.InetSocketAddress 4 | 5 | import akka.actor.ActorSystem 6 | import akka.http.scaladsl.Http 7 | import akka.stream.Materializer 8 | import akka.stream.scaladsl.{Sink, Source} 9 | import io.rsocket.Closeable 10 | import reactor.core.publisher.Mono 11 | 12 | import scala.concurrent.duration._ 13 | 14 | final case class HttpServerBindingCloseable(binding: Http.ServerBinding)(implicit system: ActorSystem, m: Materializer) 15 | extends Closeable { 16 | 17 | override def onClose(): Mono[Void] = { 18 | val publisher = Source.fromFuture(binding.whenTerminated).runWith(Sink.asPublisher(fanout = false)) 19 | Mono.fromDirect(publisher).then() 20 | } 21 | 22 | override def dispose(): Unit = binding.terminate(hardDeadline = 3.seconds) 23 | 24 | /** 25 | * @see NettyContext#address() 26 | * @return socket address. 27 | */ 28 | def address: InetSocketAddress = binding.localAddress 29 | } 30 | -------------------------------------------------------------------------------- /src/main/scala/io/rsocket/transport/akka/server/TcpServerBindingCloseable.scala: -------------------------------------------------------------------------------- 1 | package io.rsocket.transport.akka.server 2 | 3 | import java.net.InetSocketAddress 4 | 5 | import akka.actor.ActorSystem 6 | import akka.stream.Materializer 7 | import akka.stream.scaladsl.{Sink, Source, Tcp} 8 | import io.rsocket.Closeable 9 | import reactor.core.publisher.Mono 10 | 11 | final case class TcpServerBindingCloseable(binding: Tcp.ServerBinding)(implicit system: ActorSystem, m: Materializer) 12 | extends Closeable { 13 | 14 | override def onClose(): Mono[Void] = { 15 | val publisher = Source.fromFuture(binding.whenUnbound).runWith(Sink.asPublisher(fanout = false)) 16 | Mono.fromDirect(publisher).then() 17 | } 18 | 19 | override def dispose(): Unit = binding.unbind() 20 | 21 | /** 22 | * @see NettyContext#address() 23 | * @return socket address. 24 | */ 25 | def address: InetSocketAddress = binding.localAddress 26 | } 27 | -------------------------------------------------------------------------------- /src/main/scala/io/rsocket/transport/akka/server/TcpServerTransport.scala: -------------------------------------------------------------------------------- 1 | package io.rsocket.transport.akka.server 2 | 3 | import java.nio.ByteOrder 4 | 5 | import akka.actor.ActorSystem 6 | import akka.stream.Materializer 7 | import akka.stream.scaladsl.{Flow, Framing, Sink, Source, Tcp} 8 | import akka.util.ByteString 9 | import io.netty.buffer.ByteBufAllocator 10 | import io.rsocket.fragmentation.FragmentationDuplexConnection 11 | import io.rsocket.frame.FrameLengthFlyweight.{FRAME_LENGTH_MASK, FRAME_LENGTH_SIZE} 12 | import io.rsocket.transport.ServerTransport 13 | import io.rsocket.transport.ServerTransport.ConnectionAcceptor 14 | import io.rsocket.transport.akka.TcpDuplexConnection 15 | import reactor.core.publisher.{Mono, UnicastProcessor} 16 | 17 | import scala.compat.java8.FutureConverters._ 18 | import scala.compat.java8.FunctionConverters._ 19 | 20 | class TcpServerTransport(val interface: String, val port: Int)(implicit system: ActorSystem, m: Materializer) 21 | extends ServerTransport[TcpServerBindingCloseable] { 22 | override def start(acceptor: ConnectionAcceptor, mtu: Int): Mono[TcpServerBindingCloseable] = { 23 | val isError = FragmentationDuplexConnection.checkMtu[TcpServerBindingCloseable](mtu) 24 | if (isError != null) { 25 | isError 26 | } else { 27 | val binding = Tcp().bind(interface, port) 28 | .to(Sink.foreach(conn => { 29 | val processor = UnicastProcessor.create[ByteString] 30 | conn.flow 31 | .via(Framing.lengthField(FRAME_LENGTH_SIZE, 0, FRAME_LENGTH_MASK, ByteOrder.BIG_ENDIAN)) 32 | .join( 33 | Flow.fromSinkAndSourceMat(Sink.asPublisher[ByteString](fanout = false), Source.fromPublisher(processor)) 34 | ((in, _) => { 35 | val connection = 36 | if (mtu > 0) { 37 | new FragmentationDuplexConnection( 38 | new TcpDuplexConnection(in, processor, false), 39 | ByteBufAllocator.DEFAULT, 40 | mtu, 41 | true, 42 | "server") 43 | } else { 44 | new TcpDuplexConnection(in, processor) 45 | } 46 | acceptor.apply(connection).subscribe() 47 | })) 48 | .run() 49 | })) 50 | .run() 51 | 52 | Mono.fromCompletionStage(binding.toJava).map(asJavaFunction(TcpServerBindingCloseable(_))) 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/scala/io/rsocket/transport/akka/server/WebsocketServerTransport.scala: -------------------------------------------------------------------------------- 1 | package io.rsocket.transport.akka.server 2 | 3 | import akka.actor.ActorSystem 4 | import akka.http.scaladsl.Http 5 | import akka.http.scaladsl.model.ws.Message 6 | import akka.http.scaladsl.server.Directives._ 7 | import akka.stream.Materializer 8 | import akka.stream.scaladsl.{Flow, Sink, Source} 9 | import io.netty.buffer.ByteBufAllocator 10 | import io.rsocket.fragmentation.FragmentationDuplexConnection 11 | import io.rsocket.transport.ServerTransport 12 | import io.rsocket.transport.ServerTransport.ConnectionAcceptor 13 | import io.rsocket.transport.akka.WebsocketDuplexConnection 14 | import reactor.core.publisher.{Mono, UnicastProcessor} 15 | 16 | import scala.compat.java8.FutureConverters._ 17 | import scala.compat.java8.FunctionConverters._ 18 | 19 | class WebsocketServerTransport(val interface: String, val port: Int)(implicit system: ActorSystem, m: Materializer) 20 | extends ServerTransport[HttpServerBindingCloseable] { 21 | override def start(acceptor: ConnectionAcceptor, mtu: Int): Mono[HttpServerBindingCloseable] = { 22 | val isError = FragmentationDuplexConnection.checkMtu[HttpServerBindingCloseable](mtu) 23 | if (isError != null) { 24 | isError 25 | } else { 26 | val binding = Http().bind(interface, port) 27 | .to(Sink.foreach(conn => { 28 | val processor = UnicastProcessor.create[Message] 29 | conn.handleWith( 30 | handleWebSocketMessages( 31 | Flow.fromSinkAndSourceMat(Sink.asPublisher[Message](fanout = false), Source.fromPublisher(processor)) 32 | ((in, _) => { 33 | val connection = 34 | if (mtu > 0) { 35 | new FragmentationDuplexConnection( 36 | new WebsocketDuplexConnection(in, processor), 37 | ByteBufAllocator.DEFAULT, 38 | mtu, 39 | false, 40 | "server") 41 | } else { 42 | new WebsocketDuplexConnection(in, processor) 43 | } 44 | acceptor.apply(connection).subscribe() 45 | }))) 46 | })) 47 | .run() 48 | 49 | Mono.fromCompletionStage(binding.toJava).map(asJavaFunction(HttpServerBindingCloseable(_))) 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/io/rsocket/transport/akka/NettyTcpPing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.rsocket.transport.akka; 18 | 19 | import io.rsocket.RSocket; 20 | import io.rsocket.RSocketFactory; 21 | import io.rsocket.frame.decoder.PayloadDecoder; 22 | import io.rsocket.test.PerfTest; 23 | import io.rsocket.test.PingClient; 24 | import io.rsocket.transport.netty.client.TcpClientTransport; 25 | import org.HdrHistogram.Recorder; 26 | import org.junit.jupiter.api.BeforeEach; 27 | import org.junit.jupiter.api.Test; 28 | import reactor.core.publisher.Mono; 29 | 30 | import java.time.Duration; 31 | 32 | @PerfTest 33 | public final class NettyTcpPing { 34 | private static final int INTERACTIONS_COUNT = 1_000_000_000; 35 | private static final int port = Integer.valueOf(System.getProperty("RSOCKET_TEST_PORT", "7878")); 36 | 37 | @BeforeEach 38 | void setUp() { 39 | System.out.println("Starting ping-pong test (TCP transport)"); 40 | System.out.println("port: " + port); 41 | } 42 | 43 | @Test 44 | void requestResponseTest() { 45 | PingClient pingClient = newPingClient(); 46 | Recorder recorder = pingClient.startTracker(Duration.ofSeconds(1)); 47 | 48 | pingClient 49 | .requestResponsePingPong(INTERACTIONS_COUNT, recorder) 50 | .doOnTerminate(() -> System.out.println("Sent " + INTERACTIONS_COUNT + " messages.")) 51 | .blockLast(); 52 | } 53 | 54 | @Test 55 | void requestStreamTest() { 56 | PingClient pingClient = newPingClient(); 57 | Recorder recorder = pingClient.startTracker(Duration.ofSeconds(1)); 58 | 59 | pingClient 60 | .requestStreamPingPong(INTERACTIONS_COUNT, recorder) 61 | .doOnTerminate(() -> System.out.println("Sent " + INTERACTIONS_COUNT + " messages.")) 62 | .blockLast(); 63 | } 64 | 65 | @Test 66 | void requestStreamResumableTest() { 67 | PingClient pingClient = newResumablePingClient(); 68 | Recorder recorder = pingClient.startTracker(Duration.ofSeconds(1)); 69 | 70 | pingClient 71 | .requestStreamPingPong(INTERACTIONS_COUNT, recorder) 72 | .doOnTerminate(() -> System.out.println("Sent " + INTERACTIONS_COUNT + " messages.")) 73 | .blockLast(); 74 | } 75 | 76 | private static PingClient newPingClient() { 77 | return newPingClient(false); 78 | } 79 | 80 | private static PingClient newResumablePingClient() { 81 | return newPingClient(true); 82 | } 83 | 84 | private static PingClient newPingClient(boolean isResumable) { 85 | RSocketFactory.ClientRSocketFactory clientRSocketFactory = RSocketFactory.connect(); 86 | if (isResumable) { 87 | clientRSocketFactory.resume(); 88 | } 89 | Mono rSocket = 90 | clientRSocketFactory 91 | .frameDecoder(PayloadDecoder.ZERO_COPY) 92 | .keepAlive(Duration.ofMinutes(1), Duration.ofMinutes(30), 3) 93 | .transport(TcpClientTransport.create(port)) 94 | .start(); 95 | 96 | return new PingClient(rSocket); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/test/java/io/rsocket/transport/akka/NettyTcpPongServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.rsocket.transport.akka; 18 | 19 | import io.rsocket.RSocketFactory; 20 | import io.rsocket.frame.decoder.PayloadDecoder; 21 | import io.rsocket.test.PingHandler; 22 | import io.rsocket.transport.netty.server.TcpServerTransport; 23 | 24 | public final class NettyTcpPongServer { 25 | private static final boolean isResume = 26 | Boolean.valueOf(System.getProperty("RSOCKET_TEST_RESUME", "false")); 27 | private static final int port = Integer.valueOf(System.getProperty("RSOCKET_TEST_PORT", "7878")); 28 | 29 | public static void main(String... args) { 30 | System.out.println("Starting TCP ping-pong server"); 31 | System.out.println("port: " + port); 32 | System.out.println("resume enabled: " + isResume); 33 | 34 | RSocketFactory.ServerRSocketFactory serverRSocketFactory = RSocketFactory.receive(); 35 | if (isResume) { 36 | serverRSocketFactory.resume(); 37 | } 38 | serverRSocketFactory 39 | .frameDecoder(PayloadDecoder.ZERO_COPY) 40 | .acceptor(new PingHandler()) 41 | .transport(TcpServerTransport.create("0.0.0.0", port)) 42 | .start() 43 | .block() 44 | .onClose() 45 | .block(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/io/rsocket/transport/akka/TcpPing.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.rsocket.transport.akka; 18 | 19 | import akka.actor.ActorSystem; 20 | import akka.actor.testkit.typed.javadsl.TestKitJunitResource; 21 | import akka.actor.typed.internal.adapter.ActorSystemAdapter; 22 | import akka.stream.ActorMaterializer; 23 | import akka.stream.Materializer; 24 | import io.rsocket.RSocket; 25 | import io.rsocket.RSocketFactory; 26 | import io.rsocket.frame.decoder.PayloadDecoder; 27 | import io.rsocket.test.PerfTest; 28 | import io.rsocket.test.PingClient; 29 | import io.rsocket.transport.akka.client.TcpClientTransport; 30 | import org.HdrHistogram.Recorder; 31 | import org.junit.ClassRule; 32 | import org.junit.jupiter.api.BeforeEach; 33 | import org.junit.jupiter.api.Test; 34 | import reactor.core.publisher.Mono; 35 | 36 | import java.time.Duration; 37 | 38 | @PerfTest 39 | public final class TcpPing { 40 | private static final int INTERACTIONS_COUNT = 1_000_000_000; 41 | private static final int port = Integer.valueOf(System.getProperty("RSOCKET_TEST_PORT", "7878")); 42 | 43 | @ClassRule 44 | public static final TestKitJunitResource testKit = new TestKitJunitResource(); 45 | 46 | private static final ActorSystem system = ActorSystemAdapter.toUntyped(testKit.system()); 47 | private static final Materializer materializer = ActorMaterializer.create(system); 48 | 49 | @BeforeEach 50 | void setUp() { 51 | System.out.println("Starting ping-pong test (TCP transport)"); 52 | System.out.println("port: " + port); 53 | } 54 | 55 | @Test 56 | void requestResponseTest() { 57 | PingClient pingClient = newPingClient(); 58 | Recorder recorder = pingClient.startTracker(Duration.ofSeconds(1)); 59 | 60 | pingClient 61 | .requestResponsePingPong(INTERACTIONS_COUNT, recorder) 62 | .doOnTerminate(() -> System.out.println("Sent " + INTERACTIONS_COUNT + " messages.")) 63 | .blockLast(); 64 | } 65 | 66 | @Test 67 | void requestStreamTest() { 68 | PingClient pingClient = newPingClient(); 69 | Recorder recorder = pingClient.startTracker(Duration.ofSeconds(1)); 70 | 71 | pingClient 72 | .requestStreamPingPong(INTERACTIONS_COUNT, recorder) 73 | .doOnTerminate(() -> System.out.println("Sent " + INTERACTIONS_COUNT + " messages.")) 74 | .blockLast(); 75 | } 76 | 77 | @Test 78 | void requestStreamResumableTest() { 79 | PingClient pingClient = newResumablePingClient(); 80 | Recorder recorder = pingClient.startTracker(Duration.ofSeconds(1)); 81 | 82 | pingClient 83 | .requestStreamPingPong(INTERACTIONS_COUNT, recorder) 84 | .doOnTerminate(() -> System.out.println("Sent " + INTERACTIONS_COUNT + " messages.")) 85 | .blockLast(); 86 | } 87 | 88 | private static PingClient newPingClient() { 89 | return newPingClient(false); 90 | } 91 | 92 | private static PingClient newResumablePingClient() { 93 | return newPingClient(true); 94 | } 95 | 96 | private static PingClient newPingClient(boolean isResumable) { 97 | RSocketFactory.ClientRSocketFactory clientRSocketFactory = RSocketFactory.connect(); 98 | if (isResumable) { 99 | clientRSocketFactory.resume(); 100 | } 101 | Mono rSocket = 102 | clientRSocketFactory 103 | .frameDecoder(PayloadDecoder.ZERO_COPY) 104 | .keepAlive(Duration.ofMinutes(1), Duration.ofMinutes(30), 3) 105 | .transport(new TcpClientTransport("localhost", port, system, materializer)) 106 | .start(); 107 | 108 | return new PingClient(rSocket); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/test/java/io/rsocket/transport/akka/TcpPongServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package io.rsocket.transport.akka; 18 | 19 | import akka.actor.ActorSystem; 20 | import akka.stream.ActorMaterializer; 21 | import akka.stream.Materializer; 22 | import io.rsocket.RSocketFactory; 23 | import io.rsocket.frame.decoder.PayloadDecoder; 24 | import io.rsocket.test.PingHandler; 25 | import io.rsocket.transport.akka.server.TcpServerTransport; 26 | 27 | public final class TcpPongServer { 28 | private static final boolean isResume = 29 | Boolean.valueOf(System.getProperty("RSOCKET_TEST_RESUME", "false")); 30 | private static final int port = Integer.valueOf(System.getProperty("RSOCKET_TEST_PORT", "7878")); 31 | 32 | private static final ActorSystem system = ActorSystem.create(); 33 | private static final Materializer materializer = ActorMaterializer.create(system); 34 | 35 | public static void main(String... args) { 36 | System.out.println("Starting TCP ping-pong server"); 37 | System.out.println("port: " + port); 38 | System.out.println("resume enabled: " + isResume); 39 | 40 | RSocketFactory.ServerRSocketFactory serverRSocketFactory = RSocketFactory.receive(); 41 | if (isResume) { 42 | serverRSocketFactory.resume(); 43 | } 44 | serverRSocketFactory 45 | .frameDecoder(PayloadDecoder.ZERO_COPY) 46 | .acceptor(new PingHandler()) 47 | .transport(new TcpServerTransport("0.0.0.0", port, system, materializer)) 48 | .start() 49 | .block() 50 | .onClose() 51 | .block(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/io/rsocket/transport/akka/TcpTransportTest.java: -------------------------------------------------------------------------------- 1 | package io.rsocket.transport.akka; 2 | 3 | import akka.actor.ActorSystem; 4 | import akka.actor.testkit.typed.javadsl.TestKitJunitResource; 5 | import akka.actor.typed.internal.adapter.ActorSystemAdapter; 6 | import akka.stream.ActorMaterializer; 7 | import akka.stream.Materializer; 8 | import io.rsocket.test.TransportTest; 9 | import io.rsocket.transport.akka.client.TcpClientTransport; 10 | import io.rsocket.transport.akka.server.TcpServerTransport; 11 | import org.junit.ClassRule; 12 | 13 | import java.net.InetSocketAddress; 14 | import java.time.Duration; 15 | 16 | final class TcpTransportTest implements TransportTest { 17 | @ClassRule 18 | public static final TestKitJunitResource testKit = new TestKitJunitResource(); 19 | 20 | private final ActorSystem system = ActorSystemAdapter.toUntyped(testKit.system()); 21 | private final Materializer materializer = ActorMaterializer.create(system); 22 | private final TransportPair transportPair = 23 | new TransportPair<>( 24 | () -> InetSocketAddress.createUnresolved("localhost", 0), 25 | (address, server) -> new TcpClientTransport(server.address().getHostName(), server.address().getPort(), system, materializer), 26 | address -> new TcpServerTransport(address.getHostName(), address.getPort(), system, materializer)); 27 | 28 | @Override 29 | public Duration getTimeout() { 30 | return Duration.ofMinutes(2); 31 | } 32 | 33 | @Override 34 | public TransportPair getTransportPair() { 35 | return transportPair; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/io/rsocket/transport/akka/WebsocketTransportTest.java: -------------------------------------------------------------------------------- 1 | package io.rsocket.transport.akka; 2 | 3 | import akka.actor.ActorSystem; 4 | import akka.actor.testkit.typed.javadsl.TestKitJunitResource; 5 | import akka.actor.typed.internal.adapter.ActorSystemAdapter; 6 | import akka.http.scaladsl.model.ws.WebSocketRequest; 7 | import akka.stream.ActorMaterializer; 8 | import akka.stream.Materializer; 9 | import io.rsocket.test.TransportTest; 10 | import io.rsocket.transport.akka.client.WebsocketClientTransport; 11 | import io.rsocket.transport.akka.server.WebsocketServerTransport; 12 | import org.junit.ClassRule; 13 | 14 | import java.net.InetSocketAddress; 15 | import java.time.Duration; 16 | 17 | final class WebsocketTransportTest implements TransportTest { 18 | @ClassRule 19 | public static final TestKitJunitResource testKit = new TestKitJunitResource(); 20 | 21 | private final ActorSystem system = ActorSystemAdapter.toUntyped(testKit.system()); 22 | private final Materializer materializer = ActorMaterializer.create(system); 23 | private final TransportPair transportPair = 24 | new TransportPair<>( 25 | () -> InetSocketAddress.createUnresolved("localhost", 0), 26 | (address, server) -> new WebsocketClientTransport(WebSocketRequest.fromTargetUriString("ws://" + server.address().getHostName() + ":" + server.address().getPort()), system, materializer), 27 | address -> new WebsocketServerTransport(address.getHostName(), address.getPort(), system, materializer)); 28 | 29 | @Override 30 | public Duration getTimeout() { 31 | return Duration.ofMinutes(3); 32 | } 33 | 34 | @Override 35 | public TransportPair getTransportPair() { 36 | return transportPair; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | %date{HH:mm:ss.SSS} %-10thread %-42logger %msg%n 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | --------------------------------------------------------------------------------