本文整理了Java中java.net.BindException.initCause()
方法的一些代码示例,展示了BindException.initCause()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BindException.initCause()
方法的具体详情如下:
包路径:java.net.BindException
类名称:BindException
方法名:initCause
暂无
代码示例来源:origin: jenkinsci/jenkins
/**
* @param port
* Use 0 to choose a random port.
*/
public TcpSlaveAgentListener(int port) throws IOException {
super("TCP agent listener port="+port);
try {
serverSocket = ServerSocketChannel.open();
serverSocket.socket().bind(new InetSocketAddress(port));
} catch (BindException e) {
throw (BindException)new BindException("Failed to listen on port "+port+" because it's already in use.").initCause(e);
}
this.configuredPort = port;
setUncaughtExceptionHandler((t, e) -> {
LOGGER.log(Level.SEVERE, "Uncaught exception in TcpSlaveAgentListener " + t + ", attempting to reschedule thread", e);
shutdown();
TcpSlaveAgentListenerRescheduler.schedule(t, e);
});
LOGGER.log(Level.FINE, "TCP agent listener started on port {0}", getPort());
start();
}
代码示例来源:origin: apache/hbase
/**
* A convenience method to bind to a given address and report
* better exceptions if the address is not a valid host.
* @param socket the socket to bind
* @param address the address to bind to
* @param backlog the number of connections allowed in the queue
* @throws BindException if the address can't be bound
* @throws UnknownHostException if the address isn't a valid host name
* @throws IOException other random errors from bind
*/
public static void bind(ServerSocket socket, InetSocketAddress address,
int backlog) throws IOException {
try {
socket.bind(address, backlog);
} catch (BindException e) {
BindException bindException =
new BindException("Problem binding to " + address + " : " +
e.getMessage());
bindException.initCause(e);
throw bindException;
} catch (SocketException e) {
// If they try to bind to a different host's address, give a better
// error message.
if ("Unresolved address".equals(e.getMessage())) {
throw new UnknownHostException("Invalid hostname for server: " +
address.getHostName());
}
throw e;
}
}
代码示例来源:origin: apache/geode
public ServerSocket createServerSocket(int nport, int backlog, InetAddress bindAddr,
List<GatewayTransportFilter> transportFilters, int socketBufferSize) throws IOException {
if (transportFilters.isEmpty()) {
return createServerSocket(nport, backlog, bindAddr, socketBufferSize);
} else {
printConfig();
ServerSocket result = new TransportFilterServerSocket(transportFilters);
result.setReuseAddress(true);
// Set the receive buffer size before binding the socket so
// that large buffers will be allocated on accepted sockets (see
// java.net.ServerSocket.setReceiverBufferSize javadocs)
result.setReceiveBufferSize(socketBufferSize);
try {
result.bind(new InetSocketAddress(bindAddr, nport), backlog);
} catch (BindException e) {
BindException throwMe =
new BindException(String.format("Failed to create server socket on %s[%s]",
bindAddr, Integer.valueOf(nport)));
throwMe.initCause(e);
throw throwMe;
}
return result;
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
/**
* Create bind exception by wrapping the bind exception thrown.
* @param listener
* @param ex
* @return
*/
private static BindException constructBindException(ServerConnector listener,
BindException ex) {
BindException be = new BindException("Port in use: "
+ listener.getHost() + ":" + listener.getPort());
if (ex != null) {
be.initCause(ex);
}
return be;
}
代码示例来源:origin: apache/geode
bindAddr == null ? InetAddress.getLocalHost() : bindAddr,
String.valueOf(nport)));
throwMe.initCause(e);
throw throwMe;
代码示例来源:origin: apache/hbase
BindException be = new BindException("Port in use: "
+ listener.getHost() + ":" + listener.getPort());
be.initCause(ex);
throw be;
代码示例来源:origin: org.apache.hadoop/hadoop-hdfs
private static BindException appendMessageToBindException(BindException e,
String msg) {
BindException newBe = new BindException(e.getMessage() + " " + msg);
newBe.initCause(e.getCause());
newBe.setStackTrace(e.getStackTrace());
return newBe;
}
}
代码示例来源:origin: OpenNMS/opennms
Receiver2(List<Client> clients) throws IOException {
m_name = "DHCPReceiver2";
m_worker = null;
m_status = START_PENDING;
try {
m_receiver = new DatagramSocket(DHCP_TARGET_PORT);
} catch (BindException e) {
BindException newE = new BindException("Could not open datagram socket for DHCP client on port " + DHCP_TARGET_PORT + ". Is there another DHCP client listening on this port? Original exception: " + e);
newE.initCause(e);
throw newE;
}
m_receiver.setSoTimeout(1000);
m_clients = clients;
}
代码示例来源:origin: org.webpieces/core-channelmanager2
private void bindImpl(SocketAddress srvrAddr) throws IOException {
try {
channel.bind(srvrAddr);
} catch(BindException e) {
BindException ee = new BindException("bind exception on addr="+srvrAddr);
ee.initCause(e);
throw ee;
}
}
代码示例来源:origin: org.eclipse.hudson/hudson-core
/**
* @param port Use 0 to choose a random port.
*/
public TcpSlaveAgentListener(int port) throws IOException {
super("TCP slave agent listener port=" + port);
try {
serverSocket = new ServerSocket(port);
} catch (BindException e) {
throw (BindException) new BindException("Failed to listen on port " + port + " because it's already in use.").initCause(e);
}
this.configuredPort = port;
LOGGER.info("JNLP slave agent listener started on TCP port " + getPort());
start();
}
代码示例来源:origin: com.facebook.hadoop/hadoop-core
/**
* A convenience method to bind to a given address and report
* better exceptions if the address is not a valid host.
* @param socket the socket to bind
* @param address the address to bind to
* @param backlog the number of connections allowed in the queue
* @throws BindException if the address can't be bound
* @throws UnknownHostException if the address isn't a valid host name
* @throws IOException other random errors from bind
*/
public static void bind(ServerSocket socket, InetSocketAddress address,
int backlog) throws IOException {
try {
socket.bind(address, backlog);
} catch (BindException e) {
BindException bindException = new BindException("Problem binding to " + address
+ " : " + e.getMessage());
bindException.initCause(e);
throw bindException;
} catch (SocketException e) {
// If they try to bind to a different host's address, give a better
// error message.
if ("Unresolved address".equals(e.getMessage())) {
throw new UnknownHostException("Invalid hostname for server: " +
address.getHostName());
} else {
throw e;
}
}
}
代码示例来源:origin: org.eclipse.hudson.main/hudson-core
/**
* @param port
* Use 0 to choose a random port.
*/
public TcpSlaveAgentListener(int port) throws IOException {
super("TCP slave agent listener port="+port);
try {
serverSocket = new ServerSocket(port);
} catch (BindException e) {
throw (BindException)new BindException("Failed to listen on port "+port+" because it's already in use.").initCause(e);
}
this.configuredPort = port;
LOGGER.info("JNLP slave agent listener started on TCP port "+getPort());
start();
}
代码示例来源:origin: org.jvnet.hudson.main/hudson-core
/**
* @param port
* Use 0 to choose a random port.
*/
public TcpSlaveAgentListener(int port) throws IOException {
super("TCP slave agent listener port="+port);
try {
serverSocket = new ServerSocket(port);
} catch (BindException e) {
throw (BindException)new BindException("Failed to listen on port "+port+" because it's already in use.").initCause(e);
}
this.configuredPort = port;
LOGGER.info("JNLP slave agent listener started on TCP port "+getPort());
start();
}
代码示例来源:origin: kaazing/gateway
@Override
protected Set<SocketAddress> bindInternal(
List<? extends SocketAddress> localAddresses) throws Exception {
for (SocketAddress localAddress : localAddresses) {
try {
Channel channel = bootstrap.bind(localAddress);
boundChannels.put(localAddress, channel);
}
catch (Exception e) {
BindException be = new BindException(format("Unable to bind address: %s", localAddress));
be.initCause(e);
be.fillInStackTrace();
throw be;
}
}
Set<SocketAddress> newLocalAddresses = new HashSet<>();
for (SocketAddress localAddress : localAddresses) {
newLocalAddresses.add(localAddress);
}
return newLocalAddresses;
}
代码示例来源:origin: hudson/hudson-2.x
/**
* @param port
* Use 0 to choose a random port.
*/
public TcpSlaveAgentListener(int port) throws IOException {
super("TCP slave agent listener port="+port);
try {
serverSocket = new ServerSocket(port);
} catch (BindException e) {
throw (BindException)new BindException("Failed to listen on port "+port+" because it's already in use.").initCause(e);
}
this.configuredPort = port;
LOGGER.info("JNLP slave agent listener started on TCP port "+getPort());
start();
}
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
/**
* @param port
* Use 0 to choose a random port.
*/
public TcpSlaveAgentListener(int port) throws IOException {
super("TCP agent listener port="+port);
try {
serverSocket = ServerSocketChannel.open();
serverSocket.socket().bind(new InetSocketAddress(port));
} catch (BindException e) {
throw (BindException)new BindException("Failed to listen on port "+port+" because it's already in use.").initCause(e);
}
this.configuredPort = port;
setUncaughtExceptionHandler((t, e) -> {
LOGGER.log(Level.SEVERE, "Uncaught exception in TcpSlaveAgentListener " + t + ", attempting to reschedule thread", e);
shutdown();
TcpSlaveAgentListenerRescheduler.schedule(t, e);
});
LOGGER.log(Level.FINE, "TCP agent listener started on port {0}", getPort());
start();
}
代码示例来源:origin: org.webpieces/core-channelmanager2
private void bindImpl(SocketAddress addr) throws IOException {
try {
bindImpl2(addr);
} catch(Error e) {
//NOTE: jdk was throwing Error instead of BindException. We fix
//this and throw BindException which is the logical choice!!
//We are crossing our fingers hoping there are not other SocketExceptions
//from things other than address already in use!!!
if(e.getCause() instanceof SocketException) {
BindException exc = new BindException(e.getMessage());
exc.initCause(e.getCause());
throw exc;
}
throw e;
}
}
代码示例来源:origin: org.apache.geode/gemfire-core
public ServerSocket createServerSocket(int nport, int backlog,
InetAddress bindAddr, List<GatewayTransportFilter> transportFilters,
int socketBufferSize)
throws IOException {
if (transportFilters.isEmpty()) {
return createServerSocket(nport, backlog, bindAddr, socketBufferSize);
}
else {
printConfig();
ServerSocket result = new TransportFilterServerSocket(transportFilters);
result.setReuseAddress(true);
// Set the receive buffer size before binding the socket so
// that large buffers will be allocated on accepted sockets (see
// java.net.ServerSocket.setReceiverBufferSize javadocs)
result.setReceiveBufferSize(socketBufferSize);
try {
result.bind(new InetSocketAddress(bindAddr, nport), backlog);
}
catch (BindException e) {
BindException throwMe = new BindException(
LocalizedStrings.SocketCreator_FAILED_TO_CREATE_SERVER_SOCKET_ON_0_1
.toLocalizedString(new Object[] { bindAddr,
Integer.valueOf(nport) }));
throwMe.initCause(e);
throw throwMe;
}
return result;
}
}
代码示例来源:origin: io.snappydata/gemfire-core
public ServerSocket createServerSocket(int nport, int backlog,
InetAddress bindAddr, GFLogWriter log,
List<GatewayTransportFilter> transportFilters, int socketBufferSize)
throws IOException {
if (transportFilters.isEmpty()) {
return createServerSocket(nport, backlog, bindAddr, log, socketBufferSize);
}
else {
printConfig(log);
ServerSocket result = new TransportFilterServerSocket(transportFilters);
result.setReuseAddress(true);
// Set the receive buffer size before binding the socket so
// that large buffers will be allocated on accepted sockets (see
// java.net.ServerSocket.setReceiverBufferSize javadocs)
result.setReceiveBufferSize(socketBufferSize);
try {
result.bind(new InetSocketAddress(bindAddr, nport), backlog);
}
catch (BindException e) {
BindException throwMe = new BindException(
LocalizedStrings.SocketCreator_FAILED_TO_CREATE_SERVER_SOCKET_ON_0_1
.toLocalizedString(new Object[] { bindAddr,
Integer.valueOf(nport) }));
throwMe.initCause(e);
throw throwMe;
}
return result;
}
}
代码示例来源:origin: kaazing/gateway
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
Channel channel = future.getChannel();
boundChannels.put(localAddress, channel);
bound.setBound();
}
else {
BindException be = new BindException(format("Unable to bind address: %s", localAddress));
be.initCause(future.getCause());
be.fillInStackTrace();
bound.setException(be);
}
}
});
内容来源于网络,如有侵权,请联系作者删除!