public final class Quasardb extends Object implements Iterable<QuasardbEntry<?>>
Date for a provided alias.Usage example :
// First : create a configuration object.
QuasardbConfig config = new QuasardbConfig();
// Second : create a node object
QuasardbNode node = new QuasardbNode("127.0.0.1", 1234);
// Third : add new node to config
config.addNode(node);
// Fourth : create a related quasardb instance.
Quasardb qdb = new Quasardb(config);
// Or you can supply the configuration later :
// Quasardb qdb = new Quasardb();
// qdb.setConfig(config);
// Fifth : connect to quasardb cluster.
qdb.connect();
// Sixth : use the quasardb instance :
qdb.put("foo", new String("bar"));
System.out.println(" => key 'foo' contains : " + qdb.get("foo"));
// Seventh : disconnect from the quasardb cluster
// Notice that this step is optional
qdb.close();
Note about entries :
| Constructor and Description |
|---|
Quasardb() |
Quasardb(QuasardbConfig config)
Create a quasardb instance with the provided configuration.
The configuration must have the following parameters : nodes: a collection of QuasardbNode.
expiry: the default expiry time in seconds for all new entries.
Example : |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close the connection to the quasardb instance and frees resources.
|
<V> V |
compareAndSwap(String alias,
V value,
V comparand)
Atomically compare an existing alias with comparand, updates it to new if they match and return the original value.
Please note that entries starting with "qdb" are reserved. |
<V> V |
compareAndSwap(String alias,
V value,
V comparand,
long expiryTime)
Atomically compare an existing alias with comparand, updates it to new if they match and return the original value.
Please note that entries starting with "qdb" are reserved. |
void |
connect()
Initialize connection to the quasardb instance and setup serialization framework.
|
<V> V |
get(String alias)
Get the entry associated with the supplied unique key (alias).
|
<V> V |
getAndReplace(String alias,
V value)
Update an existing alias with data and return its previous value.
Please note that entries starting with "qdb" are reserved. |
<V> V |
getAndReplace(String alias,
V value,
long expiryTime)
Update an existing alias with data and return its previous value.
Please note that entries starting with "qdb" are reserved. |
String |
getBuild()
Retrieve the build version of the current quasardb instance.
|
QuasardbConfig |
getConfig()
Get the current instance configuration.
|
String |
getCurrentNodeConfig()
Retrieve the configuration of the current quasardb instance in JSON.
|
String |
getCurrentNodeStatus()
Retrieve the status of the current quasardb instance in JSON format.
|
String |
getCurrentNodeTopology()
Retrieve the topology of the current quasardb instance in JSON.
|
long |
getDefaultExpiryTimeInSeconds()
Get the default expiry time in seconds for all new entries.
|
Date |
getExpiryTimeInDate(String alias)
Retrieve the expiry time in date for a provided alias
|
long |
getExpiryTimeInSeconds(String alias)
Retrieve the expiry time in seconds for a provided alias
|
String |
getNodeConfig(String node,
int port)
Retrieve the configuration of the specific quasardb instance in JSON.
|
String |
getNodeStatus(String node,
int port)
Retrieve the status of the current quasardb instance in JSON format.
|
String |
getNodeTopology(String node,
int port)
Retrieve the topology of the current quasardb instance.
|
<V> V |
getRemove(String alias)
Atomically get the entry associated with the supplied unique key (alias) and remove it.
|
String |
getVersion()
Retrieve the version of the current quasardb instance.
|
Iterator<QuasardbEntry<?>> |
iterator()
Quasardb implements
Iterable for QuasardbEntry, providing support for simplified iteration. |
void |
purgeAll()
Delete all the stored objects in the current quasardb instance.
Use with caution |
<V> void |
put(String alias,
V value)
Adds an entry (value) to the current qdb instance under the alias key.
Entries must not already exist. Entries starting with "qdb" are reserved. |
<V> void |
put(String alias,
V value,
long expiryTime)
Adds an entry (value) to the current qdb instance under the alias key.
Entries must not already exist. Entries starting with "qdb" are reserved. |
boolean |
remove(String alias)
Delete the object associated with the alias key.
Please note that entries starting with "qdb" are reserved. |
<V> boolean |
removeIf(String alias,
V comparand)
Atomically delete the object associated whith the alias key if the object is equal to comparand.
|
<V> Results |
runBatch(List<Operation<V>> operations)
Submit a list of operation which can increase performance when it is necessary to run many small operations.
Using properly the batch operations requires : initializing running list of operations read results |
void |
setConfig(QuasardbConfig config)
Updates the configuration properties
|
void |
setDefaultExpiryTimeInSeconds(long expiryTime)
Set the default expiry time in seconds for all next entries.
|
void |
setExpiryTimeAt(String alias,
Date expiryDate)
Change the expiry time for a provided alias at the provided date.
|
void |
setExpiryTimeInSeconds(String alias,
long expiryTime)
Change the expiry time in seconds for a provided alias
|
List<String> |
startsWith(String prefix)
Perform a search prefix based operation on all quasardb entries.
Pay attention that : search operation is based on aliases, not on values. search operation is case sensitive. searching on reserved aliases (starts with "qdb") is not allowed. |
void |
stopCurrentNode(String reason)
Stop the current node with a given reason.
|
void |
stopNode(String node,
int port,
String reason)
Stop a specific node with a given reason.
|
String |
toString() |
<V> boolean |
update(String alias,
V value)
Update an existing entry or create a new one.
|
<V> boolean |
update(String alias,
V value,
long expiryTime)
Update an existing entry or create a new one.
Please note that entries starting with "qdb" are reserved. |
public Quasardb()
public Quasardb(QuasardbConfig config)
QuasardbNode.
// First : create a configuration.
QuasardbConfig config = new QuasardbConfig();
// Second : add a node to the configuration
QuasardbNode node = new QuasardbNode("127.0.0.1", 2836);
config.addNode(node);
// Optionnaly set a default expiry time in seconds on all next entries
config.setExpiryTimeInSeconds(2);
// Second : create a related quasardb instance.
Quasardb myQuasardbInstance = new Quasardb(config);
config - the config map in order to initialize connexion with the quasardb instanceQuasardbException - if initialization step failpublic void connect()
throws QuasardbException
QuasardbException - if connection to the quasardb instance failpublic String getVersion() throws QuasardbException
QuasardbException - if the connection with the current instance fail.public String getBuild() throws QuasardbException
QuasardbException - if the connection with the current instance fail.public String getCurrentNodeStatus() throws QuasardbException
{
"engine_build_date":"87f8d02 2014-01-15 16:12:30 +0100",
"engine_version":"master",
"entries":
{
"persisted":{"count":0,"size":0},
"resident":{"count":0,"size":0}
},
"hardware_concurrency":6,
"memory":
{
"physmem":{"total":25767272448,"used":5493329920},
"vm":{"total":8796092891136,"used":417980416}
},
"network":{
"listening_address":"127.0.0.1",
"listening_port":2836,
"partitions":
{
"available_sessions":[1999,1999,2000,2000,2000],
"count":5,
"max_sessions":2000
}
},
"node_id":"5309f39a3f176b9-179cd55bd9dc83e5-c09beea926e4bb75-a460c8c4e5487da9",
"operating_system":"Microsoft Windows 7 Ultimate Edition Service Pack 1 (build 7601), 64-bit",
"operations":
{
"compare_and_swap":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
},
"find":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
},
"find_remove":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
},
"find_update":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
},
"put":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
},
"remove":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
},
"purge_all":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
},
"remove_if":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
},
"update":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
}
},
"overall":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
},
"startup":"2014-01-20T15:01:11",
"timestamp":"2014-01-20T15:09:40"
}
QuasardbException - if the connection with the current instance fail.public String getNodeStatus(String node, int port) throws QuasardbException
{
"engine_build_date":"87f8d02 2014-01-15 16:12:30 +0100",
"engine_version":"master",
"entries":
{
"persisted":{"count":0,"size":0},
"resident":{"count":0,"size":0}
},
"hardware_concurrency":6,
"memory":
{
"physmem":{"total":25767272448,"used":5493329920},
"vm":{"total":8796092891136,
"used":417980416}
},
"network":{
"listening_address":"127.0.0.1",
"listening_port":2836,
"partitions":
{
"available_sessions":[1999,1999,2000,2000,2000],
"count":5,
"max_sessions":2000
}
},
"node_id":"5309f39a3f176b9-179cd55bd9dc83e5-c09beea926e4bb75-a460c8c4e5487da9",
"operating_system":"Microsoft Windows 7 Ultimate Edition Service Pack 1 (build 7601), 64-bit",
"operations":
{
"compare_and_swap":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
},
"find":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
},
"find_remove":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
},
"find_update":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
},
"put":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
},
"remove":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
},
"purge_all":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
},
"remove_if":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
},
"update":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
}
},
"overall":{
"count":0,
"evictions":0,
"failures":0,
"in_bytes":0,
"out_bytes":0,
"pageins":0,
"successes":0
},
"startup":"2014-01-20T15:01:11",
"timestamp":"2014-01-20T15:09:40"
}
node - the host of the quasardb node you want to retrieve statusport - the port of the quasardb node you want to retrieve statusQuasardbException - if the connection with the current instance fail.public String getCurrentNodeConfig() throws QuasardbException
{
"global":{
"depot":{
"replication_factor":1,
"root":"db",
"sync":false,
"transient":false
},
"limiter":{
"max_bytes":12883636224,
"max_in_entries_count":100000
}
},
"local":{
"chord":{
"bootstrapping_peers":[],
"no_stabilization":false,
"node_id":"5309f39a3f176b9-179cd55bd9dc83e5-c09beea926e4bb75-a460c8c4e5487da9"
},
"logger":{
"dump_file":"qdb_error_dump.txt",
"flush_interval":3,
"log_files":[],
"log_level":2,
"log_to_console":true,
"log_to_syslog":false
},
"network":{
"client_timeout":60,
"idle_timeout":300,
"listen_on":"127.0.0.1:2836",
"partitions_count":5,
"server_sessions":2000
},
"user":{
"license_file":"qdb.lic"
}
}
}
QuasardbException - if the connection with the current instance fail.public String getNodeConfig(String node, int port) throws QuasardbException
{
"global":{
"depot":{
"replication_factor":1,
"root":"db",
"sync":false,
"transient":false
},
"limiter":{
"max_bytes":12883636224,
"max_in_entries_count":100000
}
},
"local":{
"chord":{
"bootstrapping_peers":[],
"no_stabilization":false,
"node_id":"5309f39a3f176b9-179cd55bd9dc83e5-c09beea926e4bb75-a460c8c4e5487da9"
},
"logger":{
"dump_file":"qdb_error_dump.txt",
"flush_interval":3,
"log_files":[],
"log_level":2,
"log_to_console":true,
"log_to_syslog":false
},
"network":{
"client_timeout":60,
"idle_timeout":300,
"listen_on":"127.0.0.1:2836",
"partitions_count":5,
"server_sessions":2000
},
"user":{
"license_file":"qdb.lic"
}
}
}
node - the host of the quasardb node you want to retrieve configurationport - the port of the quasardb node you want to retrieve configurationQuasardbException - if the connection with the current instance fail.public String getCurrentNodeTopology() throws QuasardbException
{
"center":{
"endpoint":"127.0.0.1:2836",
"reference":"5309f39a3f176b9-179cd55bd9dc83e5-c09beea926e4bb75-a460c8c4e5487da9"
},
"predecessor":{
"endpoint":"127.0.0.1:2836",
"reference":"5309f39a3f176b9-179cd55bd9dc83e5-c09beea926e4bb75-a460c8c4e5487da9"
},
"successor":{
"endpoint":"127.0.0.1:2836",
"reference":"5309f39a3f176b9-179cd55bd9dc83e5-c09beea926e4bb75-a460c8c4e5487da9"
}
}
QuasardbException - if the connection with the current instance fail.public String getNodeTopology(String node, int port) throws QuasardbException
{
"center":{
"endpoint":"127.0.0.1:2836",
"reference":"5309f39a3f176b9-179cd55bd9dc83e5-c09beea926e4bb75-a460c8c4e5487da9"
},
"predecessor":{
"endpoint":"127.0.0.1:2836",
"reference":"5309f39a3f176b9-179cd55bd9dc83e5-c09beea926e4bb75-a460c8c4e5487da9"
},
"successor":{
"endpoint":"127.0.0.1:2836",
"reference":"5309f39a3f176b9-179cd55bd9dc83e5-c09beea926e4bb75-a460c8c4e5487da9"
}
}
node - the host of the quasardb node you want to retrieve topologyport - the port of the quasardb node you want to retrieve topologyQuasardbException - if the connection with the current instance fail.public long getExpiryTimeInSeconds(String alias) throws QuasardbException
alias - the object's unique key/alias.QuasardbException - if the connection with current instance fail or provided alias doesn't exist or prodived alias is reserved.public Date getExpiryTimeInDate(String alias) throws QuasardbException
alias - the object's unique key/alias.QuasardbException - if the connection with current instance fail or provided alias doesn't exist or prodived alias is reserved.public void setExpiryTimeInSeconds(String alias, long expiryTime) throws QuasardbException
alias - the object's unique key/alias.expiryTime - the expiry time in second related to the provided alias (0 means eternal)QuasardbException - if the connection with current instance fail or provided alias doesn't exist or a negative expiryTime is provided or prodived alias is reserved.public void setExpiryTimeAt(String alias, Date expiryDate) throws QuasardbException
alias - the object's unique key/alias.expiryDate - the expiry date related to the provided alias.QuasardbException - if the connection with current instance fail, provided alias does not exist or is reservedpublic long getDefaultExpiryTimeInSeconds()
public void setDefaultExpiryTimeInSeconds(long expiryTime)
throws QuasardbException
expiryTime - expiry time in seconds to set upQuasardbException - if a negative expiryTime is providedpublic void stopCurrentNode(String reason) throws QuasardbException
reason - the reason to stop the selected node.QuasardbExceptionpublic void stopNode(String node, int port, String reason) throws QuasardbException
node - the host of the quasardb node you want to stop - can be a IP address or a hostname.port - the port of the quasardb node you want to stop.reason - the reason to stop the selected node.QuasardbExceptionpublic <V> V get(String alias) throws QuasardbException
alias - the object's unique key/alias.QuasardbException - if an error occurs, the entry does not exist or the entry starts with "qdb".public <V> V getRemove(String alias) throws QuasardbException
alias - the object's unique key/alias.QuasardbException - if an error occurs, the entry does not exist or the entry starts with "qdb".public <V> void put(String alias, V value) throws QuasardbException
alias - a key to uniquely identify the entry within the cluster.value - object to associate to the key.QuasardbException - if an error occurs, the entry already exists or the entry starts with "qdb".public <V> void put(String alias, V value, long expiryTime) throws QuasardbException
alias - a key to uniquely identify the entry within the cluster.value - object to associate to the key.expiryTime - expiry time in seconds associate to the key. The provided value is prior to the default expiry time.QuasardbException - if an error occurs (for example : lost session) or the entry already exists or the entry is reserved (it starts with "qdb").public <V> boolean update(String alias, V value) throws QuasardbException
alias - a key to uniquely identify the entry within the cluster.value - the new object to associate to the keyQuasardbException - if an error occurs (for example : lost session) or provided alias is reserved (it starts with "qdb").public <V> boolean update(String alias, V value, long expiryTime) throws QuasardbException
alias - a key to uniquely identify the entry within the cluster.value - the new object to associate to the keyexpiryTime - expiry time in seconds associate to the key. The provided value is prior to the default expiry time.QuasardbException - if an error occurs (for example : lost session) or provided alias is reserved (it starts with "qdb").public <V> V getAndReplace(String alias, V value) throws QuasardbException
alias - a key to uniquely identify the entry within the clustervalue - the new object to associate to the keyQuasardbException - if an error occurs (for example : lost session) or provided alias is reserved (it starts with "qdb").public <V> V getAndReplace(String alias, V value, long expiryTime) throws QuasardbException
alias - a key to uniquely identify the entry within the clustervalue - the new object to associate to the keyexpiryTime - expiry time in seconds associate to the key. The provided value is prior to the default expiry time.QuasardbException - if an error occurs (for example : lost session) or provided alias is reserved (it starts with "qdb").public <V> V compareAndSwap(String alias, V value, V comparand) throws QuasardbException
alias - a key to uniquely identify the entry within the clustervalue - the new object to associate to the keycomparand - the object to compare with original value associated to the keyQuasardbException - if an error occurs (for example : lost session) or provided alias is reserved (it starts with "qdb").public <V> V compareAndSwap(String alias, V value, V comparand, long expiryTime) throws QuasardbException
alias - a key to uniquely identify the entry within the clustervalue - the new object to associate to the keycomparand - the object to compare with original value associated to the keyexpiryTime - expiry time in seconds associate to the key. The provided value is prior to the default expiry time.QuasardbException - if an error occurs (for example : lost session) or provided alias is reserved (it starts with "qdb").public boolean remove(String alias) throws QuasardbException
alias - the alias you want to delete.QuasardbException - if the connection with the current instance fail or provided alias is reserved (it starts with "qdb").public void purgeAll()
throws QuasardbException
QuasardbException - if the connection with the current instance fail.public <V> boolean removeIf(String alias, V comparand) throws QuasardbException
alias - the alias you want to deletecomparand - the object you want to compare withQuasardbException - if the connection with the current instance fail or provided alias is reserved (it starts with "qdb").public <V> Results runBatch(List<Operation<V>> operations) throws QuasardbException
operations - List of operations to submit in batch mode to Quasardb. See OperationResultsQuasardbExceptionpublic List<String> startsWith(String prefix) throws QuasardbException
prefix - prefixQuasardbException - if an error occurs (for example : lost session) or provided prefix is reserved.public void close()
throws QuasardbException
QuasardbException - if the connection to the quasardb instance cannot be closedpublic final QuasardbConfig getConfig()
QuasardbException - if the connection to the quasardb instance cannot be closedQuasardbConfigpublic void setConfig(QuasardbConfig config)
config - configuration propertiesQuasardbException - if the connection to the quasardb instance cannot be closedQuasardbConfigpublic Iterator<QuasardbEntry<?>> iterator()
Iterable for QuasardbEntry, providing support for simplified iteration.
However iteration should be used with caution. It is an O(n) operation.iterator in interface Iterable<QuasardbEntry<?>>Iterable.iterator()Copyright © 2015 quasardb. All Rights Reserved.