001/*
002 * JPPF.
003 * Copyright (C) 2005-2016 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   * Information on the job.
033   */
034  private JobInformation jobInfo;
035
036  /**
037   * Initialize this job with the supplied information.
038   * @param jobInfo information on the job.
039   */
040  Job(final JobInformation jobInfo) {
041    super(jobInfo.getJobUuid());
042    this.jobInfo = jobInfo;
043  }
044
045  /**
046   * Set the information on the job.
047   * @param jobInfo an instance of {@link JobInformation}.
048   */
049  synchronized void setJobInformation(final JobInformation jobInfo) {
050    this.jobInfo = jobInfo;
051  }
052
053  /**
054   * Get the information on the job.
055   * @return an instance of {@link JobInformation}.
056   */
057  public synchronized JobInformation getJobInformation() {
058    return jobInfo;
059  }
060
061  /**
062   * Get the driver that holds this job.
063   * @return a {@link JobDriver} instance.
064   */
065  public JobDriver getJobDriver() {
066    return (JobDriver) getParent();
067  }
068
069  /**
070   * Get the dispatch with the specified node uuid for this job.
071   * @param nodeUuid the uuid of the node of the dispatch to retrieve.
072   * @return a {@link JobDispatch} instance, or {@code null} if thiere is nu such job dispatch.
073   */
074  public JobDispatch getJobDispatch(final String nodeUuid) {
075    return (JobDispatch) getChild(nodeUuid);
076  }
077
078  /**
079   * Get the job dispatches for this job.
080   * @return a list of {@link JobDispatch} instances, possibly empty.
081   */
082  public List<JobDispatch> getJobDispatches() {
083    List<JobDispatch> list = new ArrayList<>(getChildCount());
084    for (AbstractJobComponent child: getChildren()) list.add((JobDispatch) child);
085    return list;
086  }
087
088  @Override
089  public String toString() {
090    StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append('[');
091    sb.append("uuid=").append(uuid);
092    sb.append(", jobInfo=").append(jobInfo);
093    sb.append(']');
094    return sb.toString();
095  }
096
097  @Override
098  public String getDisplayName() {
099    return jobInfo != null ? jobInfo.getJobName() : "" + uuid;
100  }
101}