Search in sources :

Example 1 with NioEventLoops

use of com.aerospike.client.async.NioEventLoops 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);
                    break;
                }
            case NETTY_EPOLL:
                {
                    EventLoopGroup group = new EpollEventLoopGroup(this.eventLoopSize);
                    eventLoops = new NettyEventLoops(eventPolicy, group);
                    break;
                }
        }
        try {
            clientPolicy.eventLoops = eventLoops;
            if (clientPolicy.maxConnsPerNode < this.asyncMaxCommands) {
                clientPolicy.maxConnsPerNode = 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) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) NettyEventLoops(com.aerospike.client.async.NettyEventLoops) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) EventPolicy(com.aerospike.client.async.EventPolicy) NioEventLoops(com.aerospike.client.async.NioEventLoops) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Example 2 with NioEventLoops

use of com.aerospike.client.async.NioEventLoops 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 {
    EventLoops eventLoops;
    switch(params.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 = 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 {
            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) EventLoopGroup(io.netty.channel.EventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) EventLoop(com.aerospike.client.async.EventLoop) NioEventLoops(com.aerospike.client.async.NioEventLoops) EventLoops(com.aerospike.client.async.EventLoops) NettyEventLoops(com.aerospike.client.async.NettyEventLoops) 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)

Example 3 with NioEventLoops

use of com.aerospike.client.async.NioEventLoops 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)

Aggregations

AerospikeClient (com.aerospike.client.AerospikeClient)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 Host (com.aerospike.client.Host)2 ClientPolicy (com.aerospike.client.policy.ClientPolicy)2 EventLoop (com.aerospike.client.async.EventLoop)1 EventLoops (com.aerospike.client.async.EventLoops)1 EventPolicy (com.aerospike.client.async.EventPolicy)1 Args (com.aerospike.test.util.Args)1 BeforeClass (org.junit.BeforeClass)1