Search in sources :

Example 56 with Callback

use of okhttp3.Callback in project azure-sdk-for-java by Azure.

the class JobSchedulesImpl method getAsync.

/**
     * Gets information about the specified job schedule.
     *
     * @param jobScheduleId The id of the job schedule to get.
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if callback is null
     * @return the {@link Call} object
     */
public ServiceCall getAsync(String jobScheduleId, final ServiceCallback<CloudJobSchedule> serviceCallback) throws IllegalArgumentException {
    if (serviceCallback == null) {
        throw new IllegalArgumentException("ServiceCallback is required for async calls.");
    }
    if (jobScheduleId == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter jobScheduleId is required and cannot be null."));
        return null;
    }
    if (this.client.apiVersion() == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."));
        return null;
    }
    final JobScheduleGetOptions jobScheduleGetOptions = null;
    String select = null;
    String expand = null;
    Integer timeout = null;
    String clientRequestId = null;
    Boolean returnClientRequestId = null;
    DateTime ocpDate = null;
    String ifMatch = null;
    String ifNoneMatch = null;
    DateTime ifModifiedSince = null;
    DateTime ifUnmodifiedSince = null;
    DateTimeRfc1123 ocpDateConverted = null;
    if (ocpDate != null) {
        ocpDateConverted = new DateTimeRfc1123(ocpDate);
    }
    DateTimeRfc1123 ifModifiedSinceConverted = null;
    if (ifModifiedSince != null) {
        ifModifiedSinceConverted = new DateTimeRfc1123(ifModifiedSince);
    }
    DateTimeRfc1123 ifUnmodifiedSinceConverted = null;
    if (ifUnmodifiedSince != null) {
        ifUnmodifiedSinceConverted = new DateTimeRfc1123(ifUnmodifiedSince);
    }
    Call<ResponseBody> call = service.get(jobScheduleId, this.client.apiVersion(), this.client.acceptLanguage(), select, expand, timeout, clientRequestId, returnClientRequestId, ocpDateConverted, ifMatch, ifNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, this.client.userAgent());
    final ServiceCall serviceCall = new ServiceCall(call);
    call.enqueue(new ServiceResponseCallback<CloudJobSchedule>(serviceCallback) {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            try {
                serviceCallback.success(getDelegate(response));
            } catch (BatchErrorException | IOException exception) {
                serviceCallback.failure(exception);
            }
        }
    });
    return serviceCall;
}
Also used : ServiceCall(com.microsoft.rest.ServiceCall) CloudJobSchedule(com.microsoft.azure.batch.protocol.models.CloudJobSchedule) DateTime(org.joda.time.DateTime) ResponseBody(okhttp3.ResponseBody) DateTimeRfc1123(com.microsoft.rest.DateTimeRfc1123) JobScheduleGetOptions(com.microsoft.azure.batch.protocol.models.JobScheduleGetOptions)

Example 57 with Callback

use of okhttp3.Callback in project azure-sdk-for-java by Azure.

the class JobSchedulesImpl method listNextAsync.

/**
     * Lists all of the job schedules in the specified account.
     *
     * @param nextPageLink The NextLink from the previous successful call to List operation.
     * @param jobScheduleListNextOptions Additional parameters for the operation
     * @param serviceCall the ServiceCall object tracking the Retrofit calls
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if callback is null
     * @return the {@link Call} object
     */
public ServiceCall listNextAsync(final String nextPageLink, final JobScheduleListNextOptions jobScheduleListNextOptions, final ServiceCall serviceCall, final ListOperationCallback<CloudJobSchedule> serviceCallback) throws IllegalArgumentException {
    if (serviceCallback == null) {
        throw new IllegalArgumentException("ServiceCallback is required for async calls.");
    }
    if (nextPageLink == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter nextPageLink is required and cannot be null."));
        return null;
    }
    Validator.validate(jobScheduleListNextOptions, serviceCallback);
    String clientRequestId = null;
    if (jobScheduleListNextOptions != null) {
        clientRequestId = jobScheduleListNextOptions.clientRequestId();
    }
    Boolean returnClientRequestId = null;
    if (jobScheduleListNextOptions != null) {
        returnClientRequestId = jobScheduleListNextOptions.returnClientRequestId();
    }
    DateTime ocpDate = null;
    if (jobScheduleListNextOptions != null) {
        ocpDate = jobScheduleListNextOptions.ocpDate();
    }
    DateTimeRfc1123 ocpDateConverted = null;
    if (ocpDate != null) {
        ocpDateConverted = new DateTimeRfc1123(ocpDate);
    }
    Call<ResponseBody> call = service.listNext(nextPageLink, this.client.acceptLanguage(), clientRequestId, returnClientRequestId, ocpDateConverted, this.client.userAgent());
    serviceCall.newCall(call);
    call.enqueue(new ServiceResponseCallback<List<CloudJobSchedule>>(serviceCallback) {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            try {
                ServiceResponseWithHeaders<PageImpl<CloudJobSchedule>, JobScheduleListHeaders> result = listNextDelegate(response);
                serviceCallback.load(result.getBody().getItems());
                if (result.getBody().getNextPageLink() != null && serviceCallback.progress(result.getBody().getItems()) == ListOperationCallback.PagingBahavior.CONTINUE) {
                    listNextAsync(result.getBody().getNextPageLink(), jobScheduleListNextOptions, serviceCall, serviceCallback);
                } else {
                    serviceCallback.success(new ServiceResponseWithHeaders<>(serviceCallback.get(), result.getHeaders(), result.getResponse()));
                }
            } catch (BatchErrorException | IOException exception) {
                serviceCallback.failure(exception);
            }
        }
    });
    return serviceCall;
}
Also used : CloudJobSchedule(com.microsoft.azure.batch.protocol.models.CloudJobSchedule) DateTime(org.joda.time.DateTime) ServiceResponseWithHeaders(com.microsoft.rest.ServiceResponseWithHeaders) ResponseBody(okhttp3.ResponseBody) DateTimeRfc1123(com.microsoft.rest.DateTimeRfc1123) List(java.util.List) PagedList(com.microsoft.azure.PagedList)

Example 58 with Callback

use of okhttp3.Callback in project azure-sdk-for-java by Azure.

the class JobSchedulesImpl method updateAsync.

/**
     * Updates the properties of the specified job schedule.
     *
     * @param jobScheduleId The id of the job schedule to update.
     * @param jobScheduleUpdateParameter The parameters for the request.
     * @param jobScheduleUpdateOptions Additional parameters for the operation
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if callback is null
     * @return the {@link Call} object
     */
public ServiceCall updateAsync(String jobScheduleId, JobScheduleUpdateParameter jobScheduleUpdateParameter, JobScheduleUpdateOptions jobScheduleUpdateOptions, final ServiceCallback<Void> serviceCallback) throws IllegalArgumentException {
    if (serviceCallback == null) {
        throw new IllegalArgumentException("ServiceCallback is required for async calls.");
    }
    if (jobScheduleId == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter jobScheduleId is required and cannot be null."));
        return null;
    }
    if (jobScheduleUpdateParameter == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter jobScheduleUpdateParameter is required and cannot be null."));
        return null;
    }
    if (this.client.apiVersion() == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."));
        return null;
    }
    Validator.validate(jobScheduleUpdateParameter, serviceCallback);
    Validator.validate(jobScheduleUpdateOptions, serviceCallback);
    Integer timeout = null;
    if (jobScheduleUpdateOptions != null) {
        timeout = jobScheduleUpdateOptions.timeout();
    }
    String clientRequestId = null;
    if (jobScheduleUpdateOptions != null) {
        clientRequestId = jobScheduleUpdateOptions.clientRequestId();
    }
    Boolean returnClientRequestId = null;
    if (jobScheduleUpdateOptions != null) {
        returnClientRequestId = jobScheduleUpdateOptions.returnClientRequestId();
    }
    DateTime ocpDate = null;
    if (jobScheduleUpdateOptions != null) {
        ocpDate = jobScheduleUpdateOptions.ocpDate();
    }
    String ifMatch = null;
    if (jobScheduleUpdateOptions != null) {
        ifMatch = jobScheduleUpdateOptions.ifMatch();
    }
    String ifNoneMatch = null;
    if (jobScheduleUpdateOptions != null) {
        ifNoneMatch = jobScheduleUpdateOptions.ifNoneMatch();
    }
    DateTime ifModifiedSince = null;
    if (jobScheduleUpdateOptions != null) {
        ifModifiedSince = jobScheduleUpdateOptions.ifModifiedSince();
    }
    DateTime ifUnmodifiedSince = null;
    if (jobScheduleUpdateOptions != null) {
        ifUnmodifiedSince = jobScheduleUpdateOptions.ifUnmodifiedSince();
    }
    DateTimeRfc1123 ocpDateConverted = null;
    if (ocpDate != null) {
        ocpDateConverted = new DateTimeRfc1123(ocpDate);
    }
    DateTimeRfc1123 ifModifiedSinceConverted = null;
    if (ifModifiedSince != null) {
        ifModifiedSinceConverted = new DateTimeRfc1123(ifModifiedSince);
    }
    DateTimeRfc1123 ifUnmodifiedSinceConverted = null;
    if (ifUnmodifiedSince != null) {
        ifUnmodifiedSinceConverted = new DateTimeRfc1123(ifUnmodifiedSince);
    }
    Call<ResponseBody> call = service.update(jobScheduleId, jobScheduleUpdateParameter, this.client.apiVersion(), this.client.acceptLanguage(), timeout, clientRequestId, returnClientRequestId, ocpDateConverted, ifMatch, ifNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, this.client.userAgent());
    final ServiceCall serviceCall = new ServiceCall(call);
    call.enqueue(new ServiceResponseCallback<Void>(serviceCallback) {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            try {
                serviceCallback.success(updateDelegate(response));
            } catch (BatchErrorException | IOException exception) {
                serviceCallback.failure(exception);
            }
        }
    });
    return serviceCall;
}
Also used : ServiceCall(com.microsoft.rest.ServiceCall) DateTime(org.joda.time.DateTime) ResponseBody(okhttp3.ResponseBody) DateTimeRfc1123(com.microsoft.rest.DateTimeRfc1123)

Example 59 with Callback

use of okhttp3.Callback in project azure-sdk-for-java by Azure.

the class JobsImpl method terminateAsync.

/**
     * Terminates the specified job, marking it as completed.
     *
     * @param jobId The id of the job to terminate.
     * @param terminateReason The text you want to appear as the job's TerminateReason. The default is 'UserTerminate'.
     * @param jobTerminateOptions Additional parameters for the operation
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if callback is null
     * @return the {@link Call} object
     */
public ServiceCall terminateAsync(String jobId, String terminateReason, JobTerminateOptions jobTerminateOptions, final ServiceCallback<Void> serviceCallback) throws IllegalArgumentException {
    if (serviceCallback == null) {
        throw new IllegalArgumentException("ServiceCallback is required for async calls.");
    }
    if (jobId == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter jobId is required and cannot be null."));
        return null;
    }
    if (this.client.apiVersion() == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."));
        return null;
    }
    Validator.validate(jobTerminateOptions, serviceCallback);
    Integer timeout = null;
    if (jobTerminateOptions != null) {
        timeout = jobTerminateOptions.timeout();
    }
    String clientRequestId = null;
    if (jobTerminateOptions != null) {
        clientRequestId = jobTerminateOptions.clientRequestId();
    }
    Boolean returnClientRequestId = null;
    if (jobTerminateOptions != null) {
        returnClientRequestId = jobTerminateOptions.returnClientRequestId();
    }
    DateTime ocpDate = null;
    if (jobTerminateOptions != null) {
        ocpDate = jobTerminateOptions.ocpDate();
    }
    String ifMatch = null;
    if (jobTerminateOptions != null) {
        ifMatch = jobTerminateOptions.ifMatch();
    }
    String ifNoneMatch = null;
    if (jobTerminateOptions != null) {
        ifNoneMatch = jobTerminateOptions.ifNoneMatch();
    }
    DateTime ifModifiedSince = null;
    if (jobTerminateOptions != null) {
        ifModifiedSince = jobTerminateOptions.ifModifiedSince();
    }
    DateTime ifUnmodifiedSince = null;
    if (jobTerminateOptions != null) {
        ifUnmodifiedSince = jobTerminateOptions.ifUnmodifiedSince();
    }
    JobTerminateParameter jobTerminateParameter = null;
    if (terminateReason != null) {
        jobTerminateParameter = new JobTerminateParameter();
        jobTerminateParameter.withTerminateReason(terminateReason);
    }
    DateTimeRfc1123 ocpDateConverted = null;
    if (ocpDate != null) {
        ocpDateConverted = new DateTimeRfc1123(ocpDate);
    }
    DateTimeRfc1123 ifModifiedSinceConverted = null;
    if (ifModifiedSince != null) {
        ifModifiedSinceConverted = new DateTimeRfc1123(ifModifiedSince);
    }
    DateTimeRfc1123 ifUnmodifiedSinceConverted = null;
    if (ifUnmodifiedSince != null) {
        ifUnmodifiedSinceConverted = new DateTimeRfc1123(ifUnmodifiedSince);
    }
    Call<ResponseBody> call = service.terminate(jobId, this.client.apiVersion(), this.client.acceptLanguage(), timeout, clientRequestId, returnClientRequestId, ocpDateConverted, ifMatch, ifNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, jobTerminateParameter, this.client.userAgent());
    final ServiceCall serviceCall = new ServiceCall(call);
    call.enqueue(new ServiceResponseCallback<Void>(serviceCallback) {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            try {
                serviceCallback.success(terminateDelegate(response));
            } catch (BatchErrorException | IOException exception) {
                serviceCallback.failure(exception);
            }
        }
    });
    return serviceCall;
}
Also used : ServiceCall(com.microsoft.rest.ServiceCall) DateTime(org.joda.time.DateTime) ResponseBody(okhttp3.ResponseBody) DateTimeRfc1123(com.microsoft.rest.DateTimeRfc1123) JobTerminateParameter(com.microsoft.azure.batch.protocol.models.JobTerminateParameter)

Example 60 with Callback

use of okhttp3.Callback in project azure-sdk-for-java by Azure.

the class JobsImpl method patchAsync.

/**
     * Updates the properties of a job.
     *
     * @param jobId The id of the job whose properties you want to update.
     * @param jobPatchParameter The parameters for the request.
     * @param jobPatchOptions Additional parameters for the operation
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if callback is null
     * @return the {@link Call} object
     */
public ServiceCall patchAsync(String jobId, JobPatchParameter jobPatchParameter, JobPatchOptions jobPatchOptions, final ServiceCallback<Void> serviceCallback) throws IllegalArgumentException {
    if (serviceCallback == null) {
        throw new IllegalArgumentException("ServiceCallback is required for async calls.");
    }
    if (jobId == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter jobId is required and cannot be null."));
        return null;
    }
    if (jobPatchParameter == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter jobPatchParameter is required and cannot be null."));
        return null;
    }
    if (this.client.apiVersion() == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."));
        return null;
    }
    Validator.validate(jobPatchParameter, serviceCallback);
    Validator.validate(jobPatchOptions, serviceCallback);
    Integer timeout = null;
    if (jobPatchOptions != null) {
        timeout = jobPatchOptions.timeout();
    }
    String clientRequestId = null;
    if (jobPatchOptions != null) {
        clientRequestId = jobPatchOptions.clientRequestId();
    }
    Boolean returnClientRequestId = null;
    if (jobPatchOptions != null) {
        returnClientRequestId = jobPatchOptions.returnClientRequestId();
    }
    DateTime ocpDate = null;
    if (jobPatchOptions != null) {
        ocpDate = jobPatchOptions.ocpDate();
    }
    String ifMatch = null;
    if (jobPatchOptions != null) {
        ifMatch = jobPatchOptions.ifMatch();
    }
    String ifNoneMatch = null;
    if (jobPatchOptions != null) {
        ifNoneMatch = jobPatchOptions.ifNoneMatch();
    }
    DateTime ifModifiedSince = null;
    if (jobPatchOptions != null) {
        ifModifiedSince = jobPatchOptions.ifModifiedSince();
    }
    DateTime ifUnmodifiedSince = null;
    if (jobPatchOptions != null) {
        ifUnmodifiedSince = jobPatchOptions.ifUnmodifiedSince();
    }
    DateTimeRfc1123 ocpDateConverted = null;
    if (ocpDate != null) {
        ocpDateConverted = new DateTimeRfc1123(ocpDate);
    }
    DateTimeRfc1123 ifModifiedSinceConverted = null;
    if (ifModifiedSince != null) {
        ifModifiedSinceConverted = new DateTimeRfc1123(ifModifiedSince);
    }
    DateTimeRfc1123 ifUnmodifiedSinceConverted = null;
    if (ifUnmodifiedSince != null) {
        ifUnmodifiedSinceConverted = new DateTimeRfc1123(ifUnmodifiedSince);
    }
    Call<ResponseBody> call = service.patch(jobId, jobPatchParameter, this.client.apiVersion(), this.client.acceptLanguage(), timeout, clientRequestId, returnClientRequestId, ocpDateConverted, ifMatch, ifNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, this.client.userAgent());
    final ServiceCall serviceCall = new ServiceCall(call);
    call.enqueue(new ServiceResponseCallback<Void>(serviceCallback) {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            try {
                serviceCallback.success(patchDelegate(response));
            } catch (BatchErrorException | IOException exception) {
                serviceCallback.failure(exception);
            }
        }
    });
    return serviceCall;
}
Also used : ServiceCall(com.microsoft.rest.ServiceCall) DateTime(org.joda.time.DateTime) ResponseBody(okhttp3.ResponseBody) DateTimeRfc1123(com.microsoft.rest.DateTimeRfc1123)

Aggregations

ResponseBody (okhttp3.ResponseBody)248 Response (okhttp3.Response)214 Request (okhttp3.Request)208 IOException (java.io.IOException)203 Callback (okhttp3.Callback)172 DateTimeRfc1123 (com.microsoft.rest.DateTimeRfc1123)166 Call (okhttp3.Call)166 DateTime (org.joda.time.DateTime)166 ServiceCall (com.microsoft.rest.ServiceCall)140 Test (org.junit.Test)119 List (java.util.List)101 Call (retrofit2.Call)87 MockResponse (okhttp3.mockwebserver.MockResponse)72 RequestBody (okhttp3.RequestBody)62 OkHttpClient (okhttp3.OkHttpClient)61 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)57 GsonBuilder (com.google.gson.GsonBuilder)53 Retrofit (retrofit2.Retrofit)53 PagedList (com.microsoft.azure.PagedList)52 ServiceResponseWithHeaders (com.microsoft.rest.ServiceResponseWithHeaders)52