Beispiel #1
0
 public Socket newSocket() throws IOException {
   // zero means 'bind on any available port.'
   if (isEncryptedChannel()) {
     if (Config.getOutboundBindAny())
       return SSLFactory.getSocket(
           DatabaseDescriptor.getEncryptionOptions(),
           endPoint(),
           DatabaseDescriptor.getSSLStoragePort());
     else
       return SSLFactory.getSocket(
           DatabaseDescriptor.getEncryptionOptions(),
           endPoint(),
           DatabaseDescriptor.getSSLStoragePort(),
           FBUtilities.getLocalAddress(),
           0);
   } else {
     if (Config.getOutboundBindAny())
       return new Socket(endPoint(), DatabaseDescriptor.getStoragePort());
     else
       return new Socket(
           endPoint(), DatabaseDescriptor.getStoragePort(), FBUtilities.getLocalAddress(), 0);
   }
 }
 public Socket newSocket() throws IOException {
   // zero means 'bind on any available port.'
   if (isEncryptedChannel()) {
     if (Config.getOutboundBindAny())
       return SSLFactory.getSocket(
           DatabaseDescriptor.getServerEncryptionOptions(),
           endPoint(),
           DatabaseDescriptor.getSSLStoragePort());
     else
       return SSLFactory.getSocket(
           DatabaseDescriptor.getServerEncryptionOptions(),
           endPoint(),
           DatabaseDescriptor.getSSLStoragePort(),
           FBUtilities.getLocalAddress(),
           0);
   } else {
     Socket socket =
         SocketChannel.open(new InetSocketAddress(endPoint(), DatabaseDescriptor.getStoragePort()))
             .socket();
     if (Config.getOutboundBindAny() && !socket.isBound())
       socket.bind(new InetSocketAddress(FBUtilities.getLocalAddress(), 0));
     return socket;
   }
 }
 private boolean connect() {
   if (logger.isDebugEnabled()) logger.debug("attempting to connect to " + endpoint);
   long start = System.currentTimeMillis();
   while (System.currentTimeMillis() < start + DatabaseDescriptor.getRpcTimeout()) {
     try {
       // zero means 'bind on any available port.'
       socket =
           new Socket(
               endpoint, DatabaseDescriptor.getStoragePort(), InetAddress.getLocalHost(), 0);
       socket.setTcpNoDelay(true);
       output = new DataOutputStream(socket.getOutputStream());
       return true;
     } catch (IOException e) {
       socket = null;
       if (logger.isTraceEnabled()) logger.trace("unable to connect to " + endpoint, e);
       try {
         Thread.sleep(OPEN_RETRY_DELAY);
       } catch (InterruptedException e1) {
         throw new AssertionError(e1);
       }
     }
   }
   return false;
 }