ipgenerator.java
来自「opennms得相关源码 请大家看看」· Java 代码 · 共 480 行 · 第 1/2 页
JAVA
480 行
//// 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///// Tab Size = 8//package org.opennms.netmgt.discovery;import java.sql.SQLException;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.MissingResourceException;import java.util.NoSuchElementException;import org.apache.log4j.Category;import org.opennms.core.queue.FifoQueue;import org.opennms.core.queue.FifoQueueException;import org.opennms.core.utils.ThreadCategory;/** * * @author <A HREF="mailto:sowmya@opennms.org">Sowmya </A> * @author <A HREF="http://www.opennms.org/">OpenNMS </A> * */final class IPGenerator implements FifoQueue { /** * The specific list items to be iterated through */ private List m_specificAddresses; /** * The range of items to be enumerated through */ private List m_includeRanges; /** * The iterator used to cycle through the ranges. */ private Iterator m_iter; /** * Set true until the initial wait time is over. */ private boolean m_isInitial; /** * The system time when this instance was created. */ private long m_createTime; /** * Set to true if the end of the iterators has been reached and restarted. */ private boolean m_isRestarted; /** * The time the end of the iteration was reached in system milliseconds. */ private long m_restartTime; /** * The initial wait time. */ private long m_initialWait; /** * The time to wait between restarts. */ private long m_restartWait; /** * This class is used to chain a set of common iterators together so that * when on iterator is exhausted the next one is polled. This allows a set * of iterators to be treated as a single iterator. * * @author <a href="mailto:weave@oculan.com">Brian Weaver </a> * @author <a href="http://www.opennms.org/">OpenNMS </a> * */ static final class IteratorChain implements Iterator { /** * The chained list of iterators. */ private List m_iterators; /** * Constructs a new iterator chain */ IteratorChain() { m_iterators = new LinkedList(); } /** * Adds an iterator to the chain * * @param iter * The iterator to add. */ void add(Iterator iter) { m_iterators.add(iter); } /** * This method returns true if an iterator in the chain has a next * element. * * @return True if there is a next element. */ public boolean hasNext() { boolean rc = false; while (m_iterators.size() > 0 && !rc) { Iterator i = (Iterator) m_iterators.get(0); rc = i.hasNext(); if (!rc) m_iterators.remove(0); } return rc; } /** * This method returns the next element in the iterator chain. If there * are no elements remaining then an exception is generated. * * @return The next object in the chain. * * @throws java.util.NoSuchElementException * Thrown if there are no more elements. * */ public Object next() { Object obj = null; while (m_iterators.size() > 0 && obj == null) { Iterator i = (Iterator) m_iterators.get(0); if (i.hasNext()) obj = i.next(); else m_iterators.remove(0); } if (obj == null) throw new NoSuchElementException("No elements remain in the iterator chain"); return obj; } /** * Removes the current element from the iterator. This method is not * supported and always throws the exception * {@link java.lang.UnsupportedOperationException UnsupportedOperationException}. * * @throws java.lang.UnsupportedOperationException * Always Thrown. */ public void remove() { throw new UnsupportedOperationException("The remove method is not supported"); } } // end class IteratorChain /** * Synchronizes the Discovered IP Manager with the database. */ private void sync() { try { DiscoveredIPMgr.dataSourceSync(); } catch (SQLException sqlE) { ThreadCategory.getInstance(getClass()).error("Failed to synchronize discovered addresses with the database", sqlE); } catch (MissingResourceException fnfE) { ThreadCategory.getInstance(getClass()).error("Failed to synchronize discovered addresses with the database", fnfE); } } /** * This method is used to block a thread the generator is in a timed wait. * If there is no timed wait then the thread returns immediantly. If the * lock is not released in the time passed to the method then a false value * is returned. * * @param maxWait * The maximum time to wait, or zero for indefinite. * * @return True if the wait was successful. * */ private synchronized boolean doWait(long maxWait) throws InterruptedException { boolean completed = true; if (m_isInitial) { Category log = ThreadCategory.getInstance(getClass()); completed = false; long start = System.currentTimeMillis(); if (log.isDebugEnabled()) log.debug("doWait(initial): entry time " + start); if ((start - m_createTime) >= m_initialWait) { // Pre Check completion // if (log.isDebugEnabled()) log.debug("doWait(initial): wait over, setting complete flag"); completed = true; if (m_isInitial) sync(); m_isInitial = false; notifyAll(); } else {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?