use of com.aerospike.client.AerospikeClient in project XRTB by benmfaul.
the class AeroRange method main.
public static void main(String[] args) throws Exception {
AerospikeClient client = new AerospikeClient(args[0], 3000);
String skey = "accountingsystem";
Key key = new Key("test", "cache", skey);
while (true) {
Record record = null;
record = client.get(null, key);
String value = (String) record.bins.get("value");
System.out.println(value);
Thread.sleep(1000);
}
}
use of com.aerospike.client.AerospikeClient in project XRTB by benmfaul.
the class CookieList method main.
public static void main(String[] args) throws Exception {
int i = 0;
String aero = "localhost:3000";
String setName = null;
String mapName = null;
String op = null;
String name = null;
String file = null;
boolean range = false;
AerospikeClient client = new AerospikeClient("localhost", 3000);
Key key = new Key("test", "database", "rtb4free");
ArrayList<String> list = new ArrayList<String>();
TreeSet set = new TreeSet();
for (i = 0; i < 100000; i++) {
list.add(Integer.toString(i));
set.add(Integer.toString(i));
}
Bin bin1 = new Bin("c1x-cookies", set);
client.put(null, key, bin1);
System.out.println("Done!");
Record record = client.get(null, key);
long time = System.currentTimeMillis();
Set<String> receivedList = (Set<String>) record.getValue("c1x-cookies");
receivedList.contains("99999");
System.out.println(System.currentTimeMillis() - time);
System.out.println("Received List = " + receivedList.size());
}
use of com.aerospike.client.AerospikeClient in project gora by apache.
the class AerospikeStore method initialize.
/**
* {@inheritDoc}
* In initializing the aerospike datastore, read the mapping file, sets the basic
* aerospike specific parameters and creates the client with the user defined policies
*
* @param keyClass key class
* @param persistentClass persistent class
* @param properties properties
*/
@Override
public void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties) throws GoraException {
super.initialize(keyClass, persistentClass, properties);
try {
AerospikeMappingBuilder aerospikeMappingBuilder = new AerospikeMappingBuilder();
aerospikeMappingBuilder.readMappingFile(getConf().get(PARSE_MAPPING_FILE_KEY, DEFAULT_MAPPING_FILE), keyClass, persistentClass);
aerospikeParameters = new AerospikeParameters(aerospikeMappingBuilder.getAerospikeMapping(), properties, getConf());
ClientPolicy policy = new ClientPolicy();
policy.writePolicyDefault = aerospikeParameters.getAerospikeMapping().getWritePolicy();
policy.readPolicyDefault = aerospikeParameters.getAerospikeMapping().getReadPolicy();
// 'SendKey' property is enabled by default as the key is needed in query execution
policy.readPolicyDefault.sendKey = true;
policy.writePolicyDefault.sendKey = true;
// Set the credentials for servers with restricted access
if (aerospikeParameters.getUsername() != null) {
policy.user = aerospikeParameters.getUsername();
}
if (aerospikeParameters.getPassword() != null) {
policy.password = aerospikeParameters.getPassword();
}
aerospikeClient = new AerospikeClient(policy, aerospikeParameters.getHost(), aerospikeParameters.getPort());
aerospikeParameters.setServerSpecificParameters(aerospikeClient);
aerospikeParameters.validateServerBinConfiguration(persistentClass.getFields());
LOG.info("Aerospike Gora datastore initialized successfully.");
} catch (Exception e) {
throw new GoraException(e);
}
}
use of com.aerospike.client.AerospikeClient in project aerospike-client-java by aerospike.
the class Main method runBenchmarks.
public void runBenchmarks() throws Exception {
if (this.asyncEnabled) {
EventPolicy eventPolicy = new EventPolicy();
if (args.readPolicy.socketTimeout > 0 && args.readPolicy.socketTimeout < eventPolicy.minTimeout) {
eventPolicy.minTimeout = args.readPolicy.socketTimeout;
}
if (args.writePolicy.socketTimeout > 0 && args.writePolicy.socketTimeout < eventPolicy.minTimeout) {
eventPolicy.minTimeout = args.writePolicy.socketTimeout;
}
switch(this.eventLoopType) {
default:
case DIRECT_NIO:
{
eventLoops = new NioEventLoops(eventPolicy, this.eventLoopSize);
break;
}
case NETTY_NIO:
{
EventLoopGroup group = new NioEventLoopGroup(this.eventLoopSize);
eventLoops = new NettyEventLoops(eventPolicy, group, this.eventLoopType);
break;
}
case NETTY_EPOLL:
{
EventLoopGroup group = new EpollEventLoopGroup(this.eventLoopSize);
eventLoops = new NettyEventLoops(eventPolicy, group, this.eventLoopType);
break;
}
case NETTY_KQUEUE:
{
EventLoopGroup group = new KQueueEventLoopGroup(this.eventLoopSize);
eventLoops = new NettyEventLoops(eventPolicy, group, this.eventLoopType);
break;
}
case NETTY_IOURING:
{
EventLoopGroup group = new IOUringEventLoopGroup(this.eventLoopSize);
eventLoops = new NettyEventLoops(eventPolicy, group, this.eventLoopType);
break;
}
}
try {
clientPolicy.eventLoops = eventLoops;
if (clientPolicy.asyncMaxConnsPerNode < this.asyncMaxCommands) {
clientPolicy.asyncMaxConnsPerNode = this.asyncMaxCommands;
}
AerospikeClient client = new AerospikeClient(clientPolicy, hosts);
try {
if (initialize) {
doAsyncInserts(client);
} else {
doAsyncRWTest(client);
}
} finally {
client.close();
}
} finally {
eventLoops.close();
}
} else {
AerospikeClient client = new AerospikeClient(clientPolicy, hosts);
try {
if (initialize) {
doInserts(client);
} else {
doRWTest(client);
}
} finally {
client.close();
}
}
}
use of com.aerospike.client.AerospikeClient in project aerospike-client-java by aerospike.
the class AsyncExample method runExamples.
/**
* Connect and run one or more asynchronous client examples.
*/
public static void runExamples(Console console, Parameters params, List<String> examples) throws Exception {
EventPolicy eventPolicy = new EventPolicy();
eventPolicy.maxCommandsInProcess = params.maxCommandsInProcess;
eventPolicy.maxCommandsInQueue = params.maxCommandsInQueue;
EventLoops eventLoops;
switch(params.eventLoopType) {
default:
case DIRECT_NIO:
{
eventLoops = new NioEventLoops(eventPolicy, 1);
break;
}
case NETTY_NIO:
{
EventLoopGroup group = new NioEventLoopGroup(1);
eventLoops = new NettyEventLoops(eventPolicy, group, params.eventLoopType);
break;
}
case NETTY_EPOLL:
{
EventLoopGroup group = new EpollEventLoopGroup(1);
eventLoops = new NettyEventLoops(eventPolicy, group, params.eventLoopType);
break;
}
case NETTY_KQUEUE:
{
EventLoopGroup group = new KQueueEventLoopGroup(1);
eventLoops = new NettyEventLoops(eventPolicy, group, params.eventLoopType);
break;
}
case NETTY_IOURING:
{
EventLoopGroup group = new IOUringEventLoopGroup(1);
eventLoops = new NettyEventLoops(eventPolicy, group, params.eventLoopType);
break;
}
}
try {
ClientPolicy policy = new ClientPolicy();
policy.eventLoops = eventLoops;
policy.user = params.user;
policy.password = params.password;
policy.authMode = params.authMode;
policy.tlsPolicy = params.tlsPolicy;
params.policy = policy.readPolicyDefault;
params.writePolicy = policy.writePolicyDefault;
Host[] hosts = Host.parseHosts(params.host, params.port);
AerospikeClient client = new AerospikeClient(policy, hosts);
try {
EventLoop eventLoop = eventLoops.get(0);
params.setServerSpecific(client);
for (String exampleName : examples) {
runExample(exampleName, client, eventLoop, params, console);
}
} finally {
client.close();
}
} finally {
eventLoops.close();
}
}
Aggregations