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