public class KeyQueueAddCmd extends CmdBase implements Cmd<Boolean>
An Usage Example:
Supposing you want to add a new element(the element key name is "key1" ant the value is "val1" to a queue(the queue name is "q1"), then you get(remove) the element from the queue, 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 cluster = Cluster.of("cluster/slave.yaml");
Session sess = Session.of(cluster); ) {
// 1. add an element to this queue
KeyQueueAddCmd qadd = KeyQueueAddCmd.of("testQueueAddCmdArg1", "key1", "val1");
assert (qadd.execute(sess).get().isSuccess());
// 2. remove an element from this queue
KeyQueueRemoveCmd qrm = KeyQueueRemoveCmd.of("testQueueAddCmdArg1");
Map<String, String> r = (Map<String, String>) qrm.execute(sess).get().getValue();
assert (r.containsKey("key1"));
assert (r.containsValue("val1"));
} catch (IOException ex) {
System.out.println(ex.getMessage());
assert (false);
}
}
}
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 an element to this queue.
|
static KeyQueueAddCmd |
of(String prefix,
String key,
String val)
Constructs a KeyQueueAddCmd instance.
|
static KeyQueueAddCmd |
of(String prefix,
String key,
String val,
boolean isFifo,
boolean checkParentAttrs,
String pass,
long expirationDuration)
Constructs a KeyQueueAddCmd instance.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
bytesToInt, getValusAsInt
public static KeyQueueAddCmd of(String prefix, String key, String val)
prefix
- a string for an identification of a queue.key
- a key stringval
- a valur stringIllegalArgumentException
- if a key or a val string is null or emptypublic static KeyQueueAddCmd of(String prefix, String key, String val, boolean isFifo, boolean checkParentAttrs, String pass, long expirationDuration)
prefix
- a string for an identification of a queue.key
- a key stringval
- a valur stringisFifo
- true
if the first element which comes in will goes out.
false
otherwise.checkParentAttrs
- true
if checking a parent attribute before changing a
subkeys. false
otherwise.pass
- a password stringexpirationDuration
- a duration to expire.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.