本文整理了Java中org.opencastproject.job.api.Job.getId()
方法的一些代码示例,展示了Job.getId()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Job.getId()
方法的具体详情如下:
包路径:org.opencastproject.job.api.Job
类名称:Job
方法名:getId
[英]Gets the job identifier.
[中]获取作业标识符。
代码示例来源:origin: opencast/opencast
@Override protected String process(Job job) throws Exception {
log.info("Processing job %d", job.getId());
return PAYLOAD;
}
代码示例来源:origin: opencast/opencast
/**
* Constructs a new job runner
*
* @param job
* the job to run
* @param currentJob
* the current running job
*/
JobRunner(Job job, Job currentJob) {
jobId = job.getId();
if (currentJob != null) {
currentJobId = some(currentJob.getId());
} else {
currentJobId = none();
}
}
代码示例来源: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
private void deleteChildJobs(EntityManager em, EntityTransaction tx, long jobId) throws ServiceRegistryException {
List<Job> childJobs = getChildJobs(jobId);
if (childJobs.isEmpty()) {
logger.debug("No child jobs of job '{}' found to delete.", jobId);
return;
}
logger.debug("Start deleting child jobs of job '{}'", jobId);
try {
for (int i = childJobs.size() - 1; i >= 0; i--) {
Job job = childJobs.get(i);
JpaJob jobToDelete = em.find(JpaJob.class, job.getId());
em.remove(jobToDelete);
removeFromLoadCache(job.getId());
logger.debug("Job '{}' deleted", job.getId());
}
logger.debug("Deleted all child jobs of job '{}'", jobId);
} catch (Exception e) {
logger.error("Unable to remove child jobs from {}: {}", jobId, e);
if (tx.isActive()) {
tx.rollback();
}
throw new ServiceRegistryException(e);
}
}
代码示例来源:origin: opencast/opencast
private File customAnimation(final Job job, final URI input, final Map<String, String> metadata)
throws IOException, NotFoundException {
logger.debug("Start customizing the animation");
File output = new File(workspace.rootDirectory(), String.format("animate/%d/%s.%s", job.getId(),
FilenameUtils.getBaseName(input.getPath()), FilenameUtils.getExtension(input.getPath())));
FileUtils.forceMkdirParent(output);
String animation;
try {
animation = FileUtils.readFileToString(new File(input), "UTF-8");
} catch (IOException e) {
// Maybe no local file?
logger.debug("Falling back to workspace to read {}", input);
try (InputStream in = workspace.read(input)) {
animation = IOUtils.toString(in, "UTF-8");
}
}
// replace all metadata
for (Map.Entry<String, String> entry: metadata.entrySet()) {
String value = StringEscapeUtils.escapeXml11(entry.getValue());
animation = animation.replaceAll("\\{\\{" + entry.getKey() + "\\}\\}", value);
}
// write new animation file
FileUtils.write(output, animation, "utf-8");
return output;
}
代码示例来源:origin: opencast/opencast
/**
* Creates a wrapper for <code>job</code>, using <code>registry</code> to poll for the job outcome. The
* <code>waiter</code> is the job which is waiting for the other jobs to finish.
*
* @param jobs
* the job to poll
* @param registry
* the registry
* @param pollingInterval
* the time in miliseconds between two polling operations
* @param waiter
* the job waiting for the other jobs to finish
*/
public JobBarrier(Job waiter, ServiceRegistry registry, long pollingInterval, Job... jobs) {
if (registry == null)
throw new IllegalArgumentException("Service registry must not be null");
if (jobs == null)
throw new IllegalArgumentException("Jobs must not be null");
if (pollingInterval < 0)
throw new IllegalArgumentException("Polling interval must be a positive number");
this.serviceRegistry = registry;
this.pollingInterval = pollingInterval;
if (waiter != null)
this.waiterJobId = Opt.some(waiter.getId());
else
this.waiterJobId = Opt.none();
this.jobs = new ArrayList<Job>(Arrays.asList(jobs));
}
代码示例来源:origin: opencast/opencast
/**
* {@inheritDoc}
*
* @see org.opencastproject.serviceregistry.api.ServiceRegistry#updateJob(org.opencastproject.job.api.Job)
*/
@Override
public Job updateJob(Job job) throws NotFoundException, ServiceRegistryException {
if (job == null)
throw new IllegalArgumentException("Job cannot be null");
Job updatedJob = null;
synchronized (jobs) {
try {
updatedJob = updateInternal(job);
jobs.put(updatedJob.getId(), JobParser.toXml(new JaxbJob(updatedJob)));
} catch (IOException e) {
throw new IllegalStateException("Error serializing job", e);
}
}
return updatedJob;
}
代码示例来源:origin: opencast/opencast
String content = EntityUtils.toString(response.getEntity());
Job r = JobParser.parseJob(content);
logger.info("Converting job {} started on a remote caption service", r.getId());
return r;
代码示例来源:origin: opencast/opencast
/**
* Get the latest state of a job. Does not modify the <code>job</code> parameter.
*
* @return the updated job or none, if it cannot be found
*/
public static Opt<Job> update(ServiceRegistry reg, Job job) throws ServiceRegistryException {
try {
return Opt.some(reg.getJob(job.getId()));
} catch (NotFoundException e) {
return Opt.none();
}
}
代码示例来源: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
@Override
public Incident storeIncident(Job job, Date timestamp, String code, Incident.Severity severity,
Map<String, String> descriptionParameters, List<Tuple<String, String>> details)
throws IncidentServiceException, IllegalStateException {
try {
job = getServiceRegistry().getJob(job.getId());
final IncidentDto dto = getPenv().tx(
Queries.persist(IncidentDto.mk(job.getId(), timestamp, code, severity, descriptionParameters, details)));
return toIncident(job, dto);
} catch (NotFoundException e) {
throw new IllegalStateException("Can't create incident for not-existing job");
} catch (Exception e) {
logger.error("Could not store job incident: {}", e.getMessage());
throw new IncidentServiceException(e);
}
}
代码示例来源:origin: opencast/opencast
private List<IncidentTree> getChildIncidents(long jobId) throws NotFoundException, ServiceRegistryException,
IncidentServiceException {
List<Job> childJobs = getServiceRegistry().getChildJobs(jobId);
List<IncidentTree> incidentResults = new ArrayList<IncidentTree>();
for (Job childJob : childJobs) {
if (childJob.getParentJobId() != jobId)
continue;
List<Incident> incidentsForJob = getIncidentsOfJob(childJob.getId());
IncidentTree incidentTree = new IncidentTreeImpl(incidentsForJob, getChildIncidents(childJob.getId()));
if (hasIncidents(Collections.list(incidentTree)))
incidentResults.add(incidentTree);
}
return incidentResults;
}
代码示例来源: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 suspendWaiterJob() {
if (this.waiterJobId.isSome()) {
try {
final Job waiter = serviceRegistry.getJob(waiterJobId.get());
waiter.setStatus(Job.Status.WAITING);
List<Long> blockedForJobs = new LinkedList<Long>();
for (Job j : jobs) {
try {
if (setBlockerJob(j, waiter)) {
blockedForJobs.add(j.getId());
}
} catch (OptimisticLockException e) {
// Try again, this happens if the job finishes before we get here
// If the same exception happens again then we're in a very weird state
if (setBlockerJob(j, waiter)) {
blockedForJobs.add(j.getId());
}
}
}
waiter.setBlockedJobIds(blockedForJobs);
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
/**
* 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
private List<Incident> getIncidentsOfJob(long jobId) throws NotFoundException, IncidentServiceException {
final Job job = findJob(jobId);
try {
return mlist(getPenv().tx(IncidentDto.findByJobId(jobId))).map(toIncident(job)).value();
} catch (Exception e) {
logger.error("Could not retrieve incidents of job '{}': {}", job.getId(), e.getMessage());
throw new IncidentServiceException(e);
}
}
代码示例来源: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
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
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
public static JpaJob from(Job job) {
JpaJob newJob = new JpaJob();
newJob.id = job.getId();
newJob.dateCompleted = job.getDateCompleted();
newJob.dateCreated = job.getDateCreated();
newJob.dateStarted = job.getDateStarted();
newJob.queueTime = job.getQueueTime();
newJob.runTime = job.getRunTime();
newJob.version = job.getVersion();
newJob.payload = job.getPayload();
newJob.jobType = job.getJobType();
newJob.operation = job.getOperation();
newJob.arguments = job.getArguments();
newJob.status = job.getStatus().ordinal();
newJob.parentJobId = job.getParentJobId();
newJob.rootJobId = job.getRootJobId();
newJob.dispatchable = job.isDispatchable();
newJob.uri = job.getUri();
newJob.creator = job.getCreator();
newJob.organization = job.getOrganization();
newJob.jobLoad = job.getJobLoad();
newJob.blockedJobIds = job.getBlockedJobIds();
newJob.blockingJobId = job.getBlockingJobId();
return newJob;
}
内容来源于网络,如有侵权,请联系作者删除!