aeron-cluster/src/main/java/io/aeron/cluster/client/AeronCluster.java
public void onNewLeader(
        final long clusterSessionId,
        final long leadershipTermId,
        final int leaderMemberId,
        final String memberEndpoints)
    {
        if (clusterSessionId != this.clusterSessionId)
        {
            throw new ClusterException(
                "invalid clusterSessionId=" + clusterSessionId + " expected " + this.clusterSessionId);
        }

        this.leadershipTermId = leadershipTermId;
        this.leaderMemberId = leaderMemberId;
        ingressMessageHeaderEncoder.leadershipTermId(leadershipTermId);
        sessionKeepAliveEncoder.leadershipTermId(leadershipTermId);

        if (ctx.clusterMemberEndpoints() != null)
        {
            CloseHelper.close(publication);
            ctx.clusterMemberEndpoints(memberEndpoints);
            updateMemberEndpoints(memberEndpoints, leaderMemberId);
        }

        fragmentAssembler.clear();
        controlledFragmentAssembler.clear();
        egressListener.newLeader(clusterSessionId, leadershipTermId, leaderMemberId, memberEndpoints);
        controlledEgressListener.newLeader(clusterSessionId, leadershipTermId, leaderMemberId, memberEndpoints);
    }
public void onNewLeader(
        final long clusterSessionId,
        final long leadershipTermId,
        final int leaderMemberId,
        final String memberEndpoints)
    {
        if (clusterSessionId != this.clusterSessionId)
        {
            throw new ClusterException(
                "invalid clusterSessionId=" + clusterSessionId + " expected " + this.clusterSessionId);
        }

        this.leadershipTermId = leadershipTermId;
        this.leaderMemberId = leaderMemberId;
        ingressMessageHeaderEncoder.leadershipTermId(leadershipTermId);
        sessionKeepAliveEncoder.leadershipTermId(leadershipTermId);

        if (ctx.clusterMemberEndpoints() != null)
        {
            CloseHelper.close(publication);
            ctx.clusterMemberEndpoints(memberEndpoints);
            updateMemberEndpoints(memberEndpoints, leaderMemberId);
        }

        fragmentAssembler.clear();
        controlledFragmentAssembler.clear();
        egressListener.newLeader(clusterSessionId, leadershipTermId, leaderMemberId, memberEndpoints);
        controlledEgressListener.newLeader(clusterSessionId, leadershipTermId, leaderMemberId, memberEndpoints);
    }
To be called when a new leader event is delivered. This method needs to be called when using the
{@link EgressAdapter} or {@link EgressPoller} rather than {@link #pollEgress()} method.

@param clusterSessionId which must match {@link #clusterSessionId()}.
@param leadershipTermId that identifies the term for which the new leader has been elected.
@param leaderMemberId   which has become the new leader.
@param memberEndpoints  comma separated list of cluster members endpoints to connect to with the leader first.