@Override protected void doClose() throws Exception { socket.close(); }
@Override protected void doClose() throws Exception { socket.close(); }
public void stop() { looping=false; mcast_sock.close(); }
@Override protected void doClose() throws Exception { socket.close(); }
protected void kill() { mcast_sock.close(); }
@Override public void close(boolean isBroadcast) throws Exception { open = false; if (broadcastingSocket != null) { broadcastingSocket.close(); } if (receivingSocket != null) { receivingSocket.close(); } }
void stop() { running = false; if (mcast_sock != null) { mcast_sock.close(); mcast_sock = null; } if (sock != null) { sock.close(); sock = null; } }
public static void closeQuietly(final MulticastSocket socket) { if (socket == null) { return; } try { socket.close(); } catch (final Exception ex) { logger.debug("Failed to close multicast socket due to: " + ex, ex); } }
public void shutdown() { shutdown = true; mcs.close(); interrupt(); }
synchronized public void stop() { if (socket != null && !socket.isClosed()) { socket.close(); } }
synchronized public void stop() { if (socket != null && !socket.isClosed()) { try { log.fine("Leaving multicast group"); socket.leaveGroup(multicastAddress, multicastInterface); // Well this doesn't work and I have no idea why I get "java.net.SocketException: Can't assign requested address" } catch (Exception ex) { log.fine("Could not leave multicast group: " + ex); } // So... just close it and ignore the log messages socket.close(); } }
@Override protected void doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception { if (localAddress != null) { socket.bind(localAddress); } boolean success = false; try { socket.connect(remoteAddress); success = true; } finally { if (!success) { try { socket.close(); } catch (Throwable t) { logger.warn("Failed to close a socket.", t); } } } }
/** * Remove the expired providers(if clean is true), leave the multicast group and close the multicast socket. */ @Override public void destroy() { super.destroy(); try { ExecutorUtil.cancelScheduledFuture(cleanFuture); } catch (Throwable t) { logger.warn(t.getMessage(), t); } try { multicastSocket.leaveGroup(multicastAddress); multicastSocket.close(); } catch (Throwable t) { logger.warn(t.getMessage(), t); } ExecutorUtil.gracefulShutdown(cleanExecutor, cleanPeriod); }
/** * Remove the expired providers(if clean is true), leave the multicast group and close the multicast socket. */ @Override public void destroy() { super.destroy(); try { ExecutorUtil.cancelScheduledFuture(cleanFuture); } catch (Throwable t) { logger.warn(t.getMessage(), t); } try { multicastSocket.leaveGroup(multicastAddress); multicastSocket.close(); } catch (Throwable t) { logger.warn(t.getMessage(), t); } ExecutorUtil.gracefulShutdown(cleanExecutor, cleanPeriod); }
@Override protected void doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception { if (localAddress != null) { socket.bind(localAddress); } boolean success = false; try { socket.connect(remoteAddress); success = true; } finally { if (!success) { try { socket.close(); } catch (Throwable t) { logger.warn("Failed to close a socket.", t); } } } }
/** * Create a new instance from the given {@link MulticastSocket}. * * @param socket the {@link MulticastSocket} which is used by this instance */ public OioDatagramChannel(MulticastSocket socket) { super(null); boolean success = false; try { socket.setSoTimeout(SO_TIMEOUT); socket.setBroadcast(false); success = true; } catch (SocketException e) { throw new ChannelException( "Failed to configure the datagram socket timeout.", e); } finally { if (!success) { socket.close(); } } this.socket = socket; config = new DefaultOioDatagramChannelConfig(this, socket); }
@Test public void closeMulticastSocket() { MulticastSocket socket = mock(MulticastSocket.class); this.subject.close(socket); verify(socket).close(); } }
protected void doStop(ServiceStopper stopper) throws Exception { super.doStop(stopper); if (socket != null) { try { socket.leaveGroup(getMulticastAddress()); } catch (IOException e) { stopper.onException(this, e); } socket.close(); } }
/** * Create a new instance from the given {@link MulticastSocket}. * * @param socket the {@link MulticastSocket} which is used by this instance */ public OioDatagramChannel(MulticastSocket socket) { super(null); boolean success = false; try { socket.setSoTimeout(SO_TIMEOUT); socket.setBroadcast(false); success = true; } catch (SocketException e) { throw new ChannelException( "Failed to configure the datagram socket timeout.", e); } finally { if (!success) { socket.close(); } } this.socket = socket; config = new DefaultOioDatagramChannelConfig(this, socket); }
@Override synchronized void createSocket(int aPort, InetAddress addr) throws SocketException { impl = factory != null ? factory.createDatagramSocketImpl() : new PlainDatagramSocketImpl(); impl.create(); try { impl.setOption(SocketOptions.SO_REUSEADDR, Boolean.TRUE); impl.bind(aPort, addr); isBound = true; } catch (SocketException e) { close(); throw e; } }