Flaugh24 commented on code in PR #1472:
URL: https://github.com/apache/ignite-3/pull/1472#discussion_r1057136855
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/core/repl/Session.java:
##########
@@ -18,51 +18,60 @@
package org.apache.ignite.internal.cli.core.repl;
import jakarta.inject.Singleton;
+import java.util.List;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
/**
- * Connection session that in fact is holder for state: connected or
disconnected.
- * Also has a nodeUrl if the state is connected.
+ * Connection session that in fact is holder for state: connected or
disconnected. Also has a nodeUrl if the state is connected.
*/
@Singleton
public class Session {
- private boolean connectedToNode;
-
- private String nodeUrl;
-
- private String nodeName;
+ private final IgniteLogger log = Loggers.forClass(getClass());
- private String jdbcUrl;
-
- public boolean isConnectedToNode() {
- return connectedToNode;
- }
+ private SessionDetails sessionDetails;
- public void setConnectedToNode(boolean connectedToNode) {
- this.connectedToNode = connectedToNode;
- }
+ private boolean connectedToNode;
- public String nodeUrl() {
- return nodeUrl;
- }
+ private final List<SessionEventListener> listeners;
- public String nodeName() {
- return nodeName;
+ public Session(List<SessionEventListener> listeners) {
+ this.listeners = listeners;
}
- public void setNodeName(String nodeName) {
- this.nodeName = nodeName;
+ /** Creates session details with provided nodeUrl, nodeName, jdbcUrl. */
+ public synchronized void connect(String nodeUrl, String nodeName, String
jdbcUrl) {
+ this.sessionDetails = new SessionDetails(nodeUrl, nodeName, jdbcUrl);
+ this.connectedToNode = true;
+ listeners.forEach(it -> {
+ try {
+ it.onConnect(this);
+ } catch (Exception e) {
+ log.warn("Got an exception: ", e);
+ }
+ });
}
- public void setNodeUrl(String nodeUrl) {
- this.nodeUrl = nodeUrl;
+ /** Clears session details and sets false to connectedToNode. */
+ public synchronized void disconnect() {
+ this.sessionDetails = new SessionDetails();
+ this.connectedToNode = false;
+ listeners.forEach(it -> {
+ try {
+ it.onConnect(this);
+ } catch (Exception e) {
+ log.warn("Got an exception: ", e);
+ }
+ });
}
- public String jdbcUrl() {
- return jdbcUrl;
+ public boolean isConnectedToNode() {
+ return connectedToNode;
}
- public void setJdbcUrl(String jdbcUrl) {
- this.jdbcUrl = jdbcUrl;
+ /** Returns {@link SessionDetails}. */
+ public SessionDetails sessionDetails() {
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]