Reconnects to new address obtained from secondary address via
InterCoronaTrackerProtocol
@throws IOException
336841
private final void reconnectToNewJobTracker(int connectNum) throws IOException {
    if (connectNum >= CONNECT_MAX_NUMBER) {
      LOG.error("reconnectToNewJobTracker has reached its max number.");
      throw new IOException("reconnectToNewJobTracker has reached its max number.");
    }
    
    InetSocketAddress secondaryTracker = getSecondaryTracker();
    JobConf conf = getConf();
    InetSocketAddress oldAddress = getCurrentClientAddress();

    LOG.info("Falling back from " + oldAddress + " to secondary tracker at "
        + secondaryTracker + " with " + connectNum + " try");
    if (secondaryTracker == null)
      throw new IOException("Secondary address not provided.");

    shutdown();
    InterCoronaJobTrackerProtocol secondaryClient = RPC.waitForProxy(
        InterCoronaJobTrackerProtocol.class,
        InterCoronaJobTrackerProtocol.versionID, secondaryTracker, conf,
        SECONDARY_TRACKER_CONNECT_TIMEOUT);
    // Obtain new address
    InetSocketAddressWritable oldAddrWritable = new InetSocketAddressWritable(
        oldAddress);
    InetSocketAddressWritable newAddress = null;
    int retryNum = 0;
    do {
      newAddress = secondaryClient.getNewJobTrackerAddress(oldAddrWritable);
      try {
        waitRetry();
      } catch (InterruptedException e) {
        LOG.error("Fallback interrupted, taking next retry.");
      }
      ++retryNum;
    } while (newAddress == null && predRetry(retryNum));

    if (newAddress == null || newAddress.getAddress() == null)
      throw new IOException("Failed to obtain new job tracker address.");

    RPC.stopProxy(secondaryClient);
    try {
      connect(newAddress.getAddress());
      LOG.info("Fallback process successful: " + newAddress.getAddress());
    } catch (IOException e) {
      LOG.error("Fallback connect to " + newAddress.getAddress() + " failed for ", e);
      reconnectToNewJobTracker(++connectNum);
    }
  }
281242
@Override
    public void notifyOfConnection(
            int hostId,
            SocketChannel socket,
            SSLEngine sslEngine,
            InetSocketAddress listeningAddress) throws Exception
    {
        networkLog.info("Host " + getHostId() + " receives a new connection from host " + hostId);
        prepSocketChannel(socket);
        // Auxiliary connection never time out
        ForeignHost fhost = new ForeignHost(this, hostId, socket, Integer.MAX_VALUE,
                listeningAddress,
                createPicoNetwork(sslEngine, socket, true));
        putForeignHost(hostId, fhost);
        fhost.enableRead(VERBOTEN_THREADS);
        // Do all peers have enough secondary connections?
        for (int hId : m_peers) {
            if (m_foreignHosts.get(hId).size() != (m_secondaryConnections + 1)) {
                return;
            }
        }
        // Now it's time to use secondary pico network, see comments in presend() to know why we can't
        // do this earlier.
        m_hasAllSecondaryConnectionCreated = true;
}
796947
@Override
    public /*final*/ void bind(ResourceAddress address, IoHandler handler, BridgeSessionInitializer<? extends IoFuture> initializer) {

        // bind only address with matching scheme
        URI location = address.getResource();
        String schemeName = location.getScheme();
        if (!canBind(schemeName)) {
            throw new IllegalArgumentException(format("Unexpected scheme \"%s\" for URI: %s", schemeName, location));
        }
        
        if (!started.get()) {
            synchronized (started) {
                if (!started.get()) {
                    init();
                    started.set(true);
                }
            }
        }

        boolean bindAlternate;
        do {
            bindAlternate = address.getOption(BIND_ALTERNATE);
            //
            // add binding, expecting no clashing (according to BINDINGS_COMPARATOR)
            //
            Binding newBinding = new Binding(address, handler, initializer);
            Binding oldBinding = bindings.addBinding(newBinding);

            //System.out.println(getClass().getSimpleName()+"@"+hashCode()+" binding: "+address.getExternalURI()+" -- "+address.getOption(NEXT_PROTOCOL));

            if (oldBinding != null) {
                throw new RuntimeException("Unable to bind address " + address
                        + " because it collides with an already bound address " + oldBinding.bindAddress());
            }

            bindInternal(address, handler, initializer);
            address = address.getOption(ALTERNATE);
            
        } while (address != null && bindAlternate);
    }
228492
@Override
    public void connectAsynch(Object address) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "connectAsynch, vc=" + getVCHash());
        }
        // Determine if this is a redundant connect.
        if (connected) {
            handleRedundantConnect();
        }
        this.targetAddress = (TCPConnectRequestContext) address;
        // Nothing specific to SSL on connect. Pass through.
        ((OutboundConnectionLink) getDeviceLink()).connectAsynch(address);
        // The SSL handshake will happen in the ready method path.
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "connectAsynch");
        }
    }
1249244
void establishConnection () throws IOException {
        synchronized (operationOnConnectionMonitor) {
            if (state == State.CLOSED) {
                throw new IOException("Attempt to establish a connection with a closed connection factory");
            } else if (state == State.CONNECTED) {
                LOGGER.warn("Establishing new connection although a connection is already established");
            }
            try {
                LOGGER.info("Trying to establish connection to {}:{}", getHost(), getPort());
                connection = super.newConnection(executorService);
                connection.addShutdownListener(connectionShutdownListener);
                LOGGER.info("Established connection to {}:{}", getHost(), getPort());
                changeState(State.CONNECTED);
            } catch (IOException e) {
                LOGGER.error("Failed to establish connection to {}:{}", getHost(), getPort());
                throw e;
            }
        }
    }
1858
void startInternal() throws LifecycleException {
        _log.info( getClass().getSimpleName() + " starts initialization... (configured" +
                " nodes definition " + _memcachedNodes + ", failover nodes " + _failoverNodes + ")" );

        _statistics = Statistics.create( _enableStatistics );

        _memcachedNodesManager = createMemcachedNodesManager( _memcachedNodes, _failoverNodes);

        if(_storage == null) {
            _storage = createStorageClient( _memcachedNodesManager, _statistics );
        }

        final String sessionCookieName = _manager.getSessionCookieName();
        _currentRequest = new CurrentRequest();
        _trackingHostValve = createRequestTrackingHostValve(sessionCookieName, _currentRequest);
        final Context context = _manager.getContext();
        context.getParent().getPipeline().addValve(_trackingHostValve);
        _trackingContextValve = createRequestTrackingContextValve(sessionCookieName);
        context.getPipeline().addValve( _trackingContextValve );

        initNonStickyLockingMode( _memcachedNodesManager );

        _transcoderService = createTranscoderService( _statistics );

        _backupSessionService = new BackupSessionService( _transcoderService, _sessionBackupAsync, _sessionBackupTimeout,
                _backupThreadCount, _storage, _memcachedNodesManager, _statistics );

        _log.info( "--------\n- " + getClass().getSimpleName() + " finished initialization:" +
                "\n- sticky: "+ _sticky +
                "\n- operation timeout: " + _operationTimeout +
                "\n- node ids: " + _memcachedNodesManager.getPrimaryNodeIds() +
                "\n- failover node ids: " + _memcachedNodesManager.getFailoverNodeIds() +
                "\n- storage key prefix: " + _memcachedNodesManager.getStorageKeyFormat().prefix +
                "\n- locking mode: " + _lockingMode + " (expiration: " + _lockExpiration + "s)" +
                "\n--------");

    }
381658
def reconnected(self, conn):
        ''''''
        conn.sub(self._topic, self._channel)
        conn.rdy(1)
1094483
def reconnect(self):
        """"""
        try:
            self.conn.close()
        except Exception,e:
            self.logger.warn(e)

        self.createConnection()

        return True
1226041
def reconnect(self):
        
        self.connect(*self._saved_connect.args, **self._saved_connect.kwargs)
879785
protected void setRemoteSocketAddress(final SocketAddress newRemoteSocketAddress) {
		synchronized(remoteSocketAddressLock) {
			final SocketAddress oldRemoteSocketAddress = this.remoteSocketAddress;
			if(!newRemoteSocketAddress.equals(oldRemoteSocketAddress)) {
				this.remoteSocketAddress = newRemoteSocketAddress;
				listenerManager.enqueueEvent(
					new ConcurrentListenerManager.Event<SocketListener>() {
						@Override
						public Runnable createCall(final SocketListener listener) {
							return new Runnable() {
								@Override
								public void run() {
									listener.onRemoteSocketAddressChange(
										AbstractSocket.this,
										oldRemoteSocketAddress,
										newRemoteSocketAddress
									);
								}
							};
						}
					}
				);
			}
		}
	}
1006100
@Override
	public synchronized boolean reconnect() {
		logger.debug("reconnect() called");
		try {
			callbackRegistry.acceptConnectionStateChange(BitfinexConnectionStateEnum.RECONNECTION_INIT);
			websocketEndpoint.close();

			permissions = BitfinexApiKeyPermissions.NO_PERMISSIONS;
			authenticated = false;
			sequenceNumberAuditor.reset();
			connectionFeatureManager.setActiveConnectionFeatures(0);

			// Invalidate old data
			quoteManager.invalidateTickerHeartbeat();
			orderManager.clear();
			positionManager.clear();

			final CountDownLatch connectionReadyLatch = new CountDownLatch(4);

			final Closeable authSuccessEventCallback = callbackRegistry.onAuthenticationSuccessEvent(c -> {
				permissions = c.getPermissions();
				authenticated = true;
				connectionReadyLatch.countDown();
			});
			final Closeable authFailedCallback = callbackRegistry.onAuthenticationFailedEvent(c -> {
				permissions = c.getPermissions();
				authenticated = false;
				while (connectionReadyLatch.getCount() != 0) {
					connectionReadyLatch.countDown();
				}
			});
			
			final Closeable positionInitCallback = callbackRegistry.onMyPositionEvent((a, p) -> connectionReadyLatch.countDown());
			final Closeable walletsInitCallback = callbackRegistry.onMyWalletEvent((a, w) -> connectionReadyLatch.countDown());
			final Closeable orderInitCallback = callbackRegistry.onMySubmittedOrderEvent((a, o) -> connectionReadyLatch.countDown());

			// Reset account info handler
			setupDefaultAccountInfoHandler();

			websocketEndpoint.connect();

			connectionFeatureManager.applyConnectionFeatures();
			if( configuration.isAuthenticationEnabled()) {
				authenticateAndWait(connectionReadyLatch);
			}
			authSuccessEventCallback.close();
			authFailedCallback.close();
			positionInitCallback.close();
			walletsInitCallback.close();
			orderInitCallback.close();

			resubscribeChannels();

			updateConnectionHeartbeat();
			callbackRegistry.acceptConnectionStateChange(BitfinexConnectionStateEnum.RECONNECTION_SUCCESS);
			return true;
		} catch (final Exception e) {
			logger.error("Got exception while reconnect", e);
			websocketEndpoint.close();
			callbackRegistry.acceptConnectionStateChange(BitfinexConnectionStateEnum.RECONNECTION_FAILED);
			return false;
		}
	}
811127
private void reconnect() throws IOException {
        // First ensure we're closed.
        close();
        
        // Attempt to re-open.
        try {
			createSocket();
		} catch (Exception e) {
			e.printStackTrace();
			throw new IOException("Cannot connect to server", e);
		}
        m_inStream = m_socket.getInputStream();
        m_outStream = m_socket.getOutputStream();
    }
773801
static InetSocketAddress getNameNodeAddress(Configuration conf,
                                                      String cname, String rpcKey, String cname2) {
    String fs = conf.get(cname);
    String fs1 = conf.get(rpcKey);
    String fs2 = conf.get(cname2);
    Configuration newconf = new Configuration(conf);
    newconf.set("fs.default.name", fs);
    if (fs1 != null) {
      newconf.set(DFS_NAMENODE_RPC_ADDRESS_KEY, fs1);
    }
    if (fs2 != null) {
      newconf.set("dfs.namenode.dn-address", fs2);
    }
    return DataNode.getNameNodeAddress(newconf);
  }
1170878
protected synchronized void bind(InetAddress address, int lport)
        throws IOException
    {
       synchronized (fdLock) {
            if (!closePending && (socket == null || !socket.isBound())) {
                NetHooks.beforeTcpBind(fd, address, lport);
            }
        }
        socketBind(address, lport);
        if (socket != null)
            socket.setBound();
        if (serverSocket != null)
            serverSocket.setBound();
    }
638725
public void check() {
        List<InetSocketAddress> newAddrs = getAddresses();
        if (newAddrs != null && !newAddrs.equals(currentAddrs)) {

            if (addressChangeListener != null) {
                currentAddrs = newAddrs;
                addressChangeListener.changeAddresses(newAddrs);
            } else {
                LOGGER.error("Address change listener is null for JNDI key {}, cannot notify about new value {}", getJndiKey(), newAddrs);
            }
        }
    }
669403
private void updateOtherClientRenamed() throws IOException
    {
        final byte cid = in.readByte();
        final String cname = readString();
        for (final ConnectionListener listener : listeners)
        {
            listener.notifyClientNameChanged(Byte.valueOf(cid), cname);
        }
    }
308905
@Override
  public int addressRemote(byte []buffer, int offset, int length)
  {
    return _socket.getRemoteAddress(buffer, offset, length);
  }