blob: 25f286501e5f04f42408852f940db5b52882123c [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.preferences.ui.utils;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class CheckStateServerName {
public static String doCheckState(String servername, int timeoutMilliSecs) {
try {
InetAddress address = InetAddress.getByName(servername);
// System.out.println("Name: " + address.getHostName());
// System.out.println("Addr: " + address.getHostAddress());
// System.out.println("Reach: " + address.isReachable(3000));
if (!address.isReachable(timeoutMilliSecs)) {
return servername+" not reachable in "+timeoutMilliSecs+" milliseconds";
}
return null;
}
catch (UnknownHostException e) {
return "Unable to lookup "+servername;
}
catch (IOException e) {
return "Unable to reach "+servername;
}
}
}