public interface Cmd<T>
execute
method. The execute(ax.antpick.k2hdkc.Session) method accepts a Session argument and returns a Result instance.
This interface is currently a package-private interface because I think it's hard for implementators to use the k2hdkc C functions very well. I will move this interface to a public one if I could think it is much easier to use them.
Here is a pseudo code implements the interface:
public class ExampleCmd extends CmdBase implements Cmd {
private final String key;
public SampleCmd(String key) {
this.key = key;
}
@Override
public Optional Optional<Result<T>> execute(Session session) throws IOException {
// get value from cluster.
String rval = null;
String password = null;
PointerByReference ppval = new PointerByReference();
// Call the k2hdkc C function
boolean isSuccess = INSTANCE.k2hdkc_pm_get_str_value_wp(session.getHandle(), this.key, password, ppval);
Result<T> result = Result.of(SampleCmd.class.getSimpleName(), isSuccess, (T)Boolean.valueOf(isSuccess), 0, 0);
return Optional.of(result);
}
}
Or, you can implement the interface as a Functional interface. Supposing the interface is a public, you could write this:
try (
Cluster c = Cluster.of("slave.ini");
Session s = Session.of(); ) {
Cmd<Session, Optional<Result<T>>> cmd = s -> {
try {
K2hdkcLibrary INSTANCE = Session.getLibrary(); // can throws IOException
boolean b = INSTANCE.k2hdkc_pm_set_str_value_wa(s.getHandle(), "key", "value", false, null, null);
Result<T> rb = Result.of("set", b, (T)Boolean.valueOf(b), 0, 0);
return Optional.of(rb);
} catch (IOException ex) {
return Optional.empty();
}
};
System.out.println(cmd.execute(s));
} catch (IOException ex) {
System.err.println(ex.getMessage());
}
| Modifier and Type | Interface and Description |
|---|---|
static class |
Cmd.DataType
DataType of data in CAS operation
|
| Modifier and Type | Field and Description |
|---|---|
static boolean |
DEFAULT_CHECK_PARENT_ATTRS
Default checkParentAttrs is
true. |
static long |
DEFAULT_EXPIRATION_DURATION
Default data expiration duration is
0. |
static boolean |
DEFAULT_IS_CHECK_PARENT_ATTRS
Default clear all subkeys is
false. |
static boolean |
DEFAULT_IS_CLEAR_SUBKEYS
Default clear all subkeys is
false. |
static boolean |
DEFAULT_IS_FIFO
Default isFifo is
true. |
static boolean |
DEFAULT_IS_INCREMENT
Default isIncrement is
true. |
static boolean |
DEFAULT_NEED_RETURN_VALUE
Default isReturnValue is
true. |
static String |
DEFAULT_PARENT_KEY
Default parent string is
null. |
static String |
DEFAULT_PASS
Default passphrase string is
null. |
static int |
DEFAULT_REMOVE_ELEMENT_SIZE
Default pass is null.
|
static boolean |
DEFAULT_REMOVE_RECURSIVELY
Default removing subkeys recursively is
false. |
static String[] |
DEFAULT_SUBKEYS
Default clear all subkeys is
false. |
| Modifier and Type | Method and Description |
|---|---|
static int |
bytesToInt(byte[] b)
Packs a byte array to integer.
|
<T> Optional<Result<T>> |
execute(Session session)
Executes a command and return a result.
|
static int |
getValusAsInt(byte[] value)
Returns a value as a integer value.
|
static final boolean DEFAULT_REMOVE_RECURSIVELY
false.static final boolean DEFAULT_IS_CLEAR_SUBKEYS
false.static final String[] DEFAULT_SUBKEYS
false.static final String DEFAULT_PARENT_KEY
null.static final boolean DEFAULT_IS_CHECK_PARENT_ATTRS
false.static final int DEFAULT_REMOVE_ELEMENT_SIZE
static final boolean DEFAULT_NEED_RETURN_VALUE
true.static final boolean DEFAULT_IS_FIFO
true.static final boolean DEFAULT_CHECK_PARENT_ATTRS
true.static final boolean DEFAULT_IS_INCREMENT
true.static final String DEFAULT_PASS
null.static final long DEFAULT_EXPIRATION_DURATION
0.<T> Optional<Result<T>> execute(Session session) throws IOException
session - a Session instance.IOException - if the native C library file can't be open.static int bytesToInt(byte[] b)
b - a byte arraystatic int getValusAsInt(byte[] value)
value - a byte arrayIllegalStateException - this.value is not valid integer.Copyright © 2020. All rights reserved.