Search in sources :

Example 1 with TcpDiscoveryClientPingRequest

use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryClientPingRequest in project ignite by apache.

the class ClientImpl method pingNode.

/** {@inheritDoc} */
@Override
public boolean pingNode(@NotNull final UUID nodeId) {
    if (nodeId.equals(getLocalNodeId()))
        return true;
    TcpDiscoveryNode node = rmtNodes.get(nodeId);
    if (node == null || !node.visible())
        return false;
    GridFutureAdapter<Boolean> fut = pingFuts.get(nodeId);
    if (fut == null) {
        fut = new GridFutureAdapter<>();
        GridFutureAdapter<Boolean> oldFut = pingFuts.putIfAbsent(nodeId, fut);
        if (oldFut != null)
            fut = oldFut;
        else {
            State state = this.state;
            if (spi.getSpiContext().isStopping() || state == STOPPED || state == SEGMENTED) {
                if (pingFuts.remove(nodeId, fut))
                    fut.onDone(false);
                return false;
            } else if (state == DISCONNECTED) {
                if (pingFuts.remove(nodeId, fut))
                    fut.onDone(new IgniteClientDisconnectedCheckedException(null, "Failed to ping node, client node disconnected."));
            } else {
                final GridFutureAdapter<Boolean> finalFut = fut;
                timer.schedule(new TimerTask() {

                    @Override
                    public void run() {
                        if (pingFuts.remove(nodeId, finalFut)) {
                            if (ClientImpl.this.state == DISCONNECTED)
                                finalFut.onDone(new IgniteClientDisconnectedCheckedException(null, "Failed to ping node, client node disconnected."));
                            else
                                finalFut.onDone(false);
                        }
                    }
                }, spi.netTimeout);
                sockWriter.sendMessage(new TcpDiscoveryClientPingRequest(getLocalNodeId(), nodeId));
            }
        }
    }
    try {
        return fut.get();
    } catch (IgniteInterruptedCheckedException ignored) {
        return false;
    } catch (IgniteCheckedException e) {
        throw new IgniteSpiException(e);
    }
}
Also used : TcpDiscoveryClientPingRequest(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryClientPingRequest) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TimerTask(java.util.TimerTask) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)

Aggregations

TimerTask (java.util.TimerTask)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)1 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)1 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)1 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)1 TcpDiscoveryNode (org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode)1 TcpDiscoveryClientPingRequest (org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryClientPingRequest)1