public class GetCmd extends CmdBase implements Cmd<String>
An Usage Example:
Suppose you want to get the value of "key" from a k2hdkc cluster. 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 sess = Session.of(c); ) {
SetCmd set = SetCmd.of("key", "value");
assert (set != null);
assert (set.execute(sess) != null);
assert (set.execute(sess).get().isSuccess());
GetCmd get = GetCmd.of("key");
assert (get != null);
assert (get.execute(sess) != null);
assert (get.execute(sess).get().isSuccess());
String str = (String) get.execute(sess).get().getValue();
assert (str.equals("value"));
} catch (IOException ex) {
System.out.println(ex.getMessage());
assert (false);
}
}
}
You shoule see only the "true" and "value" 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)
Retrieves the value of a key
|
static GetCmd |
of(String key)
Constructs a GetCmd instance.
|
static GetCmd |
of(String key,
String pass)
Constructs a GetCmd instance.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
bytesToInt, getValusAsInt
public static GetCmd of(String key)
key
- a key stringIllegalArgumentException
- if a key string is null or emptypublic static GetCmd of(String key, String pass)
key
- a key stringpass
- a password string to retrieve the value(optional)IllegalArgumentException
- if a key string is null or emptypublic <T> Optional<Result<T>> execute(Session session) throws IOException
execute
in interface Cmd<String>
session
- a Session
instanceIllegalArgumentException
- if an illegal augment existsIOException
- if underlying library errors occur.Copyright © 2020. All rights reserved.