Source:
public void switchReadOnlyConnection(Boolean mustBeReadOnly) throws QueryException { if (mustBeReadOnly != currentReadOnlyAsked && currentProtocol.inTransaction()) { throw new QueryException("Trying to set to read-only mode during a transaction"); } checkWaitingConnection(); if (currentReadOnlyAsked != mustBeReadOnly) { synchronized (currentReadOnlyUpdateLock) { if (currentReadOnlyAsked == mustBeReadOnly) { return; } else { currentReadOnlyAsked = mustBeReadOnly; } if (currentReadOnlyAsked) { if (currentProtocol.isMasterConnection()) { if (!isSecondaryHostFail()) { proxy.lock.lock(); try { syncConnection(this.masterProtocol, this.secondaryProtocol); currentProtocol = this.secondaryProtocol; return; } catch (QueryException e) { if (setSecondaryHostFail()) { addToBlacklist(secondaryProtocol.getHostAddress()); } } finally { proxy.lock.unlock(); } } FailoverLoop.addListener(this); } } else { if (!currentProtocol.isMasterConnection()) { if (!isMasterHostFail()) { proxy.lock.lock(); try { syncConnection(this.secondaryProtocol, this.masterProtocol); currentProtocol = this.masterProtocol; return; } catch (QueryException e) { if (setMasterHostFail()) { addToBlacklist(masterProtocol.getHostAddress()); } } finally { proxy.lock.unlock(); } } try { reconnectFailedConnection(new SearchFilter(true, false)); handleFailLoop(); proxy.lock.lock(); try { syncConnection(this.secondaryProtocol, this.masterProtocol); currentProtocol = this.masterProtocol; } catch (QueryException e) { if (setMasterHostFail()) { addToBlacklist(masterProtocol.getHostAddress()); } } finally { proxy.lock.unlock(); } } catch (QueryException e) { FailoverLoop.removeListener(this); HostAddress failHost = (this.masterProtocol != null) ? this.masterProtocol.getHostAddress() : null; throwFailoverMessage(failHost, true, new QueryException("master " + masterProtocol.getHostAddress() + " connection failed"), false); } } } } } }

Target:
public void switchReadOnlyConnection(Boolean mustBeReadOnly) throws QueryException { if (mustBeReadOnly != currentReadOnlyAsked && currentProtocol.inTransaction()) { throw new QueryException("Trying to set to read-only mode during a transaction"); } checkWaitingConnection(); if (currentReadOnlyAsked != mustBeReadOnly) { proxy.lock.lock(); try { if (currentReadOnlyAsked == mustBeReadOnly) { return; } else { currentReadOnlyAsked = mustBeReadOnly; } if (currentReadOnlyAsked) { if (currentProtocol.isMasterConnection()) { if (!isSecondaryHostFail()) { proxy.lock.lock(); try { syncConnection(this.masterProtocol, this.secondaryProtocol); currentProtocol = this.secondaryProtocol; return; } catch (QueryException e) { if (setSecondaryHostFail()) { addToBlacklist(secondaryProtocol.getHostAddress()); } } finally { proxy.lock.unlock(); } } FailoverLoop.addListener(this); } } else { if (!currentProtocol.isMasterConnection()) { if (!isMasterHostFail()) { try { syncConnection(this.secondaryProtocol, this.masterProtocol); currentProtocol = this.masterProtocol; return; } catch (QueryException e) { if (setMasterHostFail()) { addToBlacklist(masterProtocol.getHostAddress()); } } } try { reconnectFailedConnection(new SearchFilter(true, false)); handleFailLoop(); try { syncConnection(this.secondaryProtocol, this.masterProtocol); currentProtocol = this.masterProtocol; } catch (QueryException e) { if (setMasterHostFail()) { addToBlacklist(masterProtocol.getHostAddress()); } } } catch (QueryException e) { FailoverLoop.removeListener(this); HostAddress failHost = (this.masterProtocol != null) ? this.masterProtocol.getHostAddress() : null; throwFailoverMessage(failHost, true, new QueryException("master " + masterProtocol.getHostAddress() + " connection failed"), false); } } } } finally { proxy.lock.unlock(); } } }