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 org.jppf.client.monitoring.topology.TopologyNode;
022import org.jppf.job.JobInformation;
023
024/**
025 * This class represents the dispatch of a job to a node.
026 * @author Laurent Cohen
027 * @since 5.1
028 */
029public class JobDispatch extends AbstractJobComponent {
030  /**
031   * Explicit serialVersionUID.
032   */
033  private static final long serialVersionUID = 1L;
034  /**
035   * Information on the node.
036   */
037  private transient final TopologyNode node;
038  /**
039   * Information on the job.
040   */
041  private transient final JobInformation jobInfo;
042
043  /**
044   * Initialize this job with the supplied information.
045   * @param jobInfo information on the job.
046   * @param node information on the node.
047   */
048  JobDispatch(final JobInformation jobInfo, final TopologyNode node) {
049    super(node.getUuid());
050    this.jobInfo = jobInfo;
051    this.node = node;
052  }
053
054  /**
055   * Get the information on the node for ths job dispatch.
056   * @return a {@link TopologyNode} instance.
057   */
058  public TopologyNode getNode() {
059    return node;
060  }
061
062  /**
063   * Get the job to which this dispatch belongs.
064   * @return a {@link Job} instance.
065   */
066  public Job getJob() {
067    return (Job) getParent();
068  }
069
070  /**
071   * Get the information on the job.
072   * @return an instance of {@link JobInformation}.
073   */
074  public synchronized JobInformation getJobInformation() {
075    return jobInfo;
076  }
077
078  @Override
079  public String toString() {
080    final StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append('[');
081    sb.append("uuid=").append(uuid);
082    sb.append(", jobInfo=").append(jobInfo);
083    sb.append(", node=").append(node);
084    sb.append(']');
085    return sb.toString();
086  }
087
088
089  @Override
090  public String getDisplayName() {
091    return node != null ? node.getDisplayName() : "" + uuid;
092  }
093}