1 /*
2 * Licensed to The Apereo Foundation under one or more contributor license
3 * agreements. See the NOTICE file distributed with this work for additional
4 * information regarding copyright ownership.
5 *
6 *
7 * The Apereo Foundation licenses this file to you under the Educational
8 * Community License, Version 2.0 (the "License"); you may not use this file
9 * except in compliance with the License. You may obtain a copy of the License
10 * at:
11 *
12 * http://opensource.org/licenses/ecl2.txt
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 * License for the specific language governing permissions and limitations under
18 * the License.
19 *
20 */
21
22 package org.opencastproject.job.api;
23
24 import org.opencastproject.job.api.Job.Status;
25 import org.opencastproject.serviceregistry.api.ServiceRegistryException;
26 import org.opencastproject.serviceregistry.api.UndispatchableJobException;
27
28 /**
29 * A service that creates jobs for long-running operations.
30 */
31 public interface JobProducer {
32
33 /**
34 * The type of jobs that this producer creates.
35 *
36 * @return the job type
37 */
38 String getJobType();
39
40 /**
41 * Get the number of jobs in a current status on all nodes.
42 *
43 * @return Number of jobs in this state
44 * @throws ServiceRegistryException
45 * if an error occurs while communicating with the backing data source
46 */
47 long countJobs(Status status) throws ServiceRegistryException;
48
49 /**
50 * Asks the job producer to handle the given job using the provided operation and list of arguments. The
51 * implementation of this method <b>must</b> be asynchronous if the processing takes more than a few seconds.
52 *
53 * @param job
54 * the job being dispatched
55 * @throws ServiceRegistryException
56 * if the producer was unable to start work as requested
57 */
58 void acceptJob(Job job) throws ServiceRegistryException;
59
60 /**
61 * Whether new jobs can be accepted in general.
62 *
63 * @param operation
64 * operation
65 * @throws ServiceRegistryException
66 * if the producer was unable to start work as requested
67 * @return whether the service is ready to accept jobs
68 */
69 boolean isReadyToAcceptJobs(String operation) throws ServiceRegistryException;
70
71 /**
72 * Whether the job can be accepted.
73 *
74 * @param job
75 * the job being dispatched
76 * @throws ServiceRegistryException
77 * if the producer was unable to start work as requested
78 * @throws UndispatchableJobException
79 * if the job will never be accepted because it is unacceptable
80 * @return whether the service is ready to accept the job
81 */
82 boolean isReadyToAccept(Job job) throws ServiceRegistryException, UndispatchableJobException;
83
84 }