Package org.snmp4j.agent.mo.jmx

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

/*_############################################################################
  _##
  _##  SNMP4J-AgentJMX - JMXDefaultMOFactory.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 javax.management.*;

import org.snmp4j.agent.*;
import org.snmp4j.agent.mo.*;
import org.snmp4j.smi.*;
import org.snmp4j.agent.mo.snmp.tc.TextualConvention;


/**
* The <code>JMXDefaultMOFactory</code> extends the default SNMP4J-Agent
* {@link ManagedObject} factory to create {@link MOScalarJMX} and
* {@link MOTableJMX} instances instead of {@link MOScalar} and
* {@link DefaultMOTable} instances respectively.
* <p>
* Scalars are created ready-to-use with the supplied or a default
* JMXScalarSupport instance. For tables, a {@link DefaultMOMutableTableModel}
* is created at initialization that need to be replaced externally by
* a {@link JMXTableModel} to instrument a table with JMX.
*
* @author Frank Fock
* @version 1.0
*/
public class JMXDefaultMOFactory extends DefaultMOFactory {

  private MBeanServerConnection server;
  private JMXScalarSupport scalarSupport;

  /**
   * Creates a <code>JMXDefaultMOFactory</code> instance backed by the specified
   * MBean server. If the <code>JMXScalarSupport</code> member is not set before
   * the factory is used, a default <code>MBeanAttributeMOScalarSupport</code>
   * is used.
   * @param server
   *    the MBeanServerConnection to be used by this JMXDefaultMOFactory.
   */
  public JMXDefaultMOFactory(MBeanServerConnection server) {
    this(server, null);
  }

  /**
   * Creates a <code>JMXDefaultMOFactory</code> instance backed by the specified
   * MBean server and using the supplied JMXScalarSupport instance to create
   * scalars.
   *
   * @param server MBeanServerConnection
   * @param scalarSupport JMXScalarSupport
   */
  public JMXDefaultMOFactory(MBeanServerConnection server,
                             JMXScalarSupport scalarSupport) {
    this.server = server;
    this.scalarSupport = scalarSupport;
  }

  public synchronized JMXScalarSupport getScalarSupport() {
    if (scalarSupport == null) {
      scalarSupport = new MBeanAttributeMOScalarSupport(server);
    }
    return scalarSupport;
  }

  public MBeanServerConnection getServer() {
    return server;
  }

  public synchronized void setScalarSupport(JMXScalarSupport scalarSupport) {
    this.scalarSupport = scalarSupport;
  }

  public MOScalar createScalar(OID id, MOAccess access, Variable value) {
    return new MOScalarJMX(getScalarSupport(), id, access, value);
  }

  public MOScalar createScalar(OID id, MOAccess access, Variable value,
                               String tcModuleName, String textualConvention) {
    TextualConvention tc =
        getTextualConvention(tcModuleName, textualConvention);
    if (tc != null) {
      return tc.createScalar(id, access, value);
    }
    return createScalar(id, access, value);
  }

  public MOTable createTable(OID oid, MOTableIndex indexDef, MOColumn[] columns,
                             MOTableModel model) {
    return new MOTableJMX(oid, indexDef, columns,
                          createTableModel(oid, indexDef, columns));
  }

  public MOTable createTable(OID oid, MOTableIndex indexDef, MOColumn[] columns) {
    return new MOTableJMX(oid, indexDef, columns,
                          createTableModel(oid, indexDef, columns));
  }
}
TOP

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

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.