Repository navigation
feat(core): add Connection javadoc #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,28 +14,114 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
| import io.tarantool.core.protocol.IProtoMessage; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import io.tarantool.core.protocol.IProtoResponse; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** An interface representing interaction with a Tarantool node via a connection abstraction. */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| public interface Connection extends AutoCloseable { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Method for asynchronous connection to a Tarantool node. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param addr address at which the connection is being established | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param timeoutMs timeout, specified in milliseconds, that defines the maximum wait time between | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * the start of a connection attempt and the receipt of a greeting packet | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return an instance of {@link CompletableFuture} that completes with a greeting or an error. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Major. Не описан } else if (state.get() != State.CLOSED) {
throw new IllegalStateException(state.get().getMessage());
}и описать это в |
||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+20
to
+27
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| CompletableFuture<Greeting> connect(InetSocketAddress addr, long timeoutMs) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| throws IllegalStateException; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Asynchronously sends an {@link IProtoMessage} object to a Tarantool node. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param message the message to be sent to Tarantool. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return a {@link CompletableFuture} object. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
bitgorbovsky marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| * @throws IllegalStateException if the method is called when the connection is not in a state | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * ready to send or receive messages. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+31
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| CompletableFuture<Void> send(IProtoMessage message) throws IllegalStateException; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Registers a callback that will receive any {@link IProtoResponse} message arriving from a | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Tarantool node. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param listener A handler for responses from Tarantool. Must not be {@code null}. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return The same connection object on which this method was called. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @implSpec Each subsequent call to this method will overwrite the previously registered handler. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Not thread-safe. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @apiNote Typically used when connection object are creating and not used thereafter. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+41
to
+50
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Connection listen(Consumer<IProtoResponse> listener); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * A method that registers a callback to handle a connection-close event. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param event the connection-close event ({@link ConnectionCloseEvent}) for which the handler is | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * being registered. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @param handler the handler object. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @implSpec If multiple handlers are provided for the same event, the implementation must | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
bitgorbovsky marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| * register all of them, rather than replacing a previously registered handler with a new one. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
bitgorbovsky marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| * All callbacks are guaranteed to be invoked after the connection has transitioned to the | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blocking. Утверждение не соответствует реализации. В if (state.get() != State.CONNECTING) {
Exception ex = new ConnectionClosedException(message, f.cause());
failConnectPromise(ex);
fire(event, ex); // состояние CLOSING / READY, channel ещё не null
}
state.set(State.CLOSED);
channel = null;Для Предлагаю убрать это предложение. Если гарантия нужна, сначала завершить переход, затем уведомлять: boolean notify = state.get() != State.CONNECTING;
Exception ex = notify ? new ConnectionClosedException(message, f.cause()) : null;
if (notify) {
failConnectPromise(ex);
}
state.set(State.CLOSED);
channel = null;
connectPromise = null;
if (notify) {
fire(event, ex);
}
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вероятно, что-то из этого правда |
||||||||||||||||||||||||||||||||||||||||||||||||||
| * closed state. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @apiNote Typically used during the creation of a connection object and not used thereafter. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+53
to
+64
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Connection onClose(ConnectionCloseEvent event, BiConsumer<Connection, Throwable> handler); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Gets greeting packet. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return {@link Optional#empty()} if this method was called before the connection reached a | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
bitgorbovsky marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| * state ready. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
bitgorbovsky marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Optional<Greeting> getGreeting(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Checks whether the connection is currently active and ready to process requests. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * <p>Note that this status represents a snapshot in time. The connection state may change | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * immediately after this method returns. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return {@code true} if the connection is currently in the ready state; {@code false} otherwise | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| boolean isConnected(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Closes the connection reporting the close cause as a graceful shutdown of the server. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * <p>The method is meant to be called upon receiving the {@code box.shutdown} notification from | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Tarantool. At that moment the connection is still operational, it is the server that is about | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * to terminate. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * <p>In contrast to {@link #close()}, the close is reported to the listeners as {@link | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
bitgorbovsky marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| * ConnectionCloseEvent#CLOSE_BY_SHUTDOWN} rather than {@link | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * ConnectionCloseEvent#CLOSE_BY_CLIENT}, and they are expected to react differently: a connection | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * closed by the client needs no attention, while a connection closed by shutdown has to be | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * replaced with a new one. The method itself does not reestablish the connection. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * <p>Requests pending on the connection are not failed by this method, the caller is responsible | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
bitgorbovsky marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| * for cancelling them. The method does nothing if the connection is already closed or is being | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * closed. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * @see <a | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * href="https://www.tarantool.io/ru/doc/latest/reference/internals/iproto/graceful_shutdown/">Tarantool | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * graceful shutdown</a> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| void shutdownClose(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| void setIdleTimeout(int idleTimeout); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blocking. У метода нет javadoc. Нужно описать: единицы измерения — миллисекунды; /**
* Sets the idle timeout for the connection.
*
* <p>The value is applied when the connection is established, so it affects only the next
* connection attempt.
*
* @param idleTimeout idle timeout in milliseconds; a positive value enables the check, a
* non-positive value disables it
*/
void setIdleTimeout(int idleTimeout); |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Method that pauses the reading of the buffer containing incoming data at the OS level for | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
bitgorbovsky marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| * Netty. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+110
to
+113
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| void pause(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Method that resumes the reading of the buffer containing incoming data at the OS level for | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * Netty. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+116
to
+119
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| void resume(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| void setIdleTimeout(int idleTimeout); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * A method that checks whether automatic reading of a buffer with incoming data has been stopped | ||||||||||||||||||||||||||||||||||||||||||||||||||
| * at the OS level for Netty. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+122
to
+125
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| boolean isPaused(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.