@Path(value="/jobs") @Singleton public class JobsServlet extends EndpointServlet
objectMappers
Constructor and Description |
---|
JobsServlet(ObjectMappersSuite objectMappers,
ApiJobStore apiJobStore,
JobPayloadBuilder jobPayloadBuilder,
PreResponseStore preResponseStore,
BroadcastChannel<String> broadcastChannel,
RequestMapper requestMapper,
HttpResponseMaker httpResponseMaker,
ResponseFormatResolver formatResolver)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected ResponseContext |
addPaginationInfoToResponseContext(ResponseContext responseContext,
javax.ws.rs.core.UriInfo uriInfo,
Pagination<Result> pages)
Add pagination details to ResponseContext.
|
protected javax.ws.rs.core.Response |
getErrorResponse(Throwable throwable)
Map the exception thrown while processing the job request to an appropriate http response.
|
void |
getJobByTicket(String ticket,
javax.ws.rs.core.UriInfo uriInfo,
javax.ws.rs.container.ContainerRequestContext containerRequestContext,
javax.ws.rs.container.AsyncResponse asyncResponse)
Endpoint to get all the metadata about a particular job.
|
void |
getJobResultsByTicket(String ticket,
String format,
String asyncAfter,
String perPage,
String page,
javax.ws.rs.core.UriInfo uriInfo,
javax.ws.rs.container.ContainerRequestContext containerRequestContext,
javax.ws.rs.container.AsyncResponse asyncResponse)
Endpoint to get a particular job's result.
|
void |
getJobs(String perPage,
String page,
String format,
String filters,
javax.ws.rs.core.UriInfo uriInfo,
javax.ws.rs.container.ContainerRequestContext containerRequestContext,
javax.ws.rs.container.AsyncResponse asyncResponse)
Endpoint to get metadata of all the Jobs in the ApiJobStore.
|
protected javax.ws.rs.core.Response |
getResponse(String jsonResponse)
Map the given jsonString to a Response object.
|
protected rx.Observable<PreResponse> |
getResults(String ticket,
long asyncAfter)
Get an Observable wrapping a PreResponse.
|
protected rx.Observable<javax.ws.rs.core.Response> |
handleJobResponse(String ticket,
JobsApiRequestImpl apiRequest)
Process a request to get job payload.
|
protected rx.Observable<javax.ws.rs.core.Response> |
handlePreResponse(String ticket,
JobsApiRequestImpl apiRequest,
javax.ws.rs.container.AsyncResponse asyncResponse,
rx.Observable<PreResponse> preResponseObservable,
boolean isEmpty)
If isEmpty is true, call the method to send the job payload to the user else call the method to send the job
result to the user.
|
protected rx.Observable<PreResponse> |
handlePreResponseWithError(PreResponse preResponse,
javax.ws.rs.core.UriInfo uriInfo,
Optional<PaginationParameters> paginationParameters)
Check whether the PreResponse contains an error and if it does, return an Observable wrapping the error else
return an Observable wrapping the PreResponse as is.
|
protected void |
handleResultsResponse(rx.Observable<PreResponse> preResponseObservable,
javax.ws.rs.container.AsyncResponse asyncResponse,
ApiRequest apiRequest)
Process a request to get job results.
|
formatResponse
@Inject public JobsServlet(ObjectMappersSuite objectMappers, ApiJobStore apiJobStore, JobPayloadBuilder jobPayloadBuilder, PreResponseStore preResponseStore, BroadcastChannel<String> broadcastChannel, @Named(value="jobsApiRequestMapper") RequestMapper requestMapper, HttpResponseMaker httpResponseMaker, ResponseFormatResolver formatResolver)
objectMappers
- JSON toolsapiJobStore
- The ApiJobStore containing job metadatajobPayloadBuilder
- The JobRowMapper to be used to map JobRow to the Job returned via the apipreResponseStore
- The Data store that stores all the PreResponsesbroadcastChannel
- Channel to notify other Bard processes (i.e. long pollers)requestMapper
- Mapper for changing the API requesthttpResponseMaker
- The factory for building HTTP responsesformatResolver
- The formatResolver for determining correct response format@GET @Timed public void getJobs(@DefaultValue(value="") @NotNull @QueryParam(value="perPage") String perPage, @DefaultValue(value="") @NotNull @QueryParam(value="page") String page, @QueryParam(value="format") String format, @QueryParam(value="filters") String filters, @Context javax.ws.rs.core.UriInfo uriInfo, @Context javax.ws.rs.container.ContainerRequestContext containerRequestContext, @Suspended javax.ws.rs.container.AsyncResponse asyncResponse)
perPage
- Requested number of rows of data to be displayed on each page of resultspage
- Requested page of results desiredformat
- Requested formatfilters
- Filters to be applied on the JobRows. Expects a URL filter query String that may contain multiple
filter strings separated by comma. The format of a filter String is :
(JobField name)-(operation)[(value or comma separated values)]?uriInfo
- UriInfo of the requestcontainerRequestContext
- The context of data provided by the Jersey container for this requestasyncResponse
- An asyncAfter response that we can use to respond asynchronously@GET @Timed @Path(value="/{ticket}") public void getJobByTicket(@PathParam(value="ticket") String ticket, @Context javax.ws.rs.core.UriInfo uriInfo, @Context javax.ws.rs.container.ContainerRequestContext containerRequestContext, @Suspended javax.ws.rs.container.AsyncResponse asyncResponse)
ticket
- The ticket that can uniquely identify a JoburiInfo
- UriInfo of the requestcontainerRequestContext
- The context of data provided by the Jersey container for this requestasyncResponse
- An async response that we can use to respond asynchronously@GET @Timed @Path(value="/{ticket}/results") public void getJobResultsByTicket(@PathParam(value="ticket") String ticket, @QueryParam(value="format") String format, @QueryParam(value="asyncAfter") String asyncAfter, @DefaultValue(value="") @NotNull @QueryParam(value="perPage") String perPage, @DefaultValue(value="") @NotNull @QueryParam(value="page") String page, @Context javax.ws.rs.core.UriInfo uriInfo, @Context javax.ws.rs.container.ContainerRequestContext containerRequestContext, @Suspended javax.ws.rs.container.AsyncResponse asyncResponse)
ticket
- The ticket that can uniquely identify a Jobformat
- Requested format of the responseasyncAfter
- How long the user is willing to wait for a synchronous request in milliseconds, if null
defaults to the system config default_asyncAfter
perPage
- Requested number of rows of data to be displayed on each page of resultspage
- Requested page of results desireduriInfo
- UriInfo of the requestcontainerRequestContext
- The context of data provided by the Jersey container for this requestasyncResponse
- An async response that we can use to respond asynchronouslyprotected rx.Observable<javax.ws.rs.core.Response> handlePreResponse(String ticket, JobsApiRequestImpl apiRequest, javax.ws.rs.container.AsyncResponse asyncResponse, rx.Observable<PreResponse> preResponseObservable, boolean isEmpty)
ticket
- The ticket that can uniquely identify a JobapiRequest
- JobsApiRequestImpl object with all the associated info in itasyncResponse
- Parameter specifying for how long the request should be asyncAfterpreResponseObservable
- An Observable wrapping a PreResponse or an empty observableisEmpty
- A boolean that indicates if the PreResponse is emptyprotected rx.Observable<PreResponse> getResults(@NotNull String ticket, long asyncAfter)
ticket
- The ticket for which the PreResponse needs to be retrieved.asyncAfter
- The minimum duration the request is allowed to last before becoming asynchronousprotected rx.Observable<javax.ws.rs.core.Response> handleJobResponse(String ticket, JobsApiRequestImpl apiRequest)
ticket
- The ticket that can uniquely identify a JobapiRequest
- JobsApiRequestImpl object with all the associated info in itprotected void handleResultsResponse(rx.Observable<PreResponse> preResponseObservable, javax.ws.rs.container.AsyncResponse asyncResponse, ApiRequest apiRequest)
preResponseObservable
- An Observable over the PreResponse which will be used to generate the ResponseasyncResponse
- An async response that we can use to respond asynchronouslyapiRequest
- JobsApiRequest object with all the associated info with itprotected rx.Observable<PreResponse> handlePreResponseWithError(PreResponse preResponse, javax.ws.rs.core.UriInfo uriInfo, Optional<PaginationParameters> paginationParameters)
preResponse
- The PreResponse to be inspecteduriInfo
- uriInfo object to get uriBuilderpaginationParameters
- user's requested pagination parametersprotected ResponseContext addPaginationInfoToResponseContext(ResponseContext responseContext, javax.ws.rs.core.UriInfo uriInfo, Pagination<Result> pages)
responseContext
- ResponseContext object contains all the meta info of the resultSeturiInfo
- uriInfo object to get uriBuilderpages
- Paginated resultSetprotected javax.ws.rs.core.Response getResponse(String jsonResponse)
jsonResponse
- The jsonResponse to be mapped to a Response objectprotected javax.ws.rs.core.Response getErrorResponse(Throwable throwable)
throwable
- The exception thrown while processing the requestCopyright © 2016–2018 Yahoo! Inc.. All rights reserved.