001/*
002 * JPPF.
003 * Copyright (C) 2005-2018 JPPF Team.
004 * http://www.jppf.org
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.jppf.client.monitoring.jobs;
020
021import java.util.*;
022
023import org.jppf.job.JobInformation;
024
025/**
026 * Instanes of this class represent a job as seen by a driver.
027 * @author Laurent Cohen
028 * @since 5.1
029 */
030public class Job extends AbstractJobComponent {
031  /**
032   * Explicit serialVersionUID.
033   */
034  private static final long serialVersionUID = 1L;
035  /**
036   * Information on the job.
037   */
038  private transient JobInformation jobInfo;
039
040  /**
041   * Initialize this job with the supplied information.
042   * @param jobInfo information on the job.
043   */
044  Job(final JobInformation jobInfo) {
045    super(jobInfo.getJobUuid());
046    this.jobInfo = jobInfo;
047  }
048
049  /**
050   * Set the information on the job.
051   * @param jobInfo an instance of {@link JobInformation}.
052   */
053  synchronized void setJobInformation(final JobInformation jobInfo) {
054    this.jobInfo = jobInfo;
055  }
056
057  /**
058   * Get the information on the job.
059   * @return an instance of {@link JobInformation}.
060   */
061  public synchronized JobInformation getJobInformation() {
062    return jobInfo;
063  }
064
065  /**
066   * Get the driver that holds this job.
067   * @return a {@link JobDriver} instance.
068   */
069  public JobDriver getJobDriver() {
070    return (JobDriver) getParent();
071  }
072
073  /**
074   * Get the dispatch with the specified node uuid for this job.
075   * @param nodeUuid the uuid of the node of the dispatch to retrieve.
076   * @return a {@link JobDispatch} instance, or {@code null} if thiere is nu such job dispatch.
077   */
078  public JobDispatch getJobDispatch(final String nodeUuid) {
079    return (JobDispatch) getChild(nodeUuid);
080  }
081
082  /**
083   * Get the job dispatches for this job.
084   * @return a list of {@link JobDispatch} instances, possibly empty.
085   */
086  public List<JobDispatch> getJobDispatches() {
087    final List<JobDispatch> list = new ArrayList<>(getChildCount());
088    for (final AbstractJobComponent child: getChildren()) list.add((JobDispatch) child);
089    return list;
090  }
091
092  @Override
093  public String toString() {
094    final StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append('[');
095    sb.append("uuid=").append(uuid);
096    sb.append(", jobInfo=").append(jobInfo);
097    sb.append(']');
098    return sb.toString();
099  }
100
101  @Override
102  public String getDisplayName() {
103    return jobInfo != null ? jobInfo.getJobName() : "" + uuid;
104  }
105}