Search in sources :

Example 6 with AerospikeClient

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);
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key)

Example 7 with AerospikeClient

use of com.aerospike.client.AerospikeClient in project aerospike-client-java by aerospike.

the class SuiteAsync method init.

@BeforeClass
public static void init() {
    System.out.println("Begin AerospikeClient");
    Args args = Args.Instance;
    switch(args.eventLoopType) {
        default:
        case DIRECT_NIO:
            {
                eventLoops = new NioEventLoops(1);
                break;
            }
        case NETTY_NIO:
            {
                EventLoopGroup group = new NioEventLoopGroup(1);
                eventLoops = new NettyEventLoops(group);
                break;
            }
        case NETTY_EPOLL:
            {
                EventLoopGroup group = new EpollEventLoopGroup(1);
                eventLoops = new NettyEventLoops(group);
                break;
            }
    }
    try {
        ClientPolicy policy = new ClientPolicy();
        policy.eventLoops = eventLoops;
        policy.user = args.user;
        policy.password = args.password;
        policy.tlsPolicy = args.tlsPolicy;
        Host[] hosts = Host.parseHosts(args.host, args.port);
        eventLoop = eventLoops.get(0);
        client = new AerospikeClient(policy, hosts);
        try {
            args.setServerSpecific(client);
        } catch (RuntimeException re) {
            client.close();
            throw re;
        }
    } catch (Exception e) {
        eventLoops.close();
        throw e;
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) Args(com.aerospike.test.util.Args) ClientPolicy(com.aerospike.client.policy.ClientPolicy) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) NettyEventLoops(com.aerospike.client.async.NettyEventLoops) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) Host(com.aerospike.client.Host) NioEventLoops(com.aerospike.client.async.NioEventLoops) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) BeforeClass(org.junit.BeforeClass)

Example 8 with AerospikeClient

use of com.aerospike.client.AerospikeClient in project aerospike-client-java by aerospike.

the class Example method runExamples.

/**
	 * Connect and run one or more client examples.
	 */
public static void runExamples(Console console, Parameters params, List<String> examples) throws Exception {
    ClientPolicy policy = new ClientPolicy();
    policy.user = params.user;
    policy.password = params.password;
    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 {
        params.setServerSpecific(client);
        for (String exampleName : examples) {
            runExample(exampleName, client, params, console);
        }
    } finally {
        client.close();
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) ClientPolicy(com.aerospike.client.policy.ClientPolicy) Host(com.aerospike.client.Host)

Example 9 with AerospikeClient

use of com.aerospike.client.AerospikeClient in project XRTB by benmfaul.

the class Membership method main.

/**
	 * Let's test this mess.
	 * @param args
	 * @throws Exception
	 */
public static void main(String[] args) throws Exception {
    AerospikeClient client = new AerospikeClient("localhost", 3000);
    Membership m = new Membership("c1x-cookies", "/home/ben/Downloads/c1x_cookies.csv", client);
    System.out.println(m.query("9786B01215534DEB9AAC2D5FEE23A497"));
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient)

Example 10 with AerospikeClient

use of com.aerospike.client.AerospikeClient in project XRTB by benmfaul.

the class RedissonClient method set.

/**
	 * Set a key value as string with an expiration (No expiration set on cache2k, it is already set 
	 * @param skey String. The key name.
	 * @param value String. The value.
	 * @param expire int. The number of seconds before expiring.
	 * @throws Exception on aerorpike or cache errors.
	 */
public void set(String skey, String value, int expire) throws Exception {
    if (ae == null) {
        cache.put(skey, value);
        return;
    }
    AerospikeClient client = ae.getClient();
    if (client == null)
        return;
    WritePolicy policy = new WritePolicy();
    policy.expiration = expire;
    Key key = new Key("test", "cache", skey);
    Bin bin1 = new Bin("value", value);
    ae.getClient().put(policy, key, bin1);
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) Bin(com.aerospike.client.Bin) Key(com.aerospike.client.Key) WritePolicy(com.aerospike.client.policy.WritePolicy)

Aggregations

AerospikeClient (com.aerospike.client.AerospikeClient)11 ClientPolicy (com.aerospike.client.policy.ClientPolicy)5 Host (com.aerospike.client.Host)4 Key (com.aerospike.client.Key)4 Record (com.aerospike.client.Record)3 NettyEventLoops (com.aerospike.client.async.NettyEventLoops)3 NioEventLoops (com.aerospike.client.async.NioEventLoops)3 EventLoopGroup (io.netty.channel.EventLoopGroup)3 EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)3 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)3 Bin (com.aerospike.client.Bin)2 Args (com.aerospike.test.util.Args)2 BeforeClass (org.junit.BeforeClass)2 AerospikeException (com.aerospike.client.AerospikeException)1 EventLoop (com.aerospike.client.async.EventLoop)1 EventLoops (com.aerospike.client.async.EventLoops)1 EventPolicy (com.aerospike.client.async.EventPolicy)1 WritePolicy (com.aerospike.client.policy.WritePolicy)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1