001/*
002 * JPPF.
003 * Copyright (C) 2005-2015 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   * Information on the node.
032   */
033  private final TopologyNode node;
034  /**
035   * Information on the job.
036   */
037  private final JobInformation jobInfo;
038
039  /**
040   * Initialize this job with the supplied information.
041   * @param jobInfo information on the job.
042   * @param node information on the node.
043   */
044  JobDispatch(final JobInformation jobInfo, final TopologyNode node) {
045    super(node.getUuid());
046    this.jobInfo = jobInfo;
047    this.node = node;
048  }
049
050  /**
051   * Get the information on the node for ths job dispatch.
052   * @return a {@link TopologyNode} instance.
053   */
054  public TopologyNode getNode() {
055    return node;
056  }
057
058  /**
059   * Get the job to which this dispatch belongs.
060   * @return a {@link Job} instance.
061   */
062  public Job getJob() {
063    return (Job) getParent();
064  }
065
066  /**
067   * Get the information on the job.
068   * @return an instance of {@link JobInformation}.
069   */
070  public synchronized JobInformation getJobInformation() {
071    return jobInfo;
072  }
073
074  @Override
075  public String toString() {
076    StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append('[');
077    sb.append("uuid=").append(uuid);
078    sb.append(", jobInfo=").append(jobInfo);
079    sb.append(", node=").append(node);
080    sb.append(']');
081    return sb.toString();
082  }
083
084
085  @Override
086  public String getDisplayName() {
087    return node != null ? node.getDisplayName() : "" + uuid;
088  }
089}