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();
}
}
}
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();
}
}
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;
}
}
Aggregations