diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c5fb601..4d3794a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,151 +1 @@ -# Changelog -All notable changes to this project will be documented in this file. - -## [Unreleased] - -### Changed -- rebranding [EventStoreDB-Client-Java#294](https://github.com/kurrent-io/EventStoreDB-Client-Java/pull/294) - -## [5.4.5] - 2025-03-24 - -### Fixed -- Fix subscription error handling during server shutdown [EventStoreDB-Client-Java#311](https://github.com/EventStore/EventStoreDB-Client-Java/pull/311) - -## [5.4.4] - 2025-03-05 -### Changed -- Upgrade dependencies to latest [EventStoreDB-Client-Java#304](https://github.com/EventStore/EventStoreDB-Client-Java/pull/304) - -### Fixed -- Support back-pressure on reads and subscriptions. [EventStoreDB-Client-Java#292](https://github.com/EventStore/EventStoreDB-Client-Java/pull/295) -- Unwrap CompletionException in GrpcClient. [EventStoreDB-Client-Java#298](https://github.com/EventStore/EventStoreDB-Client-Java/pull/298) - -## [5.4.3] - 2024-11-07 -### Fixed -- Disable trace context extraction for deleted events. [EventStoreDB-Client-Java#292](https://github.com/EventStore/EventStoreDB-Client-Java/pull/292) - -## [5.4.2] - 2024-10-16 -### Added -- Support custom headers. [EventStoreDB-Client-Java#289](https://github.com/EventStore/EventStoreDB-Client-Java/pull/289) - -### Changed -- Extract tracing metadata from Event. [EventStoreDB-Client-Java#284](https://github.com/EventStore/EventStoreDB-Client-Java/pull/284) - -## [5.4.1] - 2024-07-16 -### Changed -- Add user certificates and otel samples. [EventStoreDB-Client-Java#274](https://github.com/EventStore/EventStoreDB-Client-Java/pull/274) -- Support different runtime environments out-of-the-box. [EventStoreDB-Client-Java#279](https://github.com/EventStore/EventStoreDB-Client-Java/pull/279) -- Remove expectation oriented tests. [EventStoreDB-Client-Java#279](https://github.com/EventStore/EventStoreDB-Client-Java/pull/279) -- Fixed bug in the ClientTelemetry whereby injection logic forces all events to have JSON content type. [EventStoreDB-Client-Java#281](https://github.com/EventStore/EventStoreDB-Client-Java/pull/281) - -### Fixed -- Use connection string in user certificate sample. [EventStoreDB-Client-Java#276](https://github.com/EventStore/EventStoreDB-Client-Java/pull/276) -- Fix connection service skipping discovery interval sleeps. [EventStoreDB-Client-Java#278](https://github.com/EventStore/EventStoreDB-Client-Java/pull/278) - -## [5.4.0] - 2024-05-23 -### Added -- new connection settings to provide an x.509 certificate for user authentication. [EventStoreDB-Client-Java#266](https://github.com/EventStore/EventStoreDB-Client-Java/pull/266) - -### Changed -- Updated CI workflows and tests to pull eventstore docker images from cloud smith registry. [EventStoreDB-Client-Java#263](https://github.com/EventStore/EventStoreDB-Client-Java/pull/263) -- Added tracing instrumentation of Append and Subscribe (Catchup and Persistent) operations using the Open Telemetry APIs. [EventStoreDB-Client-Java#270](https://github.com/EventStore/EventStoreDB-Client-Java/pull/270) -- Updated everywhere to pull es-gencert-cli from Cloudsmith [EventStoreDB-Client-Java#271](https://github.com/EventStore/EventStoreDB-Client-Java/pull/271) - -## [5.3.2] - 2024-03-05 -### Changed -- Updated protobuf & protoc to 3.25.3 [EventStoreDB-Client-Java#268](https://github.com/EventStore/EventStoreDB-Client-Java/pull/268) - -### Fixed -- https://github.com/EventStore/EventStoreDB-Client-Java/issues/267 [EventStoreDB-Client-Java#268](https://github.com/EventStore/EventStoreDB-Client-Java/pull/268) - -## [5.3.1] - 2024-02-29 -### Changed -- Updated gRPC client and Protoc to latest, which come with arm64 binaries, enabling compile on arm64 [EventStoreDB-Client-Java#265](https://github.com/EventStore/EventStoreDB-Client-Java/pull/265) - -### Fixed -- parsing of server semver for CI, where the server version may have tagging [EventStoreDB-Client-Java#264](https://github.com/EventStore/EventStoreDB-Client-Java/pull/264) - -## [5.3.0] - 2024-01-31 -### Added -- Expose building a JSON payload event with raw bytes [EventStoreDB-Client-Java#258](https://github.com/EventStore/EventStoreDB-Client-Java/pull/258) - -### Fixed -- Fix cluster discovery process. [EventStoreDB-Client-Java#261](https://github.com/EventStore/EventStoreDB-Client-Java/pull/261) - -## [5.2.0] - 2023-11-10 -### Added -- Support new subscription messages. [EventStoreDB-Client-Java#254](https://github.com/EventStore/EventStoreDB-Client-Java/pull/254) - -## [5.1.1] - 2023-11-03 -### Fixed -- Fix IllegalStateException when stopping a subscription. [EventStoreDB-Client-Java#250](https://github.com/EventStore/EventStoreDB-Client-Java/pull/250) - -## [5.1.0] - 2023-10-31 -### Added -- Support certificate file input in connection string and builder. [EventStoreDB-Client-Java#247](https://github.com/EventStore/EventStoreDB-Client-Java/pull/247) - -### Changed -- Improve error reporting in SubscriptionListener. [EventStoreDB-Client-Java#245](https://github.com/EventStore/EventStoreDB-Client-Java/pull/245) -- Update dependencies. [EventStoreDB-Client-Java#246](https://github.com/EventStore/EventStoreDB-Client-Java/pull/246) - -## [5.0.0] - 2023-10-23 -### Changed -- Improve internal gRPC connection management for better error propagation. [EventStoreDB-Client-Java#226](https://github.com/EventStore/EventStoreDB-Client-Java/pull/226) -- Add secure and cluster tests. [EventStoreDB-Client-Java#236](https://github.com/EventStore/EventStoreDB-Client-Java/pull/236) -- Improve connection string parsing. [EventStoreDB-Client-Java#243](https://github.com/EventStore/EventStoreDB-Client-Java/pull/243) - -### Added -- Support authenticated gossip read request. [EventStoreDB-Client-Java#235](https://github.com/EventStore/EventStoreDB-Client-Java/pull/235) - -### Fixed -- Improve stream metadata serialization. [EventStoreDB-Client-Java#242](https://github.com/EventStore/EventStoreDB-Client-Java/pull/242) - -## [4.3.0] - 2023-07-03 -### Added -- Support user-provided gRPC client interceptors. [EventStoreDB-Client-Java#233](https://github.com/EventStore/EventStoreDB-Client-Java/pull/233) - -## [4.2.0] - 2023-04-27 - -### Fixed -- Do not start discovery process on ABORT gRPC error. [EventStoreDB-Client-Java#219](https://github.com/EventStore/EventStoreDB-Client-Java/pull/219) -- Fix OptionBase authentication code. [EventStoreDB-Client-Java#221](https://github.com/EventStore/EventStoreDB-Client-Java/pull/221) - -### Added -- Provide toString override for public types. [EventStoreDB-Client-Java#218](https://github.com/EventStore/EventStoreDB-Client-Java/pull/218) -- Implement `ExpectedRevision` raw long representation. [EventStoreDB-Client-Java#230](https://github.com/EventStore/EventStoreDB-Client-Java/pull/230) - -### Changed -- Increase max inbound message length. [EventStoreDB-Client-Java#222](https://github.com/EventStore/EventStoreDB-Client-Java/pull/222) - -## [4.1.1] - 2023-03-06 - -### Changed -- Stop using Jackson JsonMapper static instances. [EventStoreDB-Client-Java#217](https://github.com/EventStore/EventStoreDB-Client-Java/pull/217) - -## [4.1.0] - 2023-02-24 - -### Added -- Add specific exceptions when delete stream operation fails. [EventStoreDB-Client-Java#208](https://github.com/EventStore/EventStoreDB-Client-Java/pull/208) -- Implement human-representation for `ExpectedVersion` types. [EventStoreDB-Client-Java#204](https://github.com/EventStore/EventStoreDB-Client-Java/pull/204) - -### Fixed -- Fix server filtering sample code. [EventStoreDB-Client-Java#206](https://github.com/EventStore/EventStoreDB-Client-Java/pull/206) -- Fix `ConnectionSettingsBuilder` when dealing with keep-alive settings. [EventStoreDB-Client-Java#207](https://github.com/EventStore/EventStoreDB-Client-Java/pull/207) -- Fix `tombstoneStream` overload. [EventStoreDB-Client-Java#205](https://github.com/EventStore/EventStoreDB-Client-Java/pull/205) -- No longer store credentials unprotected in memory. [EventStoreDB-Client-Java#214](https://github.com/EventStore/EventStoreDB-Client-Java/pull/214) - -### Changed -- Update gRPC and protobuf version. [EventStoreDB-Client-Java#213](https://github.com/EventStore/EventStoreDB-Client-Java/pull/213) - -## [4.0.0] - 2022-11-01 - -### Fixed -- Fix next expected version when appending to a stream. [EventStoreDB-Client-Java#196](https://github.com/EventStore/EventStoreDB-Client-Java/pull/196) -- Fix condition causing subscribers not to be completed. [EventStoreDB-Client-Java#193](https://github.com/EventStore/EventStoreDB-Client-Java/pull/193) -- Shutdown `GossipClient` after usage. [EventStoreDB-Client-Java#186](https://github.com/EventStore/EventStoreDB-Client-Java/pull/186) -- Fix channel lifecycle behaviour. [EventStoreDB-Client-Java#184](https://github.com/EventStore/EventStoreDB-Client-Java/pull/184) -- Do not shutdown client on leader reconnect attempt. [EventStoreDB-Client-Java#182](https://github.com/EventStore/EventStoreDB-Client-Java/pull/182) -- Fix error signals to the `GrpcClient` based on a `CompletableFuture`. [EventStoreDB-Client-Java#182](https://github.com/EventStore/EventStoreDB-Client-Java/pull/182) - -### Changed -- Fix next expected version when appending to a stream. [EventStoreDB-Client-Java#196](https://github.com/EventStore/EventStoreDB-Client-Java/pull/196) -- Add additional logging for connection handling. [EventStoreDB-Client-Java#181](https://github.com/EventStore/EventStoreDB-Client-Java/pull/181) +This changelog is no longer maintained. The information has been moved to the [GitHub release notes](https://github.com/kurrent-io/KurrentDB-Client-Java/releases) page. diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..0fdf6854 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2011-2025 Kurrent, Inc + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index aac3fc04..00000000 --- a/LICENSE.md +++ /dev/null @@ -1,57 +0,0 @@ -# Kurrent License v1 - -Copyright (c) 2011-2025, Kurrent, Inc. All rights reserved. - -### Acceptance - -By using the software, you agree to all of the terms and conditions below. - -### Copyright License - -The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below. - -### Limitations - -You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software. - -Unless authorized in writing by the licensor, you may not move, change, disable, interfere with, or circumvent the license mechanisms in the software, and you may not remove or obscure any functionality in the software that is protected by the license mechanisms. - -You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law. - -### Patents - -The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company. - -### Notices - -You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms. - -If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software. - -### No Other Rights - -These terms do not imply any licenses other than those expressly granted in these terms. - -### Termination - -If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently. - -### No Liability - -***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.*** - -### Definitions - -The **licensor** is the entity offering these terms, and the **software** is the software the licensor makes available under these terms, including any portion of it. - -**licensing mechanisms** refers to functionality that restricts use of the software based on whether you possess a valid license key, including functionality to validate license keys and audit usage of the software to ensure license compliance. - -**you** refers to the individual or entity agreeing to these terms. - -**your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect. - -**your licenses** are all the licenses granted to you for the software under these terms. - -**use** means anything you do with the software requiring one of your licenses. - -**trademark** means trademarks, service marks, and similar rights. \ No newline at end of file diff --git a/build.gradle b/build.gradle index b06e3ba9..6c2124a8 100644 --- a/build.gradle +++ b/build.gradle @@ -25,7 +25,7 @@ tasks.withType(JavaCompile) { } group = 'io.kurrent' -version = '1.0.1' +version = '1.0.2' java { withSourcesJar() diff --git a/src/main/java/io/kurrent/dbclient/ClientTelemetryTags.java b/src/main/java/io/kurrent/dbclient/ClientTelemetryTags.java index 4c94f0dc..49efc5a1 100644 --- a/src/main/java/io/kurrent/dbclient/ClientTelemetryTags.java +++ b/src/main/java/io/kurrent/dbclient/ClientTelemetryTags.java @@ -36,9 +36,9 @@ Builder withServerTagsFromGrpcChannel(ManagedChannel channel) { Builder withServerTagsFromClientSettings(KurrentDBClientSettings settings) { if (settings == null || !settings.isDnsDiscover()) return this; - InetSocketAddress dns = settings.getHosts()[0]; + Endpoint dns = settings.getHosts()[0]; - return withServerTags(dns.getAddress().toString(), String.valueOf(dns.getPort())); + return withServerTags(dns.getHost(), String.valueOf(dns.getPort())); } private Builder withServerTags(String address, String port) { diff --git a/src/main/java/io/kurrent/dbclient/ConnectionSettingsBuilder.java b/src/main/java/io/kurrent/dbclient/ConnectionSettingsBuilder.java index df4cfe4e..f71efcea 100644 --- a/src/main/java/io/kurrent/dbclient/ConnectionSettingsBuilder.java +++ b/src/main/java/io/kurrent/dbclient/ConnectionSettingsBuilder.java @@ -29,7 +29,7 @@ public class ConnectionSettingsBuilder { private boolean _tlsVerifyCert = true; private UserCredentials _defaultCredentials; private ClientCertificate _defaultClientCertificate; - private LinkedList _hosts = new LinkedList<>(); + private LinkedList _hosts = new LinkedList<>(); private long _keepAliveTimeout = Consts.DEFAULT_KEEP_ALIVE_TIMEOUT_IN_MS; private long _keepAliveInterval = Consts.DEFAULT_KEEP_ALIVE_INTERVAL_IN_MS; private Long _defaultDeadline = null; @@ -54,7 +54,7 @@ public KurrentDBClientSettings buildConnectionSettings() { _tlsVerifyCert, _defaultCredentials, _defaultClientCertificate, - _hosts.toArray(new InetSocketAddress[0]), + _hosts.toArray(new Endpoint[0]), _keepAliveTimeout, _keepAliveInterval, _defaultDeadline, @@ -155,14 +155,15 @@ public ConnectionSettingsBuilder defaultClientCertificate(ClientCertificate defa * Adds an endpoint the client will use to connect. */ public ConnectionSettingsBuilder addHost(String host, int port) { - return addHost(new InetSocketAddress(host, port)); + this._hosts.add(new Endpoint(host, port)); + return this; } /** * Adds an endpoint the client will use to connect. */ public ConnectionSettingsBuilder addHost(InetSocketAddress host) { - this._hosts.push(host); + this._hosts.push(new Endpoint(host.getHostName(), host.getPort())); return this; } diff --git a/src/main/java/io/kurrent/dbclient/Endpoint.java b/src/main/java/io/kurrent/dbclient/Endpoint.java new file mode 100644 index 00000000..c1de3fb4 --- /dev/null +++ b/src/main/java/io/kurrent/dbclient/Endpoint.java @@ -0,0 +1,19 @@ +package io.kurrent.dbclient; + +public class Endpoint { + private final String host; + private final int port; + + public Endpoint(String host, int port) { + this.host = host; + this.port = port; + } + + public String getHost() { + return host; + } + + public int getPort() { + return port; + } +} diff --git a/src/main/java/io/kurrent/dbclient/KurrentDBClientSettings.java b/src/main/java/io/kurrent/dbclient/KurrentDBClientSettings.java index 44580d66..fc3c9837 100644 --- a/src/main/java/io/kurrent/dbclient/KurrentDBClientSettings.java +++ b/src/main/java/io/kurrent/dbclient/KurrentDBClientSettings.java @@ -34,7 +34,7 @@ public class KurrentDBClientSettings { private final boolean tlsVerifyCert; private final UserCredentials defaultCredentials; private final ClientCertificate defaultClientCertificate; - private final InetSocketAddress[] hosts; + private final Endpoint[] hosts; private final long keepAliveTimeout; private final long keepAliveInterval; private final Long defaultDeadline; @@ -117,7 +117,7 @@ public ClientCertificate getDefaultClientCertificate() { * The list of endpoints that the client uses to connect. * @return hosts to connect to. */ - public InetSocketAddress[] getHosts() { + public Endpoint[] getHosts() { return hosts; } @@ -177,7 +177,7 @@ public String getTlsCaFile() { boolean tlsVerifyCert, UserCredentials defaultCredentials, ClientCertificate defaultClientCertificate, - InetSocketAddress[] hosts, + Endpoint[] hosts, long keepAliveTimeout, long keepAliveInterval, Long defaultDeadline, diff --git a/src/main/java/io/kurrent/dbclient/ReadResponseObserver.java b/src/main/java/io/kurrent/dbclient/ReadResponseObserver.java index da6408c8..029d30a2 100644 --- a/src/main/java/io/kurrent/dbclient/ReadResponseObserver.java +++ b/src/main/java/io/kurrent/dbclient/ReadResponseObserver.java @@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory; import java.nio.charset.Charset; +import java.time.Instant; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -118,11 +119,21 @@ else if (value.hasLastStreamPosition()) else if (value.hasLastAllStreamPosition()) { Shared.AllStreamPosition position = value.getLastAllStreamPosition(); consumer.onLastAllStreamPosition(position.getCommitPosition(), position.getPreparePosition()); - } else if (value.hasCaughtUp()) - consumer.onCaughtUp(); - else if (value.hasFellBehind()) - consumer.onFellBehind(); - else { + } else if (value.hasCaughtUp()) { + StreamsOuterClass.ReadResp.CaughtUp caughtUp = value.getCaughtUp(); + Instant timestamp = Instant.ofEpochSecond(caughtUp.getTimestamp().getSeconds(), caughtUp.getTimestamp().getNanos()); + Long streamRevision = caughtUp.hasStreamRevision() ? caughtUp.getStreamRevision() : null; + Position position = caughtUp.hasPosition() ? new Position(caughtUp.getPosition().getCommitPosition(), caughtUp.getPosition().getPreparePosition()) : null; + + consumer.onCaughtUp(timestamp, streamRevision, position); + } else if (value.hasFellBehind()) { + StreamsOuterClass.ReadResp.FellBehind fellBehind = value.getFellBehind(); + Instant timestamp = Instant.ofEpochSecond(fellBehind.getTimestamp().getSeconds(), fellBehind.getTimestamp().getNanos()); + Long streamRevision = fellBehind.hasStreamRevision() ? fellBehind.getStreamRevision() : null; + Position position = fellBehind.hasPosition() ? new Position(fellBehind.getPosition().getCommitPosition(), fellBehind.getPosition().getPreparePosition()) : null; + + consumer.onFellBehind(timestamp, streamRevision, position); + } else { logger.warn("received unknown message variant"); } diff --git a/src/main/java/io/kurrent/dbclient/ReadStreamConsumer.java b/src/main/java/io/kurrent/dbclient/ReadStreamConsumer.java index 492f0088..a4c30aad 100644 --- a/src/main/java/io/kurrent/dbclient/ReadStreamConsumer.java +++ b/src/main/java/io/kurrent/dbclient/ReadStreamConsumer.java @@ -2,6 +2,8 @@ import org.reactivestreams.Subscriber; +import java.time.Instant; + class ReadStreamConsumer implements StreamConsumer { private final Subscriber subscriber; @@ -41,10 +43,10 @@ public void onLastAllStreamPosition(long commit, long prepare) { } @Override - public void onCaughtUp() {} + public void onCaughtUp(Instant timestamp, Long streamRevision, Position position) {} @Override - public void onFellBehind() {} + public void onFellBehind(Instant timestamp, Long streamRevision, Position position) {} @Override public void onCancelled(Throwable exception) { diff --git a/src/main/java/io/kurrent/dbclient/SingleNodeDiscovery.java b/src/main/java/io/kurrent/dbclient/SingleNodeDiscovery.java index a0eba2f5..3e28055d 100644 --- a/src/main/java/io/kurrent/dbclient/SingleNodeDiscovery.java +++ b/src/main/java/io/kurrent/dbclient/SingleNodeDiscovery.java @@ -4,14 +4,14 @@ import java.util.concurrent.CompletableFuture; class SingleNodeDiscovery implements Discovery { - private final InetSocketAddress endpoint; + private final Endpoint endpoint; - SingleNodeDiscovery(InetSocketAddress endpoint) { + SingleNodeDiscovery(Endpoint endpoint) { this.endpoint = endpoint; } @Override public CompletableFuture run(ConnectionState state) { - return CompletableFuture.runAsync(() -> state.connect(endpoint)); + return CompletableFuture.runAsync(() -> state.connect(new InetSocketAddress(this.endpoint.getHost(), this.endpoint.getPort()))); } } \ No newline at end of file diff --git a/src/main/java/io/kurrent/dbclient/StreamConsumer.java b/src/main/java/io/kurrent/dbclient/StreamConsumer.java index 36613e22..8bd4c8e1 100644 --- a/src/main/java/io/kurrent/dbclient/StreamConsumer.java +++ b/src/main/java/io/kurrent/dbclient/StreamConsumer.java @@ -1,5 +1,7 @@ package io.kurrent.dbclient; +import java.time.Instant; + public interface StreamConsumer { default void onSubscribe(org.reactivestreams.Subscription subscription) {} void onEvent(ResolvedEvent event); @@ -9,8 +11,8 @@ default void onSubscribe(org.reactivestreams.Subscription subscription) {} void onFirstStreamPosition(long position); void onLastStreamPosition(long position); void onLastAllStreamPosition(long commit, long prepare); - void onCaughtUp(); - void onFellBehind(); + void onCaughtUp(Instant timestamp, Long streamRevision, Position position); + void onFellBehind(Instant timestamp, Long streamRevision, Position position); void onCancelled(Throwable exception); void onComplete(); } diff --git a/src/main/java/io/kurrent/dbclient/SubscriptionListener.java b/src/main/java/io/kurrent/dbclient/SubscriptionListener.java index afd62fa1..5fc43989 100644 --- a/src/main/java/io/kurrent/dbclient/SubscriptionListener.java +++ b/src/main/java/io/kurrent/dbclient/SubscriptionListener.java @@ -1,5 +1,7 @@ package io.kurrent.dbclient; +import java.time.Instant; + /** * Listener used to handle catch-up subscription notifications raised throughout its lifecycle. */ @@ -28,12 +30,12 @@ public void onConfirmation(Subscription subscription) {} * Called when the subscription has reached the head of the stream. * @param subscription handle to the subscription. */ - public void onCaughtUp(Subscription subscription) {} + public void onCaughtUp(Subscription subscription, Instant timestamp, Long streamRevision, Position position) {} /** * Called when the subscription has fallen behind, meaning it's no longer keeping up with the * stream's pace. * @param subscription handle to the subscription. */ - public void onFellBehind(Subscription subscription) {} + public void onFellBehind(Subscription subscription, Instant timestamp, Long streamRevision, Position position) {} } diff --git a/src/main/java/io/kurrent/dbclient/SubscriptionStreamConsumer.java b/src/main/java/io/kurrent/dbclient/SubscriptionStreamConsumer.java index 4770cfef..80f70a12 100644 --- a/src/main/java/io/kurrent/dbclient/SubscriptionStreamConsumer.java +++ b/src/main/java/io/kurrent/dbclient/SubscriptionStreamConsumer.java @@ -1,6 +1,7 @@ package io.kurrent.dbclient; +import java.time.Instant; import java.util.concurrent.CompletableFuture; class SubscriptionStreamConsumer implements StreamConsumer { @@ -56,13 +57,13 @@ public void onLastStreamPosition(long position) {} public void onLastAllStreamPosition(long commit, long prepare) {} @Override - public void onCaughtUp() { - this.listener.onCaughtUp(this.subscription); + public void onCaughtUp(Instant timestamp, Long streamRevision, Position position) { + this.listener.onCaughtUp(this.subscription, timestamp, streamRevision, position); } @Override - public void onFellBehind() { - this.listener.onFellBehind(this.subscription); + public void onFellBehind(Instant timestamp, Long streamRevision, Position position) { + this.listener.onFellBehind(this.subscription, timestamp, streamRevision, position); } @Override diff --git a/src/main/java/io/kurrent/dbclient/resolution/DeferredNodeResolution.java b/src/main/java/io/kurrent/dbclient/resolution/DeferredNodeResolution.java index fece6c9b..337239b1 100644 --- a/src/main/java/io/kurrent/dbclient/resolution/DeferredNodeResolution.java +++ b/src/main/java/io/kurrent/dbclient/resolution/DeferredNodeResolution.java @@ -1,18 +1,20 @@ package io.kurrent.dbclient.resolution; +import io.kurrent.dbclient.Endpoint; + import java.net.InetSocketAddress; import java.util.Collections; import java.util.List; public class DeferredNodeResolution implements NodeResolution { - private final InetSocketAddress address; + private final Endpoint address; - public DeferredNodeResolution(InetSocketAddress address) { + public DeferredNodeResolution(Endpoint address) { this.address = address; } @Override public List resolve() { - return Collections.singletonList(address); + return Collections.singletonList(new InetSocketAddress(address.getHost(), address.getPort())); } } diff --git a/src/main/java/io/kurrent/dbclient/resolution/DeprecatedNodeResolution.java b/src/main/java/io/kurrent/dbclient/resolution/DeprecatedNodeResolution.java index 774f9417..be343fb6 100644 --- a/src/main/java/io/kurrent/dbclient/resolution/DeprecatedNodeResolution.java +++ b/src/main/java/io/kurrent/dbclient/resolution/DeprecatedNodeResolution.java @@ -1,5 +1,7 @@ package io.kurrent.dbclient.resolution; +import io.kurrent.dbclient.Endpoint; + import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; @@ -8,16 +10,16 @@ import java.util.stream.Collectors; public class DeprecatedNodeResolution implements NodeResolution { - private final InetSocketAddress address; + private final Endpoint address; - public DeprecatedNodeResolution(InetSocketAddress address) { + public DeprecatedNodeResolution(Endpoint address) { this.address = address; } @Override public List resolve() { try { - return Arrays.stream(InetAddress.getAllByName(address.getHostName())) + return Arrays.stream(InetAddress.getAllByName(address.getHost())) .map(addr -> new InetSocketAddress(addr, address.getPort())) .collect(Collectors.toList()); } catch (UnknownHostException e) { diff --git a/src/main/java/io/kurrent/dbclient/resolution/FixedSeedsNodeResolution.java b/src/main/java/io/kurrent/dbclient/resolution/FixedSeedsNodeResolution.java index 09c0cf44..3118a76f 100644 --- a/src/main/java/io/kurrent/dbclient/resolution/FixedSeedsNodeResolution.java +++ b/src/main/java/io/kurrent/dbclient/resolution/FixedSeedsNodeResolution.java @@ -1,18 +1,26 @@ package io.kurrent.dbclient.resolution; +import io.kurrent.dbclient.Endpoint; + import java.net.InetSocketAddress; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class FixedSeedsNodeResolution implements NodeResolution { - private final InetSocketAddress[] seeds; + private final Endpoint[] seeds; - public FixedSeedsNodeResolution(InetSocketAddress[] seeds) { + public FixedSeedsNodeResolution(Endpoint[] seeds) { this.seeds = seeds; } @Override public List resolve() { - return Arrays.asList(seeds); + List addresses = new ArrayList<>(seeds.length); + + for (Endpoint seed : seeds) + addresses.add(new InetSocketAddress(seed.getHost(), seed.getPort())); + + return addresses; } } diff --git a/src/main/proto/streams.proto b/src/main/proto/streams.proto index 0eb05295..4ff613a7 100644 --- a/src/main/proto/streams.proto +++ b/src/main/proto/streams.proto @@ -103,9 +103,37 @@ message ReadResp { FellBehind fell_behind = 9; } - message CaughtUp {} + // The $all or stream subscription has caught up and become live. + message CaughtUp { + // Current time in the server when the subscription caught up + google.protobuf.Timestamp timestamp = 1; + + // Checkpoint for resuming a stream subscription. + // For stream subscriptions it is populated unless the stream is empty. + // For $all subscriptions it is not populated. + optional int64 stream_revision = 2; + + // Checkpoint for resuming a $all subscription. + // For stream subscriptions it is not populated. + // For $all subscriptions it is populated unless the database is empty. + optional Position position = 3; + } + + // The $all or stream subscription has fallen back into catchup mode and is no longer live. + message FellBehind { + // Current time in the server when the subscription fell behind + google.protobuf.Timestamp timestamp = 1; + + // Checkpoint for resuming a stream subscription. + // For stream subscriptions it is populated unless the stream is empty. + // For $all subscriptions it is not populated. + optional int64 stream_revision = 2; - message FellBehind {} + // Checkpoint for resuming a $all subscription. + // For stream subscriptions it is not populated. + // For $all subscriptions it is populated unless the database is empty. + optional Position position = 3; + } message ReadEvent { RecordedEvent event = 1; @@ -132,7 +160,16 @@ message ReadResp { message Checkpoint { uint64 commit_position = 1; uint64 prepare_position = 2; + + // Current time in the server when the checkpoint was reached + google.protobuf.Timestamp timestamp = 3; } + + message Position { + uint64 commit_position = 1; + uint64 prepare_position = 2; + } + message StreamNotFound { event_store.client.StreamIdentifier stream_identifier = 1; } diff --git a/src/test/java/io/kurrent/dbclient/misc/ParseValidConnectionStringTests.java b/src/test/java/io/kurrent/dbclient/misc/ParseValidConnectionStringTests.java index 8000293f..888b6a76 100644 --- a/src/test/java/io/kurrent/dbclient/misc/ParseValidConnectionStringTests.java +++ b/src/test/java/io/kurrent/dbclient/misc/ParseValidConnectionStringTests.java @@ -145,7 +145,7 @@ public void assertEquals(KurrentDBClientSettings settings, KurrentDBClientSettin Assertions.assertEquals(settings.getHosts().length, other.getHosts().length); IntStream.range(0, settings.getHosts().length).forEach((i) -> { - Assertions.assertEquals(settings.getHosts()[i].getHostName(), other.getHosts()[i].getHostName()); + Assertions.assertEquals(settings.getHosts()[i].getHost(), other.getHosts()[i].getHost()); Assertions.assertEquals(settings.getHosts()[i].getPort(), other.getHosts()[i].getPort()); }); } @@ -227,7 +227,7 @@ private KurrentDBClientSettings parseJson(String input) throws JsonProcessingExc } tree.get("hosts").elements().forEachRemaining((host) -> { - builder.addHost(new InetSocketAddress(host.get("address").asText(), host.get("port").asInt())); + builder.addHost(host.get("address").asText(), host.get("port").asInt()); }); if (tree.get("features") != null) { diff --git a/src/test/java/io/kurrent/dbclient/streams/SubscriptionTests.java b/src/test/java/io/kurrent/dbclient/streams/SubscriptionTests.java index c05e6f68..9798ee42 100644 --- a/src/test/java/io/kurrent/dbclient/streams/SubscriptionTests.java +++ b/src/test/java/io/kurrent/dbclient/streams/SubscriptionTests.java @@ -7,6 +7,7 @@ import org.junit.jupiter.api.Timeout; import java.io.IOException; +import java.time.Instant; import java.util.ArrayList; import java.util.Optional; import java.util.concurrent.CountDownLatch; @@ -176,7 +177,7 @@ default void testCaughtUpMessageIsReceived() throws Throwable { Subscription subscription = client.subscribeToStream(streamName, new SubscriptionListener() { @Override - public void onCaughtUp(Subscription subscription) { + public void onCaughtUp(Subscription subscription, Instant timestamp, Long streamRevision, Position position) { caughtUp.countDown(); } }, SubscribeToStreamOptions.get().fromStart()).get();