/**
  * Closes a connection to the supplied remote address, if it is open. This method is particularly
  * useful when not using a timeout for remote connections.
  *
  * @param remoteAddress the address of the peer socket.
  * @return <code>true</code> if the connection has been closed and <code>false</code> if there was
  *     nothing to close.
  * @since 1.7.1
  */
 public synchronized boolean close(Address remoteAddress) throws IOException {
   if (logger.isDebugEnabled()) {
     logger.debug("Closing socket for peer address " + remoteAddress);
   }
   SocketEntry entry = (SocketEntry) sockets.remove(remoteAddress);
   if (entry != null) {
     synchronized (entry) {
       entry.getSocket().close();
     }
     logger.info("Socket to " + entry.getPeerAddress() + " closed");
     return true;
   }
   return false;
 }
Exemplo n.º 2
0
 public void sendMessage(
     UdpAddress targetAddress, byte[] message, TransportStateReference tmStateReference)
     throws java.io.IOException {
   InetSocketAddress targetSocketAddress =
       new InetSocketAddress(targetAddress.getInetAddress(), targetAddress.getPort());
   if (logger.isDebugEnabled()) {
     logger.debug(
         "Sending message to "
             + targetAddress
             + " with length "
             + message.length
             + ": "
             + new OctetString(message).toHexString());
   }
   DatagramSocket s = ensureSocket();
   s.send(new DatagramPacket(message, message.length, targetSocketAddress));
 }