Search in sources :

Example 1 with PingFailureDetector

use of com.hazelcast.internal.cluster.fd.PingFailureDetector in project hazelcast by hazelcast.

the class ClusterHeartbeatManager method createIcmpFailureDetectorIfNeeded.

private PingFailureDetector createIcmpFailureDetectorIfNeeded() {
    IcmpFailureDetectorConfig icmpFailureDetectorConfig = getActiveMemberNetworkConfig(node.config).getIcmpFailureDetectorConfig();
    boolean icmpEchoFailFast = icmpFailureDetectorConfig == null || icmpFailureDetectorConfig.isFailFastOnStartup();
    if (icmpParallelMode) {
        if (icmpEchoFailFast) {
            logger.info("Checking that ICMP failure-detector is permitted. Attempting to create a raw-socket using JNI.");
            if (!ICMPHelper.isRawSocketPermitted()) {
                throw new IllegalStateException("ICMP failure-detector can't be used in this environment. " + "Check Hazelcast Documentation Chapter on the Ping Failure Detector for supported platforms " + "and how to enable this capability for your operating system");
            }
            logger.info("ICMP failure-detector is supported, enabling.");
        }
        return new PingFailureDetector(icmpMaxAttempts);
    }
    return null;
}
Also used : IcmpFailureDetectorConfig(com.hazelcast.config.IcmpFailureDetectorConfig) PingFailureDetector(com.hazelcast.internal.cluster.fd.PingFailureDetector)

Example 2 with PingFailureDetector

use of com.hazelcast.internal.cluster.fd.PingFailureDetector in project hazelcast by hazelcast.

the class ClientICMPManager method start.

public static void start(ClientIcmpPingConfig clientIcmpPingConfig, TaskScheduler taskScheduler, ILogger logger, Collection<Connection> unmodifiableActiveConnections) {
    if (!clientIcmpPingConfig.isEnabled()) {
        return;
    }
    if (clientIcmpPingConfig.isEchoFailFastOnStartup()) {
        echoFailFast(logger);
    }
    int icmpTtl = clientIcmpPingConfig.getTtl();
    int icmpTimeoutMillis = clientIcmpPingConfig.getTimeoutMilliseconds();
    int icmpIntervalMillis = clientIcmpPingConfig.getIntervalMilliseconds();
    int icmpMaxAttempts = clientIcmpPingConfig.getMaxAttempts();
    if (icmpTimeoutMillis > icmpIntervalMillis) {
        throw new IllegalStateException("ICMP timeout is set to a value greater than the ICMP interval, " + "this is not allowed.");
    }
    if (icmpIntervalMillis < MIN_ICMP_INTERVAL_MILLIS) {
        throw new IllegalStateException("ICMP interval is set to a value less than the min allowed, " + MIN_ICMP_INTERVAL_MILLIS + "ms");
    }
    PingFailureDetector<Connection> failureDetector = new PingFailureDetector<>(icmpMaxAttempts);
    taskScheduler.scheduleWithRepetition(() -> {
        failureDetector.retainAttemptsForAliveEndpoints(unmodifiableActiveConnections);
        for (Connection connection : unmodifiableActiveConnections) {
            // we don't want an isReachable call to an address stopping us to check other addresses.
            // so we run each check in its own thread
            taskScheduler.execute(() -> ping(logger, failureDetector, connection, icmpTtl, icmpTimeoutMillis));
        }
    }, icmpIntervalMillis, icmpIntervalMillis, TimeUnit.MILLISECONDS);
}
Also used : PingFailureDetector(com.hazelcast.internal.cluster.fd.PingFailureDetector) Connection(com.hazelcast.internal.nio.Connection)

Aggregations

PingFailureDetector (com.hazelcast.internal.cluster.fd.PingFailureDetector)2 IcmpFailureDetectorConfig (com.hazelcast.config.IcmpFailureDetectorConfig)1 Connection (com.hazelcast.internal.nio.Connection)1