Flaugh24 commented on code in PR #1472: URL: https://github.com/apache/ignite-3/pull/1472#discussion_r1057136149
########## modules/cli/src/main/java/org/apache/ignite/internal/cli/core/JdbcUrl.java: ########## @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +package org.apache.ignite.internal.cli.core; + +import java.net.MalformedURLException; +import java.net.URL; + +/** Representation of Ignite JDBC url. */ +public class JdbcUrl { + private final String host; + private final int port; + + /** Constructor. */ + private JdbcUrl(String host, int port) { + this.host = host; + this.port = port; + } + + /** Returns {@link JdbcUrl} with provided host and port. */ + public static JdbcUrl of(String url, int port) throws MalformedURLException { + return new JdbcUrl(new URL(url).getHost(), port); + } + + public String toString() { Review Comment: done ########## 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); Review Comment: done ########## 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); 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]
