use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class NettyCommand method executeCommand.
private void executeCommand(long deadline, int tstate) {
state = AsyncCommand.CHANNEL_INIT;
iteration++;
try {
node = command.getNode(cluster);
node.validateErrorCount();
conn = (NettyConnection) node.getAsyncConnection(eventState.index, null);
if (conn != null) {
setTimeoutTask(deadline, tstate);
InboundHandler handler = (InboundHandler) conn.channel.pipeline().last();
handler.setCommand(this);
writeCommand();
return;
}
connectInProgress = true;
if (command.policy.connectTimeout > 0) {
timeoutState = new TimeoutState(deadline, tstate);
deadline = timeoutState.start + TimeUnit.MILLISECONDS.toNanos(command.policy.connectTimeout);
timeoutTask.cancel();
eventLoop.timer.addTimeout(timeoutTask, deadline);
} else {
setTimeoutTask(deadline, tstate);
}
final InboundHandler handler = new InboundHandler(this);
Bootstrap b = new Bootstrap();
initBootstrap(b, cluster, eventLoop);
b.handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) {
if (state != AsyncCommand.CHANNEL_INIT) {
// Timeout occurred. Close channel.
try {
ch.close();
} catch (Throwable e) {
}
connectInProgress = false;
return;
}
state = AsyncCommand.CONNECT;
conn = new NettyConnection(ch);
node.connectionOpened(eventLoop.index);
connectInProgress = false;
ChannelPipeline p = ch.pipeline();
if (cluster.tlsPolicy != null && !cluster.tlsPolicy.forLoginOnly) {
state = AsyncCommand.TLS_HANDSHAKE;
cluster.nettyTlsContext.addHandler(ch, p);
}
p.addLast(handler);
}
});
b.connect(node.getAddress());
eventState.errors = 0;
} catch (AerospikeException.Connection ac) {
eventState.errors++;
onNetworkError(ac);
} catch (AerospikeException.Backoff ab) {
eventState.errors++;
onBackoffError(ab);
} catch (AerospikeException ae) {
// Fail without retry on non-connection errors.
eventState.errors++;
onFatalError(ae);
} catch (Throwable e) {
// Fail without retry on unknown errors.
eventState.errors++;
onFatalError(new AerospikeException(e));
}
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class NodeValidator method setAddress.
private void setAddress(Cluster cluster, HashMap<String, String> map, String addressCommand, String tlsName) {
String result = map.get(addressCommand);
if (result == null || result.length() == 0) {
// Load balancer detection is not possible.
return;
}
List<Host> hosts = Host.parseServiceHosts(result);
Host h;
// Search real hosts for seed.
for (Host host : hosts) {
h = host;
if (cluster.ipMap != null) {
String alt = cluster.ipMap.get(h.name);
if (alt != null) {
h = new Host(alt, h.port);
}
}
if (h.equals(this.primaryHost)) {
// Found seed which is not a load balancer.
return;
}
}
// Find first valid real host.
for (Host host : hosts) {
try {
h = host;
if (cluster.ipMap != null) {
String alt = cluster.ipMap.get(h.name);
if (alt != null) {
h = new Host(alt, h.port);
}
}
InetAddress[] addresses = InetAddress.getAllByName(h.name);
for (InetAddress address : addresses) {
try {
InetSocketAddress socketAddress = new InetSocketAddress(address, h.port);
Connection conn = (cluster.tlsPolicy != null) ? new Connection(cluster.tlsPolicy, tlsName, socketAddress, cluster.connectTimeout) : new Connection(socketAddress, cluster.connectTimeout);
try {
if (this.sessionToken != null) {
if (!AdminCommand.authenticate(cluster, conn, this.sessionToken)) {
throw new AerospikeException("Authentication failed");
}
}
// Authenticated connection. Set real host.
setAliases(address, tlsName, h.port);
this.primaryHost = new Host(address.getHostAddress(), tlsName, h.port);
this.primaryAddress = socketAddress;
this.primaryConn.close();
this.primaryConn = conn;
return;
} catch (Exception e) {
conn.close();
}
} catch (Exception e) {
// Try next address.
}
}
} catch (Exception e) {
// Try next host.
}
}
// with original seed.
if (Log.infoEnabled()) {
Log.info("Invalid address " + result + ". access-address is probably not configured on server.");
}
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class AsyncQuery method parseRow.
@Override
protected void parseRow(Key key) throws AerospikeException {
if (resultCode != 0) {
throw new AerospikeException(resultCode);
}
Record record = parseRecord();
listener.onRecord(key, record);
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class AsyncRead method handleUdfError.
private final void handleUdfError(int resultCode) {
String ret = (String) record.bins.get("FAILURE");
if (ret == null) {
throw new AerospikeException(resultCode);
}
String message;
int code;
try {
String[] list = ret.split(":");
code = Integer.parseInt(list[2].trim());
message = list[0] + ':' + list[1] + ' ' + list[3];
} catch (Exception e) {
// Use generic exception if parse error occurs.
throw new AerospikeException(resultCode, ret);
}
throw new AerospikeException(code, message);
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class AsyncScanPartition method parseRow.
@Override
protected void parseRow(Key key) {
if ((info3 & Command.INFO3_PARTITION_DONE) != 0) {
// specified partition will need to be requested on the scan retry.
if (resultCode == 0) {
tracker.partitionDone(nodePartitions, generation);
}
return;
}
if (resultCode != 0) {
throw new AerospikeException(resultCode);
}
Record record = parseRecord();
listener.onRecord(key, record);
tracker.setDigest(nodePartitions, key);
}
Aggregations