class AutoReconnectSession extends DelegatedSession {

    private ConnectionInfo ci;
    private String newTargetNodes;

    AutoReconnectSession(ConnectionInfo ci) {
        this.ci = ci;
    }

    @Override
    public void setAutoCommit(boolean autoCommit) {
        super.setAutoCommit(autoCommit);

        if (newTargetNodes != null) {
            reconnect();
        }
    }

    @Override
    public void runModeChanged(String newTargetNodes) {
        this.newTargetNodes = newTargetNodes;
        if (session.isAutoCommit()) {
            reconnect();
        }
    }

    private void reconnect() {<FILL_FUNCTION_BODY>}

    @Override
    public void reconnectIfNeeded() {
        if (newTargetNodes != null) {
            reconnect();
        }
    }
}

        Session oldSession = this.session;
        this.ci = this.ci.copy(newTargetNodes);
        ci.getSessionFactory().createSession(ci).onSuccess(s -> {
            AutoReconnectSession a = (AutoReconnectSession) s;
            session = a.session;
            oldSession.close();
            newTargetNodes = null;
        });
    
<methods>public void <init>() ,public void <init>(com.lealone.db.session.Session) ,public void cancel() ,public void cancelStatement(int) ,public void checkClosed() ,public void close() ,public AsyncCallback<T> createCallback() ,public com.lealone.sql.SQLCommand createSQLCommand(java.lang.String, int, boolean) ,public com.lealone.db.ConnectionInfo getConnectionInfo() ,public com.lealone.db.DataHandler getDataHandler() ,public int getId() ,public byte[] getLobMacSalt() ,public java.lang.String getLocalHostAndPort() ,public int getNetworkTimeout() ,public com.lealone.db.RunMode getRunMode() ,public com.lealone.db.scheduler.Scheduler getScheduler() ,public com.lealone.db.session.SessionStatus getStatus() ,public java.lang.String getTargetNodes() ,public com.lealone.common.trace.Trace getTrace(com.lealone.common.trace.TraceModuleType, com.lealone.common.trace.TraceObjectType) ,public com.lealone.common.trace.Trace getTrace(com.lealone.common.trace.TraceModuleType, com.lealone.common.trace.TraceObjectType, int) ,public java.lang.String getURL() ,public com.lealone.sql.PreparedSQLStatement.YieldableCommand getYieldableCommand() ,public com.lealone.sql.PreparedSQLStatement.YieldableCommand getYieldableCommand(boolean, com.lealone.db.session.Session.TimeoutListener) ,public void init() ,public boolean isAutoCommit() ,public boolean isClosed() ,public boolean isInvalid() ,public boolean isRunModeChanged() ,public boolean isSingleThreadCallback() ,public boolean isValid() ,public void reconnectIfNeeded() ,public void runModeChanged(java.lang.String) ,public Future<R> send(com.lealone.server.protocol.Packet, AckPacketHandler<R,P>) ,public Future<R> send(com.lealone.server.protocol.Packet, int, AckPacketHandler<R,P>) ,public void setAutoCommit(boolean) ,public void setInvalid(boolean) ,public void setLobMacSalt(byte[]) ,public void setNetworkTimeout(int) ,public void setRunMode(com.lealone.db.RunMode) ,public void setScheduler(com.lealone.db.scheduler.Scheduler) ,public void setSession(com.lealone.db.session.Session) ,public void setSingleThreadCallback(boolean) ,public void setStatus(com.lealone.db.session.SessionStatus) ,public void setTargetNodes(java.lang.String) ,public void setYieldableCommand(com.lealone.sql.PreparedSQLStatement.YieldableCommand) <variables>protected com.lealone.db.session.Session session