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.management;
020
021import java.io.Serializable;
022
023/**
024 * Instances of this class encapsulate runtime information on tasks executed by a node.
025 * @author Laurent Cohen
026 */
027public class TaskInformation implements Serializable {
028  /**
029   * Explicit serialVersionUID.
030   */
031  private static final long serialVersionUID = 1L;
032  /**
033   * The task id.
034   */
035  private final String id;
036  /**
037   * The id of the job this task belongs to.
038   */
039  private final String jobId;
040  /**
041   * The name of the job this task belongs to.
042   */
043  private final String jobName;
044  /**
045   * The cpu time taken by the task.
046   */
047  private final long cpuTime;
048  /**
049   * The wall clock time taken by the task.
050   */
051  private final long elapsedTime;
052  /**
053   * Determines whether the task had an exception.
054   */
055  private final boolean error;
056  /**
057   * Timestamp for the creation of this event.
058   */
059  private final long timestamp = System.currentTimeMillis();
060  /**
061   * The position of the task in the job to which it belongs.
062   * @since 5.0
063   */
064  private final int jobPosition;
065
066  /**
067   * Initialize this event object with the specified task.
068   * @param id the task id.
069   * @param jobId the id of the job this task belongs to.
070   * @param jobName the name of the job this task belongs to.
071   * @param cpuTime the cpu time taken by the task.
072   * @param elapsedTime the wall clock time taken by the task.
073   * @param error determines whether the task had an exception.
074   * @param jobPosition the position of the task in the job to which it belongs..
075   * @exclude
076   */
077  public TaskInformation(final String id, final String jobId, final String jobName, final long cpuTime, final long elapsedTime, final boolean error, final int jobPosition) {
078    this.id = id;
079    this.jobId = jobId;
080    this.jobName = jobName;
081    this.cpuTime = cpuTime;
082    this.elapsedTime = elapsedTime;
083    this.error = error;
084    this.jobPosition = jobPosition;
085  }
086
087  /**
088   * Get the task id.
089   * @return the id as a string.
090   */
091  public String getId() {
092    return id;
093  }
094
095  /**
096   * Get the id of the job this task belongs to.
097   * @return the job id as a string.
098   */
099  public String getJobId() {
100    return jobId;
101  }
102
103  /**
104   * Get the name of the job this task belongs to.
105   * @return the job name as a string.
106   */
107  public String getJobName() {
108    return jobName;
109  }
110
111  /**
112   * Get the cpu time taken by the task.
113   * @return the cpu time in milliseconds.
114   */
115  public long getCpuTime() {
116    return cpuTime;
117  }
118
119  /**
120   * Get the wall clock time taken by the task.
121   * @return the elapsed time in milliseconds.
122   */
123  public long getElapsedTime() {
124    return elapsedTime;
125  }
126
127  /**
128   * Determines whether the task had an exception.
129   * @return true if the task had an exception, false otherwise.
130   */
131  public boolean hasError() {
132    return error;
133  }
134
135  /**
136   * Get the timestamp for the creation of this event.
137   * @return the timestamp as a long value.
138   */
139  public long getTimestamp() {
140    return timestamp;
141  }
142
143  /**
144   * Get the position of the task in the job to which it belongs.
145   * @return the position of the task in its job as an int value.
146   * @since 5.0
147   */
148  public int getJobPosition() {
149    return jobPosition;
150  }
151
152  @Override
153  public String toString() {
154    return new StringBuilder(getClass().getSimpleName()).append('[')
155      .append("taskId=").append(id)
156      .append(", jobId=").append(jobId)
157      .append(", jobName=").append(jobName)
158      .append(", cpuTime=").append(cpuTime)
159      .append(", elapsedTime=").append(elapsedTime)
160      .append(", error=").append(error)
161      .append(", jobPosition=").append(jobPosition)
162      .append(']').toString();
163  }
164}