Package org.snmp4j.agent.mo.jmx

Source Code of org.snmp4j.agent.mo.jmx.MBeanNotificationInfo

/*_############################################################################
  _##
  _##  SNMP4J-AgentJMX - MBeanNotificationInfo.java 
  _##
  _##  Copyright (C) 2006-2009  Frank Fock (SNMP4J.org)
  _## 
  _##  This program is free software; you can redistribute it and/or modify
  _##  it under the terms of the GNU General Public License version 2 as
  _##  published by the Free Software Foundation.
  _##
  _##  This program is distributed in the hope that it will be useful,
  _##  but WITHOUT ANY WARRANTY; without even the implied warranty of
  _##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  _##  GNU General Public License for more details.
  _##
  _##  You should have received a copy of the GNU General Public License
  _##  along with this program; if not, write to the Free Software
  _##  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  _##  MA  02110-1301  USA
  _## 
  _##########################################################################*/

package org.snmp4j.agent.mo.jmx;

import org.snmp4j.smi.VariableBinding;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;

/**
* The <code>MBeanNotificationInfo</code> class represents information for
* a MBean notification to SNMP notification type mapping. Since MBean
* notifications contain payload information that does not include information
* about the payload's structural source. As a consequence, the payload cannot
* always be mapped to a SNMP notification without additional information about
* table indexing. This information is provided by a
* {@link JMXNotificationIndexSupport} instance then.
*
* @author Frank Fock
* @version 1.0
*/
public class MBeanNotificationInfo {

  private JMXNotificationIndexSupport indexSupport;
  private MBeanNotificationObjectInfo[] objects;
  private OctetString context = new OctetString();

  /**
   * Creates a notification mapping between a MBean notification to a SNMP
   * notification. The notification mapping uses the default context.
   * @param objects
   *    the mappings of the SNMP notification payload to MBean attributes.
   * @param indexSupport
   *    the index support instance that provides indexes for the notification
   *    payload object OIDs where necessary.
   */
  public MBeanNotificationInfo(MBeanNotificationObjectInfo[] objects,
                               JMXNotificationIndexSupport indexSupport) {
    this.indexSupport = indexSupport;
    this.objects = objects;
  }

  /**
   * Creates a notification mapping between a MBean notification to a SNMP
   * notification.
   * @param objects
   *    the mappings of the SNMP notification payload to MBean attributes.
   * @param indexSupport
   *    the index support instance that provides indexes for the notification
   *    payload object OIDs where necessary.
   * @param context
   *    the context of the notification. Default is a zero length string.
   */
  public MBeanNotificationInfo(MBeanNotificationObjectInfo[] objects,
                               JMXNotificationIndexSupport indexSupport,
                               OctetString context) {
    this(objects, indexSupport);
    this.context = context;
  }

  public VariableBinding[] getNotificationPayload(Object notificationObject) {
    VariableBinding[] vbs = new VariableBinding[objects.length];
    if (indexSupport != null) {
      synchronized (indexSupport) {
        indexSupport.intialize(notificationObject);
        for (int i=0; i<objects.length; i++) {
          MBeanNotificationObjectInfo oinfo = objects[i];
          OID index = indexSupport.getIndex(i);
          vbs[i] = oinfo.getVariableBinding(notificationObject, index);
        }
      }
    }
    else {
      for (int i=0; i<objects.length; i++) {
        MBeanNotificationObjectInfo oinfo = objects[i];
        vbs[i] = oinfo.getVariableBinding(notificationObject, null);
      }
    }
    return vbs;
  }

  public OctetString getContext() {
    return context;
  }

}
TOP

Related Classes of org.snmp4j.agent.mo.jmx.MBeanNotificationInfo

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.