Search in sources :

Example 1 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 2 with AerospikeClient

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());
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Bin(com.aerospike.client.Bin) ArrayList(java.util.ArrayList) TreeSet(java.util.TreeSet) Record(com.aerospike.client.Record) Key(com.aerospike.client.Key)

Example 3 with AerospikeClient

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);
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) ClientPolicy(com.aerospike.client.policy.ClientPolicy) GoraException(org.apache.gora.util.GoraException) AerospikeException(com.aerospike.client.AerospikeException) GoraException(org.apache.gora.util.GoraException) IOException(java.io.IOException)

Example 4 with AerospikeClient

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();
        }
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) IOUringEventLoopGroup(io.netty.incubator.channel.uring.IOUringEventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) KQueueEventLoopGroup(io.netty.channel.kqueue.KQueueEventLoopGroup) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) NettyEventLoops(com.aerospike.client.async.NettyEventLoops) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) KQueueEventLoopGroup(io.netty.channel.kqueue.KQueueEventLoopGroup) EventPolicy(com.aerospike.client.async.EventPolicy) NioEventLoops(com.aerospike.client.async.NioEventLoops) IOUringEventLoopGroup(io.netty.incubator.channel.uring.IOUringEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 5 with AerospikeClient

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();
    }
}
Also used : AerospikeClient(com.aerospike.client.AerospikeClient) ClientPolicy(com.aerospike.client.policy.ClientPolicy) NioEventLoops(com.aerospike.client.async.NioEventLoops) EventLoops(com.aerospike.client.async.EventLoops) NettyEventLoops(com.aerospike.client.async.NettyEventLoops) EventPolicy(com.aerospike.client.async.EventPolicy) Host(com.aerospike.client.Host) NioEventLoops(com.aerospike.client.async.NioEventLoops) IOUringEventLoopGroup(io.netty.incubator.channel.uring.IOUringEventLoopGroup) EventLoopGroup(io.netty.channel.EventLoopGroup) IOUringEventLoopGroup(io.netty.incubator.channel.uring.IOUringEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) KQueueEventLoopGroup(io.netty.channel.kqueue.KQueueEventLoopGroup) EventLoop(com.aerospike.client.async.EventLoop) NettyEventLoops(com.aerospike.client.async.NettyEventLoops) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) KQueueEventLoopGroup(io.netty.channel.kqueue.KQueueEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

AerospikeClient (com.aerospike.client.AerospikeClient)16 AerospikeException (com.aerospike.client.AerospikeException)7 ClientPolicy (com.aerospike.client.policy.ClientPolicy)6 Host (com.aerospike.client.Host)4 Key (com.aerospike.client.Key)4 RecordSet (com.aerospike.client.query.RecordSet)4 Statement (com.aerospike.client.query.Statement)4 Record (com.aerospike.client.Record)3 EventPolicy (com.aerospike.client.async.EventPolicy)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 KQueueEventLoopGroup (io.netty.channel.kqueue.KQueueEventLoopGroup)3 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)3 IOUringEventLoopGroup (io.netty.incubator.channel.uring.IOUringEventLoopGroup)3 Bin (com.aerospike.client.Bin)2 Args (com.aerospike.test.util.Args)2 IOException (java.io.IOException)2 BeforeClass (org.junit.BeforeClass)2