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.client.monitoring.topology.TopologyDriver;
024import org.jppf.server.job.management.DriverJobManagementMBean;
025
026/**
027 * AN instance of this class represents a JPPF driver in the jobs hierarchy.
028 * It is essentially a container for a {@link TopologyDriver} with the additional ability to navigate the jobs hierarchy, which is orthogonal to the topology hierarchy.
029 * @author Laurent Cohen
030 * @since 5.1
031 */
032public class JobDriver extends AbstractJobComponent {
033  /**
034   * Explicit serialVersionUID.
035   */
036  private static final long serialVersionUID = 1L;
037  /**
038   * The associated driver from the topology monitor.
039   */
040  private transient final TopologyDriver driver;
041
042  /**
043   * Initialize this job driver with the specified topology driver.
044   * @param driver the object that represent a JPPF driver.
045   */
046  JobDriver(final TopologyDriver driver) {
047    super(driver.getUuid());
048    this.driver = driver;
049  }
050
051  /**
052   * Get the proxy to the driver MBean that manages and monitors jobs.
053   * @return an instance of {@link DriverJobManagementMBean}.
054   */
055  public DriverJobManagementMBean getJobManager() {
056    return driver.getJobManager();
057  }
058
059  /**
060   * Get the associated driver from the topology monitor.
061   * @return an instance of {@link TopologyDriver}.
062   */
063  public TopologyDriver getTopologyDriver() {
064    return driver;
065  }
066
067  /**
068   * Get a job handled by this driver from its uuid.
069   * @param jobUuid the uuid of the job to retrieve.
070   * @return a {@link Job} instance, or {@code null} if the driver has no such job.
071   */
072  public Job getJob(final String jobUuid) {
073    return (Job) getChild(jobUuid);
074  }
075
076  /**
077   * Get the list of jobs handled by this driver.
078   * @return a list of {@link Job} instances, possibly empty.
079   */
080  public List<Job> getJobs() {
081    final List<Job> list = new ArrayList<>(getChildCount());
082    for (final AbstractJobComponent comp: getChildren()) list.add((Job) comp);
083    return list;
084  }
085
086  @Override
087  public String toString() {
088    final StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append('[');
089    sb.append("uuid=").append(uuid);
090    sb.append(", driver=").append(driver);
091    sb.append(']');
092    return sb.toString();
093  }
094
095  @Override
096  public String getDisplayName() {
097    return driver != null ? driver.getDisplayName() : "" + uuid;
098  }
099}