Skip to content

Commit

Permalink
Reformat the code
Browse files Browse the repository at this point in the history
  • Loading branch information
brycezhongqing committed Nov 13, 2023
1 parent 9868e63 commit db93223
Showing 1 changed file with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
* In DUAL_READ mode, it reads from both the old and the new load balancer, but relies on the data from old
* load balancer only.
*/
public class DualReadLoadBalancer implements LoadBalancerWithFacilities {
public class DualReadLoadBalancer implements LoadBalancerWithFacilities
{
private static final Logger LOG = LoggerFactory.getLogger(DualReadLoadBalancer.class);
private final LoadBalancerWithFacilities _oldLb;
private final LoadBalancerWithFacilities _newLb;
Expand All @@ -65,7 +66,8 @@ public class DualReadLoadBalancer implements LoadBalancerWithFacilities {

@Deprecated
public DualReadLoadBalancer(LoadBalancerWithFacilities oldLb, LoadBalancerWithFacilities newLb,
@Nonnull DualReadStateManager dualReadStateManager) {
@Nonnull DualReadStateManager dualReadStateManager)
{
this(oldLb, newLb, dualReadStateManager, null);
LOG.warn("Deprecated DualReadLoadBalancer constructor used without a threadpool");
}
Expand All @@ -77,12 +79,15 @@ public DualReadLoadBalancer(LoadBalancerWithFacilities oldLb, LoadBalancerWithFa
_newLb = newLb;
_dualReadStateManager = dualReadStateManager;
_isNewLbReady = false;
if(executor == null){
if(executor == null)
{
// Using a direct executor here means the code is executed directly,
// blocking the caller. This means the old behavior is preserved.
_executor = MoreExecutors.newDirectExecutorService();
LOG.warn("Deprecated DualReadLoadBalancer constructor used without a threadpool executor");
}else{
}
else
{
_executor = executor;
}
}
Expand Down Expand Up @@ -126,25 +131,30 @@ public void getClient(Request request, RequestContext requestContext, Callback<T
break;
case DUAL_READ:
_executor.execute(
() -> _newLb.getLoadBalancedServiceProperties(serviceName, new Callback<ServiceProperties>() {
() -> _newLb.getLoadBalancedServiceProperties(serviceName, new Callback<ServiceProperties>()
{
@Override
public void onError(Throwable e) {
public void onError(Throwable e)
{
LOG.error("Double read failure. Unable to read service properties from: {}", serviceName, e);
}

@Override
public void onSuccess(ServiceProperties result) {
public void onSuccess(ServiceProperties result)
{
String clusterName = result.getClusterName();
_dualReadStateManager.updateCluster(clusterName, DualReadModeProvider.DualReadMode.DUAL_READ);
_newLb.getLoadBalancedClusterAndUriProperties(clusterName,
new Callback<Pair<ClusterProperties, UriProperties>>() {
_newLb.getLoadBalancedClusterAndUriProperties(clusterName, new Callback<Pair<ClusterProperties, UriProperties>>()
{
@Override
public void onError(Throwable e) {
public void onError(Throwable e)
{
LOG.error("Dual read failure. Unable to read cluster properties from: {}", clusterName, e);
}

@Override
public void onSuccess(Pair<ClusterProperties, UriProperties> result) {
public void onSuccess(Pair<ClusterProperties, UriProperties> result)
{
LOG.debug("Dual read is successful. Get cluster and uri properties: {}", result);
}
});
Expand Down

0 comments on commit db93223

Please sign in to comment.