/** {@inheritDoc} */ @Override public boolean isValid(int timeout) throws SQLException { ensureNotClosed(); if (timeout < 0) throw new SQLException("Invalid timeout: " + timeout); try { JdbcConnectionValidationTask task = new JdbcConnectionValidationTask(cacheName, nodeId == null ? ignite : null); if (nodeId != null) { ClusterGroup grp = ignite.cluster().forServers().forNodeId(nodeId); if (grp.nodes().isEmpty()) throw new SQLException("Failed to establish connection with node (is it a server node?): " + nodeId); assert grp.nodes().size() == 1; if (grp.node().isDaemon()) throw new SQLException("Failed to establish connection with node (is it a server node?): " + nodeId); return ignite.compute(grp).callAsync(task).get(timeout, SECONDS); } else return task.call(); } catch (IgniteClientDisconnectedException | ComputeTaskTimeoutException e) { throw new SQLException("Failed to establish connection.", SqlStateCode.CONNECTION_FAILURE, e); } catch (IgniteException ignored) { return false; } }
/** {@inheritDoc} */ @Override public boolean isValid(int timeout) throws SQLException { ensureNotClosed(); if (timeout < 0) throw new SQLException("Invalid timeout: " + timeout); try { JdbcConnectionValidationTask task = new JdbcConnectionValidationTask(cacheName, nodeId == null ? ignite : null); if (nodeId != null) { ClusterGroup grp = ignite.cluster().forServers().forNodeId(nodeId); if (grp.nodes().isEmpty()) throw new SQLException("Failed to establish connection with node (is it a server node?): " + nodeId); assert grp.nodes().size() == 1; if (grp.node().isDaemon()) throw new SQLException("Failed to establish connection with node (is it a server node?): " + nodeId); return ignite.compute(grp).callAsync(task).get(timeout, SECONDS); } else return task.call(); } catch (IgniteClientDisconnectedException | ComputeTaskTimeoutException e) { throw new SQLException("Failed to establish connection.", SqlStateCode.CONNECTION_FAILURE, e); } catch (IgniteException ignored) { return false; } }