use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class TcpCommunicationSpi method reserveClient.
/**
* Returns existing or just created client to node.
*
* @param node Node to which client should be open.
* @param connIdx Connection index.
* @return The existing or just created client.
* @throws IgniteCheckedException Thrown if any exception occurs.
*/
private GridCommunicationClient reserveClient(ClusterNode node, int connIdx) throws IgniteCheckedException {
assert node != null;
assert (connIdx >= 0 && connIdx < connectionsPerNode) || !usePairedConnections(node) : connIdx;
UUID nodeId = node.id();
while (true) {
GridCommunicationClient[] curClients = clients.get(nodeId);
GridCommunicationClient client = curClients != null && connIdx < curClients.length ? curClients[connIdx] : null;
if (client == null) {
if (stopping)
throw new IgniteSpiException("Node is stopping.");
// Do not allow concurrent connects.
GridFutureAdapter<GridCommunicationClient> fut = new ConnectFuture();
ConnectionKey connKey = new ConnectionKey(nodeId, connIdx, -1);
GridFutureAdapter<GridCommunicationClient> oldFut = clientFuts.putIfAbsent(connKey, fut);
if (oldFut == null) {
try {
GridCommunicationClient[] curClients0 = clients.get(nodeId);
GridCommunicationClient client0 = curClients0 != null && connIdx < curClients0.length ? curClients0[connIdx] : null;
if (client0 == null) {
client0 = createNioClient(node, connIdx);
if (client0 != null) {
addNodeClient(node, connIdx, client0);
if (client0 instanceof GridTcpNioCommunicationClient) {
GridTcpNioCommunicationClient tcpClient = ((GridTcpNioCommunicationClient) client0);
if (tcpClient.session().closeTime() > 0 && removeNodeClient(nodeId, client0)) {
if (log.isDebugEnabled())
log.debug("Session was closed after client creation, will retry " + "[node=" + node + ", client=" + client0 + ']');
client0 = null;
}
}
} else {
U.sleep(200);
if (getSpiContext().node(node.id()) == null)
throw new ClusterTopologyCheckedException("Failed to send message " + "(node left topology): " + node);
}
}
fut.onDone(client0);
} catch (Throwable e) {
fut.onDone(e);
if (e instanceof Error)
throw (Error) e;
} finally {
clientFuts.remove(connKey, fut);
}
} else
fut = oldFut;
client = fut.get();
if (client == null)
continue;
if (getSpiContext().node(nodeId) == null) {
if (removeNodeClient(nodeId, client))
client.forceClose();
throw new IgniteSpiException("Destination node is not in topology: " + node.id());
}
}
assert connIdx == client.connectionIndex() : client;
if (client.reserve())
return client;
else
// Client has just been closed by idle worker. Help it and try again.
removeNodeClient(nodeId, client);
}
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class TcpDiscoveryGoogleStorageIpFinder method addrFromString.
/**
* Constructs a node address from bucket's key.
*
* @param key Bucket key.
* @return Node address.
* @throws IgniteSpiException In case of error.
*/
private InetSocketAddress addrFromString(String key) throws IgniteSpiException {
String[] res = key.split("#");
if (res.length != 2)
throw new IgniteSpiException("Invalid address string: " + key);
int port;
try {
port = Integer.parseInt(res[1]);
} catch (NumberFormatException ignored) {
throw new IgniteSpiException("Invalid port number: " + res[1]);
}
return new InetSocketAddress(res[0], port);
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class TcpDiscoveryGoogleStorageIpFinder method removeBucket.
/**
* Used by TEST SUITES only. Called through reflection.
*
* @param bucketName Bucket to delete.
*/
private void removeBucket(String bucketName) {
init();
try {
Storage.Buckets.Delete deleteBucket = storage.buckets().delete(bucketName);
deleteBucket.execute();
} catch (Exception e) {
throw new IgniteSpiException("Failed to remove the bucket: " + bucketName, e);
}
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class TcpDiscoveryGoogleStorageIpFinder method registerAddresses.
/**
* {@inheritDoc}
*/
@Override
public void registerAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
assert !F.isEmpty(addrs);
init();
for (InetSocketAddress addr : addrs) {
String key = keyFromAddr(addr);
StorageObject object = new StorageObject();
object.setBucket(bucketName);
object.setName(key);
InputStreamContent content = new InputStreamContent("application/octet-stream", OBJECT_CONTENT);
content.setLength(OBJECT_CONTENT.available());
try {
Storage.Objects.Insert insertObject = storage.objects().insert(bucketName, object, content);
insertObject.execute();
} catch (Exception e) {
throw new IgniteSpiException("Failed to put entry [bucketName=" + bucketName + ", entry=" + key + ']', e);
}
}
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class S3CheckpointSpi method saveCheckpoint.
/**
* {@inheritDoc}
*/
@Override
public boolean saveCheckpoint(String key, byte[] state, long timeout, boolean overwrite) throws IgniteSpiException {
assert !F.isEmpty(key);
long expireTime = 0;
if (timeout > 0) {
expireTime = U.currentTimeMillis() + timeout;
if (expireTime < 0)
expireTime = Long.MAX_VALUE;
}
try {
if (hasKey(key)) {
if (!overwrite)
return false;
if (log.isDebugEnabled())
log.debug("Overriding existing key: " + key);
}
S3CheckpointData data = new S3CheckpointData(state, expireTime, key);
write(data);
} catch (AmazonClientException e) {
throw new IgniteSpiException("Failed to write checkpoint data [key=" + key + ", state=" + Arrays.toString(state) + ']', e);
} catch (IgniteCheckedException e) {
throw new IgniteSpiException("Failed to marshal checkpoint data [key=" + key + ", state=" + Arrays.toString(state) + ']', e);
}
if (timeout > 0)
timeoutWrk.add(new S3TimeData(expireTime, key));
return true;
}
Aggregations