thresholdableservice.java

来自「opennms得相关源码 请大家看看」· Java 代码 · 共 531 行 · 第 1/2 页

JAVA
531
字号
//// This file is part of the OpenNMS(R) Application.//// OpenNMS(R) is Copyright (C) 2002-2003 The OpenNMS Group, Inc.  All rights reserved.// OpenNMS(R) is a derivative work, containing both original code, included code and modified// code that was published under the GNU General Public License. Copyrights for modified // and included code are below.//// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.//// Modifications://// 2003 Jan 31: Cleaned up some unused imports.//// Original code base Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.//       // For more information contact: //      OpenNMS Licensing       <license@opennms.org>//      http://www.opennms.org///      http://www.opennms.com///package org.opennms.netmgt.threshd;import java.net.InetAddress;import java.net.UnknownHostException;import java.util.Collections;import java.util.Enumeration;import java.util.Iterator;import java.util.Map;import java.util.TreeMap;import org.apache.log4j.Category;import org.opennms.core.utils.ThreadCategory;import org.opennms.netmgt.EventConstants;import org.opennms.netmgt.config.PollOutagesConfigFactory;import org.opennms.netmgt.config.threshd.Parameter;import org.opennms.netmgt.config.ThreshdConfigFactory;import org.opennms.netmgt.config.threshd.Service;import org.opennms.netmgt.poller.monitors.IPv4NetworkInterface;import org.opennms.netmgt.scheduler.ReadyRunnable;import org.opennms.netmgt.scheduler.Scheduler;import org.opennms.netmgt.utils.EventProxy;import org.opennms.netmgt.xml.event.Event;/** * <P> * The ThresholdableService class ... * </P> *  * @author <A HREF="mailto:mike@opennms.org">Mike Davidson </A> * @author <A HREF="http://www.opennms.org/">OpenNMS </A> *  */final class ThresholdableService extends IPv4NetworkInterface implements ReadyRunnable {    /**     * Interface's parent node identifier     */    private int m_nodeId;    /**     * The package information for this interface/service pair     */    private org.opennms.netmgt.config.threshd.Package m_package;    /**     * The service informaion for this interface/service pair     */    private final Service m_service;    /**     * Last known/current status     */    private int m_status;    /**     * The last time a threshold check ocurred     */    private long m_lastThresholdCheckTime;    /**     * The last time this service was scheduled for threshold checking.     */    private long m_lastScheduledThresholdCheckTime;    /**     * The proxy used to send events.     */    private final EventProxy m_proxy;    /**     * The scheduler for threshd     */    private final Scheduler m_scheduler;    /**     * Service updates     */    private ThresholderUpdates m_updates;    /**     *      */    private static final boolean ABORT_THRESHOLD_CHECK = true;    /**     * The map of thresholding parameters     */    private static Map m_properties = new TreeMap();    private ServiceThresholder m_thresholder;    /**     * The key used to lookup the service properties that are passed to the     * thresholder.     */    private final String m_svcPropKey;    /**     * The map of service parameters. These parameters are mapped by the     * composite key <em>(package name, service name)</em>.     */    private static Map SVC_PROP_MAP = Collections.synchronizedMap(new TreeMap());    /**     * Constructs a new instance of a ThresholdableService object.     *      * @param dbNodeId     *            The database identifier key for the interfaces' node     * @param address     *            InetAddress of the interface to collect from     * @param svcName     *            Service name     * @param pkg     *            The package containing parms for this collectable service.     *      */    ThresholdableService(int dbNodeId, InetAddress address, String svcName, org.opennms.netmgt.config.threshd.Package pkg) {        super(address);        m_nodeId = dbNodeId;        m_package = pkg;        m_status = ServiceThresholder.THRESHOLDING_SUCCEEDED;        m_proxy = Threshd.getInstance().getEventProxy();        m_scheduler = Threshd.getInstance().getScheduler();        m_thresholder = Threshd.getInstance().getServiceThresholder(svcName);        m_updates = new ThresholderUpdates();        // Initialize last scheduled threshold check and last threshold        // check times to current time.        m_lastScheduledThresholdCheckTime = System.currentTimeMillis();        m_lastThresholdCheckTime = System.currentTimeMillis();        // find the service matching the name        //        Service svc = null;        Enumeration esvc = m_package.enumerateService();        while (esvc.hasMoreElements()) {            Service s = (Service) esvc.nextElement();            if (s.getName().equalsIgnoreCase(svcName)) {                svc = s;                break;            }        }        if (svc == null)            throw new RuntimeException("Service name not part of package!");        // save reference to the service        m_service = svc;        // add property list for this service/package combination if        // it doesn't already exist in the service property map        //        m_svcPropKey = m_package.getName() + "." + m_service.getName();        synchronized (SVC_PROP_MAP) {            if (!SVC_PROP_MAP.containsKey(m_svcPropKey)) {                Map m = Collections.synchronizedMap(new TreeMap());                Enumeration ep = m_service.enumerateParameter();                while (ep.hasMoreElements()) {                    Parameter p = (Parameter) ep.nextElement();                    m.put(p.getKey(), p.getValue());                }                // Add configured service 'interval' attribute as                // a property as well. Needed by the ServiceThresholder                // check() method in order to generate the                // correct rrdtool fetch command.                m.put("interval", Integer.toString((int) m_service.getInterval()));                SVC_PROP_MAP.put(m_svcPropKey, m);            }        }    }    /**     * Returns node identifier     */    public int getNodeId() {        return m_nodeId;    }    /**     * Set node identifier     */    public void setNodeId(int nodeId) {        m_nodeId = nodeId;    }    /**     * Returns the service name     */    public String getServiceName() {        return m_service.getName();    }    /**     * Returns the service name     */    public String getPackageName() {        return m_package.getName();    }    /**    * Uses the existing package name to try and re-obtain the package from the threshd config factory.    * Should be called when the threshd config has been reloaded.    */    public void refreshPackage() {	org.opennms.netmgt.config.threshd.Package refreshedPackage=ThreshdConfigFactory.getInstance().getPackage(this.getPackageName());	if(refreshedPackage!=null) {		this.m_package=refreshedPackage;	}    }    /**     * Returns updates object     */    public ThresholderUpdates getThresholderUpdates() {        return m_updates;    }    /**     * This method is used to evaluate the status of this interface and service     * pair. If it is time to run the threshold check again then a value of true     * is returned. If the interface is not ready then a value of false is     * returned.     */    public boolean isReady() {        boolean ready = false;        if (!Threshd.getInstance().isSchedulingCompleted())            return false;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?