Search in sources :

Example 1 with EventLoops

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