001/*
002 * JPPF.
003 * Copyright (C) 2005-2016 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.forwarding;
020
021import java.util.concurrent.atomic.AtomicLong;
022
023import javax.management.Notification;
024
025/**
026 * Instances of this notification class wrap any JMX notification received from a node.
027 * They provide additional information to allow users to know from which node and which MBean the notification was emitted.
028 * @author Laurent Cohen
029 */
030public class JPPFNodeForwardingNotification extends Notification {
031  /**
032   * Internal notification sequence number.
033   */
034  private final static AtomicLong sequence = new AtomicLong(0L);
035  /**
036   * The notification to forward.
037   */
038  private final Notification notification;
039  /**
040   * The uuid of the originating node.
041   */
042  private final String nodeUuid;
043  /**
044   * The name of the originating MBean in the node.
045   */
046  private final String mBeanName;
047
048  /**
049   * Initialize this notification with the actual node notification that was received.
050   * @param notification the notification to forward.
051   * @param nodeUuid the uuid of the originating node.
052   * @param mBeanName name of the originating MBean in the node.
053   */
054  public JPPFNodeForwardingNotification(final Notification notification, final String nodeUuid, final String mBeanName) {
055    super("NodeForwardingNotification", JPPFNodeForwardingMBean.MBEAN_NAME, sequence.incrementAndGet());
056    this.notification = notification;
057    this.nodeUuid = nodeUuid;
058    this.mBeanName = mBeanName;
059  }
060
061  /**
062   * Get the notification forwarded from the node.
063   * @return an instance of <code>Notification</code>.
064   */
065  public Notification getNotification() {
066    return notification;
067  }
068
069  /**
070   * Get the uuid of the originating node.
071   * @return the node uuid as a string.
072   */
073  public String getNodeUuid() {
074    return nodeUuid;
075  }
076
077  /**
078   * Get the name of the originating MBean in the node.
079   * @return the MBean name as a string.
080   */
081  public String getMBeanName() {
082    return mBeanName;
083  }
084
085  @Override
086  public String toString() {
087    StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append('[');
088    sb.append("type").append(getType());
089    sb.append(", source").append(getSource());
090    sb.append(", mBeanName").append(mBeanName);
091    sb.append(", nodeUuid").append(nodeUuid);
092    sb.append(", sequenceNumber").append(getSequenceNumber());
093    sb.append(", timeStamp").append(getTimeStamp());
094    sb.append(", notification").append(notification);
095    return sb.toString();
096  }
097}