public class RemoveSubkeyCmd extends CmdBase implements Cmd<Boolean>
An Usage Example:
Supposing you want to set the subkeys("subkey1" and "subkey2") and remove a subkey("subkey1"), you could write this as:
package com.example;
import ax.antpick.k2hdkc.*;
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import java.io.IOException;
import java.util.*;
import java.util.stream.*;
public class App {
public static void main(String[] args) {
try (Cluster c = Cluster.of("cluster/slave.yaml");
Session s = Session.of(c); ) {
String[] subkeys = {"subkey1", "subkey2"};
SetAllCmd set = SetAllCmd.of("key", "val", subkeys);
assert (set.execute(s).get().isSuccess());
// 1. get key
GetCmd get = GetCmd.of("key");
String str = (String) get.execute(s).get().getValue();
assert (str.equals("val"));
// 2. get subkeys
GetSubkeysCmd getsub = GetSubkeysCmd.of("key");
List<String> list = (List<String>) getsub.execute(s).get().getValue();
assert (list.get(0).equals("subkey1"));
assert (list.get(1).equals("subkey2"));
// 3. remove subkeys
RemoveSubkeyCmd rmsub = RemoveSubkeyCmd.of("key", "subkey1");
assert (rmsub.execute(s).get().isSuccess());
// 4. get subkeys
GetSubkeysCmd getsub2 = GetSubkeysCmd.of("key");
List<String> list2 = (List<String>) getsub2.execute(s).get().getValue();
assert (list2.get(0).equals("subkey2"));
} catch (IOException ex) {
System.out.println(ex.getMessage());
assert (false);
}
}
}
You shoule see the "subkey1", "subkey2" and "subkey2" on the stdout if you could successfully run it. Before running the code above, You should run three processes.
The following commands in this repository will run all processes you need in localhost.
$ cd cluster
$ sh start_server.sh
Cmd.DataType
DEFAULT_CHECK_PARENT_ATTRS, DEFAULT_EXPIRATION_DURATION, DEFAULT_IS_CHECK_PARENT_ATTRS, DEFAULT_IS_CLEAR_SUBKEYS, DEFAULT_IS_FIFO, DEFAULT_IS_INCREMENT, DEFAULT_NEED_RETURN_VALUE, DEFAULT_PARENT_KEY, DEFAULT_PASS, DEFAULT_REMOVE_ELEMENT_SIZE, DEFAULT_REMOVE_RECURSIVELY, DEFAULT_SUBKEYS
Modifier and Type | Method and Description |
---|---|
<T> Optional<Result<T>> |
execute(Session session)
Remove subkeys.
|
static RemoveSubkeyCmd |
of(String key,
String subkey)
Constructs a RemoveSubkeyCmd instance.
|
static RemoveSubkeyCmd |
of(String key,
String subkey,
boolean isRemoveRecursively)
Constructs a RemoveSubkeyCmd instance.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
bytesToInt, getValusAsInt
public static RemoveSubkeyCmd of(String key, String subkey)
key
- a key stringsubkey
- a subkey stringIllegalArgumentException
- if a key or a val string is null or emptypublic static RemoveSubkeyCmd of(String key, String subkey, boolean isRemoveRecursively)
key
- a key stringsubkey
- a subkey stringisRemoveRecursively
- a flag to remove recursively.IllegalArgumentException
- if a key or a val string is null or emptypublic <T> Optional<Result<T>> execute(Session session) throws IOException
execute
in interface Cmd<Boolean>
session
- a session instanceIllegalArgumentException
- if an illegal augment existsIOException
- if underlying library errors occur.Copyright © 2020. All rights reserved.