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 javax.management.*;
022
023/**
024 * Notification sent to provide information about a task that was executed in a node.
025 * @author Laurent Cohen
026 */
027public class TaskExecutionNotification extends OffloadableNotification {
028  /**
029   * Explicit serialVersionUID.
030   */
031  private static final long serialVersionUID = 1L;
032  /**
033   * Information about the task that triggered this notification.
034   */
035  private final TaskInformation taskInformation;
036  /**
037   * Determines whether this is a user-defined notification sent from a task.
038   */
039  private final boolean userNotification;
040
041  /**
042   * Initialize this notification with the specified parameters.
043   * @param source the emitter MBean's object name.
044   * @param sequenceNumber the notification sequence number.
045   * @param taskInformation information about the task that triggered this notification.
046   * @param userObject an user-defined object sent along with this notification.
047   * @param userNotification determines whether this is a user-defined notification sent from a task.
048   */
049  public TaskExecutionNotification(final ObjectName source, final long sequenceNumber, final TaskInformation taskInformation, final Object userObject, final boolean userNotification) {
050    super("task.monitor", source, sequenceNumber, taskInformation.getTimestamp());
051    this.taskInformation = taskInformation;
052    this.userNotification = userNotification;
053    setUserData(userObject);
054  }
055
056  /**
057   * Get the object encapsulating information about the task.
058   * @return a <code>TaskInformation</code> instance.
059   */
060  public TaskInformation getTaskInformation() {
061    return taskInformation;
062  }
063
064  /**
065   * Determine whether this is a user-defined notification sent from a task.
066   * @return {@code true} if this is a user notification, {@code false} otherwise.
067   * @since 4.1
068   */
069  public boolean isUserNotification() {
070    return userNotification;
071  }
072
073  @Override
074  public String toString() {
075    return new StringBuilder(getClass().getSimpleName()).append('[')
076      .append("source=").append(getSource())
077      .append(", type=").append(getType())
078      .append(", taskInfo=").append(taskInformation)
079      .append(", sequence=").append(getSequenceNumber())
080      .append(']').toString();
081  }
082}