You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pt...@apache.org on 2021/08/02 08:20:52 UTC
[ignite-3] 01/01: IGNITE-15218 Add async methods to IgniteTables
This is an automated email from the ASF dual-hosted git repository.
ptupitsyn pushed a commit to branch ignite-15218
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
commit b5754065a392086ce21148901c21dc2346a2013a
Author: Pavel Tupitsyn <pt...@apache.org>
AuthorDate: Mon Aug 2 11:20:34 2021 +0300
IGNITE-15218 Add async methods to IgniteTables
---
.../apache/ignite/table/manager/IgniteTables.java | 51 ++++++++++++++++++++++
.../ignite/internal/client/table/ClientTables.java | 22 ++++++++--
2 files changed, 69 insertions(+), 4 deletions(-)
diff --git a/modules/api/src/main/java/org/apache/ignite/table/manager/IgniteTables.java b/modules/api/src/main/java/org/apache/ignite/table/manager/IgniteTables.java
index cf1342e..b396544 100644
--- a/modules/api/src/main/java/org/apache/ignite/table/manager/IgniteTables.java
+++ b/modules/api/src/main/java/org/apache/ignite/table/manager/IgniteTables.java
@@ -21,6 +21,7 @@
package org.apache.ignite.table.manager;
import java.util.List;
+import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import org.apache.ignite.configuration.schemas.table.TableChange;
import org.apache.ignite.table.Table;
@@ -40,6 +41,16 @@ public interface IgniteTables {
Table createTable(String name, Consumer<TableChange> tableInitChange);
/**
+ * Creates a new table with the given {@code name}.
+ * If a table with the same name already exists, an exception will be thrown.
+ *
+ * @param name Table name.
+ * @param tableInitChange Table changer.
+ * @return Newly created table.
+ */
+ CompletableFuture<Table> createTableAsync(String name, Consumer<TableChange> tableInitChange);
+
+ /**
* Alter a cluster table.
*
* @param name Table name.
@@ -48,6 +59,14 @@ public interface IgniteTables {
void alterTable(String name, Consumer<TableChange> tableChange);
/**
+ * Alter a cluster table.
+ *
+ * @param name Table name.
+ * @param tableChange Table changer.
+ */
+ CompletableFuture<Void> alterTableAsync(String name, Consumer<TableChange> tableChange);
+
+ /**
* Creates a new table with the given {@code name} or returns an existing one with the same {@code name}.
*
* @param name Table name.
@@ -57,6 +76,15 @@ public interface IgniteTables {
Table getOrCreateTable(String name, Consumer<TableChange> tableInitChange);
/**
+ * Creates a new table with the given {@code name} or returns an existing one with the same {@code name}.
+ *
+ * @param name Table name.
+ * @param tableInitChange Table changer.
+ * @return Existing or newly created table.
+ */
+ CompletableFuture<Table> getOrCreateTableAsync(String name, Consumer<TableChange> tableInitChange);
+
+ /**
* Drops a table with the name specified.
* If a table with the specified name does not exist in the cluster, the operation has no effect.
*
@@ -65,6 +93,14 @@ public interface IgniteTables {
void dropTable(String name);
/**
+ * Drops a table with the name specified.
+ * If a table with the specified name does not exist in the cluster, the operation has no effect.
+ *
+ * @param name Table name.
+ */
+ CompletableFuture<Void> dropTableAsync(String name);
+
+ /**
* Gets a list of all started tables.
*
* @return List of tables.
@@ -72,10 +108,25 @@ public interface IgniteTables {
List<Table> tables();
/**
+ * Gets a list of all started tables.
+ *
+ * @return List of tables.
+ */
+ CompletableFuture<List<Table>> tablesAsync();
+
+ /**
* Gets a table by name, if it was created before.
*
* @param name Name of the table.
* @return Tables with corresponding name or {@code null} if table isn't created.
*/
Table table(String name);
+
+ /**
+ * Gets a table by name, if it was created before.
+ *
+ * @param name Name of the table.
+ * @return Tables with corresponding name or {@code null} if table isn't created.
+ */
+ CompletableFuture<Table> tableAsync(String name);
}
diff --git a/modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTables.java b/modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTables.java
index e001663..7cacc0b 100644
--- a/modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTables.java
+++ b/modules/client/src/main/java/org/apache/ignite/internal/client/table/ClientTables.java
@@ -49,17 +49,28 @@ public class ClientTables implements IgniteTables {
return createTableAsync(name, tableInitChange).join();
}
- public CompletableFuture<Table> createTableAsync(String name, Consumer<TableChange> tableInitChange) {
+ /** {@inheritDoc} */
+ @Override public CompletableFuture<Table> createTableAsync(String name, Consumer<TableChange> tableInitChange) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
@Override public void alterTable(String name, Consumer<TableChange> tableChange) {
+ alterTableAsync(name, tableChange).join();
+ }
+
+ /** {@inheritDoc} */
+ @Override public CompletableFuture<Void> alterTableAsync(String name, Consumer<TableChange> tableChange) {
throw new UnsupportedOperationException();
}
/** {@inheritDoc} */
@Override public Table getOrCreateTable(String name, Consumer<TableChange> tableInitChange) {
+ return getOrCreateTableAsync(name, tableInitChange).join();
+ }
+
+ /** {@inheritDoc} */
+ @Override public CompletableFuture<Table> getOrCreateTableAsync(String name, Consumer<TableChange> tableInitChange) {
throw new UnsupportedOperationException();
}
@@ -68,7 +79,8 @@ public class ClientTables implements IgniteTables {
dropTableAsync(name).join();
}
- public CompletableFuture<Void> dropTableAsync(String name) {
+ /** {@inheritDoc} */
+ @Override public CompletableFuture<Void> dropTableAsync(String name) {
return ch.requestAsync(ClientOp.TABLE_DROP, w -> w.out().packString(name));
}
@@ -77,7 +89,8 @@ public class ClientTables implements IgniteTables {
return tablesAsync().join();
}
- public CompletableFuture<List<Table>> tablesAsync() {
+ /** {@inheritDoc} */
+ @Override public CompletableFuture<List<Table>> tablesAsync() {
return ch.serviceAsync(ClientOp.TABLES_GET, r -> {
var in = r.in();
var cnt = in.unpackMapHeader();
@@ -95,7 +108,8 @@ public class ClientTables implements IgniteTables {
return tableAsync(name).join();
}
- public CompletableFuture<Table> tableAsync(String name) {
+ /** {@inheritDoc} */
+ @Override public CompletableFuture<Table> tableAsync(String name) {
return ch.serviceAsync(ClientOp.TABLE_GET, w -> w.out().packString(name),
r -> new ClientTable(ch, r.in().unpackUuid(), name));
}