public class AddSubkeyCmd extends CmdBase implements Cmd<Boolean>
An Usage Example:
Supposing you want to add a subkey(the name is "subkey") to a key(the name is "key"), 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); ) {
// 1. add a subkey
AddSubkeyCmd cmd = AddSubkeyCmd.of("key", "subkey");
System.out.println(cmd.execute(s).get().getValue()); // true
// 2. get subkeys
GetSubkeysCmd get = GetSubkeysCmd.of("key");
List<String> list = (List<String>) get.execute(s).get().getValue(); // subkey
System.out.println(list.get(0)); // subkey
// 3. clear subkeys
ClearSubkeysCmd clear = ClearSubkeysCmd.of("key");
System.out.println(clear.execute(s).get().getValue()); // true
} catch (IOException ex) {
System.out.println(ex.getMessage());
assert (false);
}
}
}
You shoule see only the "true" message 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)
Adds a new subkey to the current subkeys of a key.
|
static AddSubkeyCmd |
of(String key,
String subkey)
Constructs a
AddSubkeyCmd instance. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
bytesToInt, getValusAsInt
public static AddSubkeyCmd of(String key, String subkey)
AddSubkeyCmd
instance.key
- a key stringsubkey
- a val stringAddSubkeyCmd
objectIllegalArgumentException
- 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
instance.Result
instance.IllegalArgumentException
- if an illegal augment existsIOException
- if underlying library errors occur.Copyright © 2020. All rights reserved.