⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 capsdconfigfactory.java

📁 opennms得相关源码 请大家看看
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            m_plugin = plugin;            m_protocol = proto;            m_parameters = params;            m_action = action;        }        /**         * Returns the protocol name         */        public String getProtocol() {            return m_protocol;        }        /**         * Returns the plugin module         */        public Plugin getPlugin() {            return m_plugin;        }        /**         * Returns the input parameters for the plugin         */        public Map getParameters() {            return m_parameters;        }        /**         * Returns true if the configuration has this particular module set as         * automaticall enabled.         *          */        public boolean autoEnabled() {            return m_action == CapsdConfigFactory.AUTO_SET;        }    } // end ProtocolInfo    /**     * <P>     * LightWeightIfEntry is designed to hold specific information about an IP     * interface in the database such as its IP address, its parent node id, and     * its managed status and represents a lighter weight version of the     * DbIpInterfaceEntry class.     * </P>     */    private static final class LightWeightIfEntry {        /**         * Represents NULL value for 'ifIndex' field in the ipInterface table         */        final static int NULL_IFINDEX = -1;        final static int NULL_IFTYPE = -1;        final static int LOOPBACK_IFTYPE = 24;        private int m_nodeId;        private int m_ifIndex;        private int m_ifType;        private String m_address;        private char m_managementState;        private char m_snmpPrimaryState;        private boolean m_primaryStateChanged;        /**         * <P>         * Constructs a new LightWeightIfEntry object.         * </P>         *          * @param nodeId         *            Interface's parent node id         * @param ifIndex         *            Interface's index         * @param address         *            Interface's ip address         * @param managementState         *            Interface's management state         * @param snmpPrimaryState         *            Interface's primary snmp interface state         * @param ifType         *            Interface's type as determined via SNMP         */        public LightWeightIfEntry(int nodeId, int ifIndex, String address, char managementState, char snmpPrimaryState, int ifType) {            m_nodeId = nodeId;            m_ifIndex = ifIndex;            m_address = address;            m_managementState = managementState;            m_snmpPrimaryState = snmpPrimaryState;            m_ifType = ifType;            m_primaryStateChanged = false;        }        /**         * <P>         * Returns the IP address of the interface.         * </P>         */        public String getAddress() {            return m_address;        }        /**         * <P>         * Returns the parent node id of the interface.         * </P>         */        public int getNodeId() {            return m_nodeId;        }        /**         * <P>         * Returns the ifIndex of the interface.         * </P>         */        public int getIfIndex() {            return m_ifIndex;        }        /**         * <P>         * Returns the ifType of the interface.         * </P>         */        public int getIfType() {            return m_ifType;        }        /**         *          */        public char getManagementState() {            return m_managementState;        }        /**         *          */        public char getSnmpPrimaryState() {            return m_snmpPrimaryState;        }        /**         *          */        public void setSnmpPrimaryState(char state) {            if (state != m_snmpPrimaryState) {                m_snmpPrimaryState = state;                m_primaryStateChanged = true;            }        }        /**         *          */        public boolean hasSnmpPrimaryStateChanged() {            return m_primaryStateChanged;        }    }    /**     * Constructs a new CapsdConfigFactory object for access to the Capsd     * configuration information.     *      * In addition to loading the configuration from the capsd-configuration.xml     * file the constructor also inserts any plugins defined in the     * configuration but not in the database into the 'service' table.     *      * @param configFile     *            The configuration file to load.     * @exception java.io.IOException     *                Thrown if the specified config file cannot be read     * @exception org.exolab.castor.xml.MarshalException     *                Thrown if the file does not conform to the schema.     * @exception org.exolab.castor.xml.ValidationException     *                Thrown if the contents do not match the required schema.     */    private CapsdConfigFactory(String configFile) throws IOException, MarshalException, ValidationException {        InputStream cfgIn = new FileInputStream(configFile);        m_config = (CapsdConfiguration) Unmarshaller.unmarshal(CapsdConfiguration.class, new InputStreamReader(cfgIn));        cfgIn.close();        // now load the plugins!        // Map by protocol name and also by class name!        //        Enumeration eprotos = m_config.enumerateProtocolPlugin();        while (eprotos.hasMoreElements()) {            ProtocolPlugin plugin = (ProtocolPlugin) eprotos.nextElement();            try {                if (m_plugins.containsKey(plugin.getClassName())) {                    Object oplugin = m_plugins.get(plugin.getClassName());                    m_plugins.put(plugin.getProtocol(), oplugin);                } else {                    Class cplugin = Class.forName(plugin.getClassName());                    Object oplugin = cplugin.newInstance();                    // map them                    //                    m_plugins.put(plugin.getClassName(), oplugin);                    m_plugins.put(plugin.getProtocol(), oplugin);                }            } catch (Throwable t) {                ThreadCategory.getInstance(getClass()).error("CapsdConfigFactory: failed to load plugin for protocol " + plugin.getProtocol() + ", class-name = " + plugin.getClassName(), t);            }        }        // load address from any specified URLs        //        // Load addresses from any urls which have been specified        //        m_urlMap = new HashMap();        Enumeration e = m_config.enumerateIpManagement();        while (e.hasMoreElements()) {            IpManagement mgt = (IpManagement) e.nextElement();            Enumeration f = mgt.enumerateIncludeUrl();            while (f.hasMoreElements()) {                String url = f.nextElement().toString();                if (!m_urlMap.containsKey(url))                    m_urlMap.put(url, getAddressesFromURL(url));            }        }    }    /**     * Load the config from the default config file and create the singleton     * instance of this factory.     *      * @exception java.io.IOException     *                Thrown if the specified config file cannot be read     * @exception org.exolab.castor.xml.MarshalException     *                Thrown if the file does not conform to the schema.     * @exception org.exolab.castor.xml.ValidationException     *                Thrown if the contents do not match the required schema.     */    public static synchronized void init() throws IOException, MarshalException, ValidationException {        if (m_loaded) {            // init already called - return            // to reload, reload() will need to be called            return;        }        File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.CAPSD_CONFIG_FILE_NAME);        ThreadCategory.getInstance(CapsdConfigFactory.class).debug("init: config file path: " + cfgFile.getPath());        m_singleton = new CapsdConfigFactory(cfgFile.getPath());        m_loaded = true;    }    /**     * Reload the config from the default config file     *      * @exception java.io.IOException     *                Thrown if the specified config file cannot be read/loaded     * @exception org.exolab.castor.xml.MarshalException     *                Thrown if the file does not conform to the schema.     * @exception org.exolab.castor.xml.ValidationException     *                Thrown if the contents do not match the required schema.     */    public static synchronized void reload() throws IOException, MarshalException, ValidationException {        m_singleton = null;        m_loaded = false;        init();    }    /**     * Return the singleton instance of this factory.     *      * @return The current factory instance.     *      * @throws java.lang.IllegalStateException     *             Thrown if the factory has not yet been initialized.     */    public static synchronized CapsdConfigFactory getInstance() {        if (!m_loaded)            throw new IllegalStateException("The factory has not been initialized");        return m_singleton;    }    /**     * Return the Capsd configuration object.     */    public CapsdConfiguration getConfiguration() {        return m_config;    }    /**     * This method is responsible for sync'ing the content of the 'service'     * table with the protocols listed in the caspd-configuration.xml file.     *      * First a list of services currently contained in the 'service' table in     * the database is built.     *      * Next, the list of services defined in capsd-configuration.xml is iterated     * over and if any services are defined but do not yet exist in the     * 'service' table they are added to the table.     *      * Finally, the list of services in the database is iterated over and if any     * service exists in the database but is no longer listed in the     * capsd-configuration.xml file then that the following occurs:     * 

⌨️ 快捷键说明

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