/*
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the "License"). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

package alluxio.client.job;

import alluxio.AbstractMasterClient;
import alluxio.Constants;
import alluxio.grpc.CancelPRequest;
import alluxio.grpc.GetJobStatusPRequest;
import alluxio.grpc.JobMasterClientServiceGrpc;
import alluxio.grpc.ListAllPRequest;
import alluxio.grpc.RunPRequest;
import alluxio.grpc.ServiceType;
import alluxio.job.JobConfig;
import alluxio.job.util.SerializationUtils;
import alluxio.job.wire.JobInfo;
import alluxio.worker.job.JobMasterClientContext;

import com.google.protobuf.ByteString;
import io.grpc.StatusRuntimeException;

import java.io.IOException;
import java.util.List;

import javax.annotation.concurrent.ThreadSafe;

/**
 * A wrapper for the gRPC client to interact with the job service master, used by job service
 * clients.
 */
@ThreadSafe
public final class RetryHandlingJobMasterClient extends AbstractMasterClient
    implements JobMasterClient {
  private JobMasterClientServiceGrpc.JobMasterClientServiceBlockingStub mClient = null;

  /**
   * Creates a new job master client.
   *
   * @param conf master client configuration
   */
  public RetryHandlingJobMasterClient(JobMasterClientContext conf) {
    super(conf);
  }

  @Override
  protected ServiceType getRemoteServiceType() {
    return ServiceType.JOB_MASTER_CLIENT_SERVICE;
  }

  @Override
  protected String getServiceName() {
    return Constants.JOB_MASTER_CLIENT_SERVICE_NAME;
  }

  @Override
  protected long getServiceVersion() {
    return Constants.JOB_MASTER_CLIENT_SERVICE_VERSION;
  }

  @Override
  protected void beforeConnect()
      throws IOException {
    // Job master client does not load cluster-default configuration because only the master
    // will use this client
  }

  @Override
  protected void afterConnect() throws IOException {
    mClient = JobMasterClientServiceGrpc.newBlockingStub(mChannel);
  }

  @Override
  public void cancel(final long jobId) throws IOException {
    retryRPC(new RpcCallable<Void>() {
      public Void call() {
        mClient.cancel(CancelPRequest.newBuilder().setJobId(jobId).build());
        return null;
      }
    });
  }

  @Override
  public JobInfo getStatus(final long jobId) throws IOException {
    return new JobInfo(retryRPC(new RpcCallable<alluxio.grpc.JobInfo>() {
      public alluxio.grpc.JobInfo call() throws StatusRuntimeException {
        return mClient.getJobStatus(GetJobStatusPRequest.newBuilder().setJobId(jobId).build())
            .getJobInfo();
      }
    }));
  }

  @Override
  public List<Long> list() throws IOException {
    return retryRPC(new RpcCallable<List<Long>>() {
      public List<Long> call() {
        return mClient.listAll(ListAllPRequest.getDefaultInstance()).getJobIdsList();
      }
    });
  }

  @Override
  public long run(final JobConfig jobConfig) throws IOException {
    final ByteString jobConfigStr = ByteString.copyFrom(SerializationUtils.serialize(jobConfig));
    return retryRPC(new RpcCallable<Long>() {
      public Long call() throws StatusRuntimeException {
        return mClient.run(RunPRequest.newBuilder().setJobConfig(jobConfigStr).build()).getJobId();
      }
    });
  }
}

@@ -2430,36 +2430,33 @@
  %7B%0A    retryRPC(
-new 
+(
 RpcCallable%3CVoid
@@ -2460,42 +2460,18 @@
 oid%3E
-(
 ) 
-%7B%0A      public Void call() %7B%0A  
+() -%3E %7B%0A
     
@@ -2543,26 +2543,24 @@
 d());%0A      
-  
 return null;
@@ -2560,24 +2560,16 @@
 n null;%0A
-      %7D%0A
     %7D);%0A

Replace anonymous type with lambda