本文整理了Java中org.opencastproject.job.api.Job
类的一些代码示例,展示了Job
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Job
类的具体详情如下:
包路径:org.opencastproject.job.api.Job
类名称:Job
[英]Represents a long running, asynchronous process. A Job may be used to track any task, whether it is queued to run in the future, currently running, or has run in the past.
[中]表示长时间运行的异步进程。作业可用于跟踪任何任务,无论它是排队等待将来运行、当前运行还是过去运行。
代码示例来源:origin: opencast/opencast
public JaxbJob(Job job) {
this();
this.id = job.getId();
this.dateCompleted = job.getDateCompleted();
this.dateCreated = job.getDateCreated();
this.dateStarted = job.getDateStarted();
this.queueTime = job.getQueueTime();
this.runTime = job.getRunTime();
this.version = job.getVersion();
this.payload = job.getPayload();
this.processingHost = job.getProcessingHost();
this.createdHost = job.getCreatedHost();
this.id = job.getId();
this.jobType = job.getJobType();
this.operation = job.getOperation();
if (job.getArguments() != null)
this.arguments = unmodifiableList(job.getArguments());
this.status = job.getStatus();
this.parentJobId = job.getParentJobId();
this.rootJobId = job.getRootJobId();
this.dispatchable = job.isDispatchable();
this.uri = job.getUri();
this.creator = job.getCreator();
this.organization = job.getOrganization();
this.jobLoad = job.getJobLoad();
if (job.getBlockedJobIds() != null)
this.blockedJobIds = unmodifiableList(job.getBlockedJobIds());
this.blockingJobId = job.getBlockingJobId();
}
代码示例来源:origin: opencast/opencast
@Override
public void removeParentlessJobs(int lifetime) throws ServiceRegistryException {
synchronized (jobs) {
for (String serializedJob : jobs.values()) {
Job job = null;
try {
job = JobParser.parseJob(serializedJob);
} catch (IOException e) {
throw new IllegalStateException("Error unmarshaling job", e);
}
Long parentJobId = job.getParentJobId();
if (parentJobId == null | parentJobId < 1)
jobs.remove(job.getId());
}
}
}
代码示例来源:origin: opencast/opencast
@Override
public List<String> getJobPayloads(String operation) throws ServiceRegistryException {
List<String> result = new ArrayList<>();
for (String serializedJob : jobs.values()) {
try {
Job job = JobParser.parseJob(serializedJob);
if (operation.equals(job.getOperation())) {
result.add(job.getPayload());
}
} catch (IOException e) {
throw new IllegalStateException("Error unmarshaling job", e);
}
}
return result;
}
代码示例来源:origin: opencast/opencast
final Job job = jpaJob.toJob();
final Date now = new Date();
final Status status = job.getStatus();
final Status fromDbStatus = fromDb.getStatus();
fromDb.setPayload(job.getPayload());
fromDb.setStatus(job.getStatus());
fromDb.setDispatchable(job.isDispatchable());
fromDb.setVersion(job.getVersion());
fromDb.setOperation(job.getOperation());
fromDb.setArguments(job.getArguments());
fromDb.setBlockedJobIds(job.getBlockedJobIds());
fromDb.setBlockingJobId(job.getBlockingJobId());
if (job.getDateCreated() == null) {
jpaJob.setDateCreated(now);
fromDb.setDateCreated(now);
job.setDateCreated(now);
if (job.getProcessingHost() != null) {
ServiceRegistrationJpaImpl processingService = (ServiceRegistrationJpaImpl) getServiceRegistration(
job.getJobType(), job.getProcessingHost());
fromDb.setProcessorServiceRegistration(processingService);
if (job.getDateStarted() == null) {
jpaJob.setDateStarted(now);
jpaJob.setQueueTime(now.getTime() - job.getDateCreated().getTime());
fromDb.setDateStarted(now);
fromDb.setQueueTime(now.getTime() - job.getDateCreated().getTime());
代码示例来源:origin: opencast/opencast
private Job updateInternal(Job job) {
Date now = new Date();
Status status = job.getStatus();
if (job.getDateCreated() == null) {
job.setDateCreated(now);
if (job.getDateStarted() == null) {
job.setDateStarted(now);
job.setQueueTime(now.getTime() - job.getDateCreated().getTime());
job.setDateCompleted(now);
if (job.getDateStarted() != null) {
job.setRunTime(now.getTime() - job.getDateStarted().getTime());
if (job.getDateStarted() == null) {
job.setDateStarted(job.getDateCreated());
job.setDateCompleted(now);
job.setRunTime(now.getTime() - job.getDateStarted().getTime());
Set<Job> updatedJobs = new HashSet<>();
for (Job savedJob : jobs) {
if (savedJob.getId() != job.getId())
updatedJobs.add(savedJob);
代码示例来源:origin: opencast/opencast
@Override protected String process(Job job) throws Exception {
log.info("Processing job %d", job.getId());
return PAYLOAD;
}
代码示例来源:origin: opencast/opencast
/**
* {@inheritDoc}
*
* @see org.opencastproject.job.api.AbstractJobProducer#process(org.opencastproject.job.api.Job)
*/
@Override
protected String process(Job job) throws Exception {
Operation op = null;
String operation = job.getOperation();
List<String> arguments = job.getArguments();
try {
op = Operation.valueOf(operation);
switch (op) {
case Waveform:
Track track = (Track) MediaPackageElementParser.getFromXml(arguments.get(0));
int pixelsPerMinute = Integer.parseInt(arguments.get(1));
int minWidth = Integer.parseInt(arguments.get(2));
int maxWidth = Integer.parseInt(arguments.get(3));
int height = Integer.parseInt(arguments.get(4));
Attachment waveformMpe = extractWaveform(track, pixelsPerMinute, minWidth, maxWidth, height);
return MediaPackageElementParser.getAsXml(waveformMpe);
default:
throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'");
}
} catch (IndexOutOfBoundsException e) {
throw new ServiceRegistryException("This argument list for operation '" + op + "' does not meet expectations", e);
} catch (MediaPackageException | WaveformServiceException e) {
throw new ServiceRegistryException("Error handling operation '" + op + "'", e);
}
}
代码示例来源:origin: opencast/opencast
logger.debug("Started processing job {}", job.getId());
if (!OPERATION.equals(job.getOperation())) {
throw new ServiceRegistryException(String.format("This service can't handle operations of type '%s'",
job.getOperation()));
List<String> arguments = job.getArguments();
URI animation = new URI(arguments.get(0));
Gson gson = new Gson();
File output = new File(workspace.rootDirectory(), String.format("animate/%d/%s.%s", job.getId(),
FilenameUtils.getBaseName(animation.getPath()), "mkv"));
FileUtils.forceMkdirParent(output);
URI uri = workspace.putInCollection("animate-" + job.getId(), output.getName(),
new FileInputStream(output));
FileUtils.deleteQuietly(new File(workspace.rootDirectory(), String.format("animate/%d", job.getId())));
代码示例来源:origin: opencast/opencast
for (JpaJob jpaJob : jobs) {
Job job = jpaJob.toJob();
if (job.getDateCreated().after(d))
continue;
if (START_OPERATION.equals(job.getOperation()) || START_WORKFLOW.equals(job.getOperation())
|| RESUME.equals(job.getOperation()))
continue;
if (job.getStatus().isTerminated()) {
try {
removeJobs(Collections.singletonList(job.getId()));
logger.debug("Parentless job '{}' removed", job.getId());
count++;
} catch (NotFoundException e) {
logger.debug("Parentless job '{} ' not found in database: {}", job.getId(), e);
代码示例来源:origin: opencast/opencast
/**
* Remove all files created by the given jobs
* @param jobs
*/
private void cleanupWorkspace(List<Job> jobs) {
for (Job job : jobs) {
String jobPayload = job.getPayload();
if (StringUtils.isNotEmpty(jobPayload)) {
try {
MediaPackageElement timelinepreviewsMpe = MediaPackageElementParser.getFromXml(jobPayload);
URI timelinepreviewsUri = timelinepreviewsMpe.getURI();
workspace.delete(timelinepreviewsUri);
} catch (MediaPackageException ex) {
// unexpected job payload
logger.error("Can't parse timeline previews attachment from job {}", job.getId());
} catch (NotFoundException ex) {
// this is ok, because we want delete the file
} catch (IOException ex) {
logger.warn("Deleting timeline previews image file from workspace failed: {}", ex.getMessage());
// this is ok, because workspace cleaner will remove old files if they exist
}
}
}
}
代码示例来源:origin: opencast/opencast
job = new JobImpl(idCounter.addAndGet(1));
if (securityService != null) {
job.setCreator(securityService.getUser().getUsername());
job.setOrganization(securityService.getOrganization().getId());
job.setDateCreated(new Date());
job.setJobType(type);
job.setOperation(operation);
job.setArguments(arguments);
job.setPayload(payload);
if (queueable)
job.setStatus(Status.QUEUED);
else
job.setStatus(Status.INSTANTIATED);
if (parentJob != null)
job.setParentJobId(parentJob.getId());
job.setJobLoad(jobLoad);
jobs.put(job.getId(), JobParser.toXml(new JaxbJob(job)));
} catch (IOException e) {
throw new IllegalStateException("Error serializing job " + job, e);
代码示例来源:origin: opencast/opencast
/**
* Record an incident for a given job caused by an uncatched exception. This method is intended to record incidents by
* the job system itself, e.g. the job dispatcher.
*/
private void unhandledException(Job job, String code, Severity severity, Throwable t) {
if (!alreadyRecordedFailureIncident(job.getId())) {
try {
is.storeIncident(
job,
new Date(),
code,
severity,
Collections.singletonMap("exception", ExceptionUtils.getMessage(t)),
Arrays.asList(tuple("job-type", job.getJobType()), tuple("job-operation", job.getOperation()),
tuple("stack-trace", ExceptionUtils.getStackTrace(t))));
} catch (IncidentServiceException e) {
logException(e);
}
}
}
代码示例来源:origin: opencast/opencast
final Job processedJob = serviceRegistry.getJob(job.getId());
final Job.Status jobStatus = processedJob.getStatus();
switch (jobStatus) {
case CANCELED:
case FAILED:
case FINISHED:
job.setStatus(jobStatus);
job.setPayload(processedJob.getPayload());
finishedJobs.put(job, jobStatus);
break;
代码示例来源:origin: opencast/opencast
if (!jobType.equals(job.getJobType())) {
logger.debug("Invalid job type submitted: {}", job.getJobType());
return false;
Thread.currentThread().getId(), currentLoad, job.getJobLoad(), job.getStatus().name(),
maxload.getLoadFactor());
currentLoad += job.getJobLoad();
if (job.getJobLoad() > maxload.getLoadFactor() && acceptJobLoadsExeedingMaxLoad) {
logger.warn(
"{} Accepting job {} of type {} with load {} even though load of {} is above this node's limit of {}.",
Thread.currentThread().getId(), job.getId(), job.getJobType(), df.format(job.getJobLoad()),
df.format(currentLoad), df.format(maxload.getLoadFactor()));
logger.warn("This is a configuration issue that you should resolve in a production system!");
logger.debug(
"{} Declining job {} of type {} with load {} because load of {} would exceed this node's limit of {}.",
Thread.currentThread().getId(), job.getId(), job.getJobType(), df.format(job.getJobLoad()),
df.format(currentLoad), df.format(maxload.getLoadFactor()));
return false;
} else {
logger.debug("{} Accepting job {} of type {} with load {} because load of {} is within this node's limit of {}.",
Thread.currentThread().getId(), job.getId(), job.getJobType(), df.format(job.getJobLoad()),
df.format(currentLoad), df.format(maxload.getLoadFactor()));
return true;
代码示例来源:origin: opencast/opencast
/**
* {@inheritDoc}
*
* @see org.opencastproject.serviceregistry.api.ServiceRegistry#count(java.lang.String, java.lang.String,
* java.lang.String, org.opencastproject.job.api.Job.Status)
*/
@Override
public long count(String serviceType, String host, String operation, Status status) throws ServiceRegistryException {
int count = 0;
synchronized (jobs) {
for (String serializedJob : jobs.values()) {
Job job = null;
try {
job = JobParser.parseJob(serializedJob);
} catch (IOException e) {
throw new IllegalStateException("Error unmarshaling job", e);
}
if (serviceType != null && !serviceType.equals(job.getJobType()))
continue;
if (host != null && !host.equals(job.getProcessingHost()))
continue;
if (operation != null && !operation.equals(job.getOperation()))
continue;
if (status != null && !status.equals(job.getStatus()))
continue;
count++;
}
}
return count;
}
代码示例来源:origin: opencast/opencast
try {
job = JobParser.parseJob(serializedJob);
User creator = userDirectoryService.loadUser(job.getCreator());
Organization organization = organizationDirectoryService.getOrganization(job.getOrganization());
securityService.setUser(creator);
securityService.setOrganization(organization);
if (Status.QUEUED.equals(job.getStatus())) {
job.setStatus(Status.DISPATCHING);
if (!dispatchJob(job)) {
job.setStatus(Status.QUEUED);
job.setStatus(Status.FAILED);
Throwable cause = (e.getCause() != null) ? e.getCause() : e;
logger.error("Unable to find a service for job " + job, cause);
} catch (ServiceRegistryException e) {
job.setStatus(Status.FAILED);
Throwable cause = (e.getCause() != null) ? e.getCause() : e;
logger.error("Error dispatching job " + job, cause);
} finally {
try {
jobs.put(job.getId(), JobParser.toXml(new JaxbJob(job)));
} catch (IOException e) {
throw new IllegalStateException("Error unmarshaling job", e);
代码示例来源:origin: opencast/opencast
private static Incident toIncident(Job job, IncidentDto dto) {
return new IncidentImpl(dto.getId(), job.getId(), job.getJobType(), job.getProcessingHost(), dto.getTimestamp(),
dto.getSeverity(), dto.getCode(), dto.getTechnicalInformation(), dto.getParameters());
}
代码示例来源:origin: opencast/opencast
/**
* Sets j's blocking job ID (ie, the job which it is blocking) to waiter's ID
* @param j
* The job doing the blocking
* @param waiter
* The job blocking, waiting for its child to finish
* @return
* True if j is an active job and has been successfully updated, false if it is not an active job
* @throws ServiceRegistryException
* @throws NotFoundException
*/
private boolean setBlockerJob(Job j, Job waiter) throws ServiceRegistryException, NotFoundException {
Job blockerJob = this.serviceRegistry.getJob(j.getId());
if (j.getStatus().isActive()) {
blockerJob.setBlockingJobId(waiter.getId());
// FYI not updating local j in jobs collection
this.serviceRegistry.updateJob(blockerJob);
return true;
} else {
return false;
}
}
代码示例来源:origin: opencast/opencast
private void wakeWaiterJob() {
if (this.waiterJobId.isSome()) {
try {
final Job waiter = serviceRegistry.getJob(waiterJobId.get());
waiter.setStatus(Job.Status.RUNNING);
for (Job j : jobs) {
Job updatedJob = this.serviceRegistry.getJob(j.getId());
updatedJob.removeBlockingJobId();
// FYI not updating local j in jobs collection
this.serviceRegistry.updateJob(updatedJob);
}
waiter.removeBlockedJobsIds();
this.serviceRegistry.updateJob(waiter);
} catch (ServiceRegistryException e) {
logger.warn("Unable to put {} into a waiting state, this may cause a deadlock: {}", waiterJobId, e.getMessage());
} catch (NotFoundException e) {
logger.warn("Unable to put {} into a waiting state, job not found by the service registry. This may cause a deadlock: {}", waiterJobId, e.getMessage());
}
} else {
logger.debug("No waiting job set, unable to put waiting job into waiting state");
}
}
代码示例来源:origin: opencast/opencast
List<ServiceRegistration> registrations = getServiceRegistrationsByLoad(job.getJobType());
if (registrations.size() == 0)
throw new ServiceUnavailableException("No service is available to handle jobs of type '" + job.getJobType() + "'");
job.setStatus(Status.DISPATCHING);
try {
job = updateJob(job);
jobHosts.put(inMemoryRegistration, jobs);
if (!service.isReadyToAcceptJobs(job.getOperation())) {
jobs.remove(job);
jobHosts.put(inMemoryRegistration, jobs);
内容来源于网络,如有侵权,请联系作者删除!