use of java.net.SocketException in project hadoop by apache.
the class DNS method getIPs.
/**
* Returns all the IPs associated with the provided interface, if any, in
* textual form.
*
* @param strInterface
* The name of the network interface or sub-interface to query
* (eg eth0 or eth0:0) or the string "default"
* @param returnSubinterfaces
* Whether to return IPs associated with subinterfaces of
* the given interface
* @return A string vector of all the IPs associated with the provided
* interface. The local host IP is returned if the interface
* name "default" is specified or there is an I/O error looking
* for the given interface.
* @throws UnknownHostException
* If the given interface is invalid
*
*/
public static String[] getIPs(String strInterface, boolean returnSubinterfaces) throws UnknownHostException {
if ("default".equals(strInterface)) {
return new String[] { cachedHostAddress };
}
NetworkInterface netIf;
try {
netIf = NetworkInterface.getByName(strInterface);
if (netIf == null) {
netIf = getSubinterface(strInterface);
}
} catch (SocketException e) {
LOG.warn("I/O error finding interface " + strInterface + ": " + e.getMessage());
return new String[] { cachedHostAddress };
}
if (netIf == null) {
throw new UnknownHostException("No such interface " + strInterface);
}
// NB: Using a LinkedHashSet to preserve the order for callers
// that depend on a particular element being 1st in the array.
// For example, getDefaultIP always returns the first element.
LinkedHashSet<InetAddress> allAddrs = new LinkedHashSet<InetAddress>();
allAddrs.addAll(Collections.list(netIf.getInetAddresses()));
if (!returnSubinterfaces) {
allAddrs.removeAll(getSubinterfaceInetAddrs(netIf));
}
String[] ips = new String[allAddrs.size()];
int i = 0;
for (InetAddress addr : allAddrs) {
ips[i++] = addr.getHostAddress();
}
return ips;
}
use of java.net.SocketException in project hadoop by apache.
the class Server method bind.
public static void bind(ServerSocket socket, InetSocketAddress address, int backlog, Configuration conf, String rangeConf) throws IOException {
try {
IntegerRanges range = null;
if (rangeConf != null) {
range = conf.getRange(rangeConf, "");
}
if (range == null || range.isEmpty() || (address.getPort() != 0)) {
socket.bind(address, backlog);
} else {
for (Integer port : range) {
if (socket.isBound())
break;
try {
InetSocketAddress temp = new InetSocketAddress(address.getAddress(), port);
socket.bind(temp, backlog);
} catch (BindException e) {
//Ignored
}
}
if (!socket.isBound()) {
throw new BindException("Could not find a free port in " + range);
}
}
} catch (SocketException e) {
throw NetUtils.wrapException(null, 0, address.getHostName(), address.getPort(), e);
}
}
use of java.net.SocketException in project hadoop by apache.
the class PrivilegedNfsGatewayStarter method init.
@Override
public void init(DaemonContext context) throws Exception {
System.err.println("Initializing privileged NFS client socket...");
NfsConfiguration conf = new NfsConfiguration();
int clientPort = conf.getInt(NfsConfigKeys.DFS_NFS_REGISTRATION_PORT_KEY, NfsConfigKeys.DFS_NFS_REGISTRATION_PORT_DEFAULT);
if (clientPort < 1 || clientPort > 1023) {
throw new RuntimeException("Must start privileged NFS server with '" + NfsConfigKeys.DFS_NFS_REGISTRATION_PORT_KEY + "' configured to a " + "privileged port.");
}
try {
InetSocketAddress socketAddress = new InetSocketAddress("localhost", clientPort);
registrationSocket = new DatagramSocket(null);
registrationSocket.setReuseAddress(true);
registrationSocket.bind(socketAddress);
} catch (SocketException e) {
LOG.error("Init failed for port=" + clientPort, e);
throw e;
}
args = context.getArguments();
}
use of java.net.SocketException in project pinpoint by naver.
the class UDPReceiver method bindSocket.
private void bindSocket(DatagramSocket socket, String bindAddress, int port) {
if (socket == null) {
throw new NullPointerException("socket must not be null");
}
try {
logger.info("DatagramSocket.bind() {}/{}", bindAddress, port);
socket.bind(new InetSocketAddress(bindAddress, port));
} catch (SocketException ex) {
throw new IllegalStateException("Socket bind Fail. port:" + port + " Caused:" + ex.getMessage(), ex);
}
}
use of java.net.SocketException in project pinpoint by naver.
the class TestUDPReceiver method createSocket.
private DatagramSocket createSocket(int receiveBufferSize) {
try {
DatagramSocket socket = new DatagramSocket(null);
socket.setReceiveBufferSize(receiveBufferSize);
if (logger.isWarnEnabled()) {
final int checkReceiveBufferSize = socket.getReceiveBufferSize();
if (receiveBufferSize != checkReceiveBufferSize) {
logger.warn("DatagramSocket.setReceiveBufferSize() error. {}!={}", receiveBufferSize, checkReceiveBufferSize);
}
}
socket.setSoTimeout(1000 * 5);
return socket;
} catch (SocketException ex) {
throw new RuntimeException("Socket create Fail. Caused:" + ex.getMessage(), ex);
}
}
Aggregations