use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class NettyEventLoops method initTlsContext.
/**
* Initialize TLS context. For internal use only.
*/
public void initTlsContext(TlsPolicy policy) {
if (this.tlsPolicy != null) {
// Already initialized.
return;
}
this.tlsPolicy = policy;
if (policy.context != null) {
// I assume the real protocol used is defined by SSLContext.getProtocol().
if (policy.ciphers == null) {
sslContext = new JdkSslContext(policy.context, true, ClientAuth.NONE);
} else {
// Ciphers are filtered in filterCipherSuites().
// Use null for ApplicationProtocolConfig argument.
sslContext = new JdkSslContext(policy.context, true, null, this, null, ClientAuth.NONE);
}
return;
}
try {
SslContextBuilder builder = SslContextBuilder.forClient();
if (policy.protocols != null) {
builder.protocols(policy.protocols);
}
if (policy.ciphers != null) {
builder.ciphers(Arrays.asList(policy.ciphers));
}
sslContext = builder.build();
} catch (Exception e) {
throw new AerospikeException("Failed to init netty TLS: " + Util.getErrorMessage(e));
}
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class NioCommand method executeCommand.
protected final void executeCommand() {
state = AsyncCommand.CONNECT;
try {
Node node = command.getNode(cluster);
byteBuffer = eventLoop.getByteBuffer();
conn = (NioConnection) node.getAsyncConnection(eventLoop.index, byteBuffer);
if (conn != null) {
conn.attach(this);
writeCommand();
return;
}
try {
conn = new NioConnection(node.getAddress(), cluster.maxSocketIdleNanos);
} catch (Exception e) {
node.decrAsyncConnection(eventLoop.index);
throw e;
}
state = (cluster.getUser() != null) ? AsyncCommand.AUTH_WRITE : AsyncCommand.COMMAND_WRITE;
conn.registerConnect(this);
eventState.errors = 0;
} catch (AerospikeException.Connection ac) {
eventState.errors++;
onNetworkError(ac, true);
} catch (IOException ioe) {
eventState.errors++;
onNetworkError(new AerospikeException(ioe), true);
} catch (Exception e) {
// Fail without retry on unknown errors.
eventState.errors++;
fail();
notifyFailure(new AerospikeException(e));
tryDelayQueue();
}
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class Node method refresh.
/**
* Request current status from server node.
*/
public final void refresh(Peers peers) {
if (!active) {
return;
}
try {
if (tendConnection.isClosed()) {
tendConnection = new Connection(cluster.tlsPolicy, host.tlsName, address, cluster.getConnectionTimeout(), cluster.maxSocketIdleNanos, null);
if (cluster.user != null) {
try {
AdminCommand command = new AdminCommand(ThreadLocalData.getBuffer());
command.authenticate(cluster, this, tendConnection);
} catch (AerospikeException ae) {
tendConnection.close();
throw ae;
} catch (Exception e) {
tendConnection.close();
throw new AerospikeException(e);
}
}
}
if (peers.usePeers) {
HashMap<String, String> infoMap = Info.request(tendConnection, "node", "peers-generation", "partition-generation");
verifyNodeName(infoMap);
verifyPeersGeneration(infoMap, peers);
verifyPartitionGeneration(infoMap);
} else {
String[] commands = cluster.useServicesAlternate ? new String[] { "node", "partition-generation", "services-alternate" } : new String[] { "node", "partition-generation", "services" };
HashMap<String, String> infoMap = Info.request(tendConnection, commands);
verifyNodeName(infoMap);
verifyPartitionGeneration(infoMap);
addFriends(infoMap, peers);
}
peers.refreshCount++;
failures = 0;
} catch (Exception e) {
if (peers.usePeers) {
peers.genChanged = true;
}
refreshFailed(e);
}
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class BatchNode method generateList.
public static List<BatchNode> generateList(Cluster cluster, BatchPolicy policy, List<BatchRead> records) throws AerospikeException {
Node[] nodes = cluster.getNodes();
if (nodes.length == 0) {
throw new AerospikeException(ResultCode.SERVER_NOT_AVAILABLE, "Command failed because cluster is empty.");
}
// Create initial key capacity for each node as average + 25%.
int max = records.size();
int keysPerNode = max / nodes.length;
keysPerNode += keysPerNode >>> 2;
// The minimum key capacity is 10.
if (keysPerNode < 10) {
keysPerNode = 10;
}
// Split keys by server node.
List<BatchNode> batchNodes = new ArrayList<BatchNode>(nodes.length);
for (int i = 0; i < max; i++) {
Partition partition = new Partition(records.get(i).key);
Node node = cluster.getMasterNode(partition);
BatchNode batchNode = findBatchNode(batchNodes, node);
if (batchNode == null) {
batchNodes.add(new BatchNode(node, keysPerNode, i));
} else {
batchNode.addKey(i);
}
}
return batchNodes;
}
use of com.aerospike.client.AerospikeException in project aerospike-client-java by aerospike.
the class BatchNode method generateList.
public static List<BatchNode> generateList(Cluster cluster, BatchPolicy policy, Key[] keys) throws AerospikeException {
Node[] nodes = cluster.getNodes();
if (nodes.length == 0) {
throw new AerospikeException(ResultCode.SERVER_NOT_AVAILABLE, "Command failed because cluster is empty.");
}
// Create initial key capacity for each node as average + 25%.
int keysPerNode = keys.length / nodes.length;
keysPerNode += keysPerNode >>> 2;
// The minimum key capacity is 10.
if (keysPerNode < 10) {
keysPerNode = 10;
}
// Split keys by server node.
List<BatchNode> batchNodes = new ArrayList<BatchNode>(nodes.length);
for (int i = 0; i < keys.length; i++) {
Partition partition = new Partition(keys[i]);
Node node = cluster.getMasterNode(partition);
BatchNode batchNode = findBatchNode(batchNodes, node);
if (batchNode == null) {
batchNodes.add(new BatchNode(node, keysPerNode, i));
} else {
batchNode.addKey(i);
}
}
return batchNodes;
}
Aggregations