All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.hajdbc.state.health.observer.PingObserveAdapter Maven / Gradle / Ivy

There is a newer version: 3.6.61
Show newest version
package net.sf.hajdbc.state.health.observer;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Observe adapter for ping
 */
public class PingObserveAdapter implements ObserveAdapter {

  public static final int TIME_OUT = 200;

  @Override
  public String getName() {
    return "ping";
  }

  @Override
  public int getWeight() {
    return 100;
  }

  @Override
  public boolean isObservable(String ip) {
    return isHostReachable(ip, TIME_OUT);
  }

  public boolean isHostReachable(String host, Integer timeOut) {
    try {
      return InetAddress.getByName(host).isReachable(timeOut);
    } catch (UnknownHostException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return false;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy