📄 polloutagesconfigmanager.java
字号:
return false; Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(time); return isTimeInOutage(cal, out); } /** * Return if time is part of specified outage. * * @param cal * the calendar to lookup * @param out * the outage * * @return true if time is in outage */ public synchronized boolean isTimeInOutage(Calendar cal, Outage out) { Category log = ThreadCategory.getInstance(getClass()); if (log.isDebugEnabled()) log.debug("isTimeInOutage: checking for time '" + cal.getTime() + "' in outage '" + out.getName() + "'"); if (out == null) return false; long curCalTime = cal.getTime().getTime(); // check if day is part of outage boolean inOutage = false; // flag indicating that day(which is optional) was not specified in the // time Enumeration e = out.enumerateTime(); while (e.hasMoreElements() && !inOutage) { Calendar outCalBegin = new GregorianCalendar(); Calendar outCalEnd = new GregorianCalendar(); outCalBegin.setTimeInMillis(curCalTime); outCalEnd.setTimeInMillis(curCalTime); Time oTime = (Time) e.nextElement(); String oTimeDay = oTime.getDay(); String begins = oTime.getBegins(); String ends = oTime.getEnds(); if (oTimeDay != null) { // see if outage time was specified as sunday/monday.. Integer dayInMap = (Integer) m_dayOfWeekMap.get(oTimeDay); if (dayInMap != null) { // check if value specified matches current date if (cal.get(Calendar.DAY_OF_WEEK) == dayInMap.intValue()) inOutage = true; outCalBegin.set(Calendar.DAY_OF_WEEK, dayInMap.intValue()); outCalEnd.set(Calendar.DAY_OF_WEEK, dayInMap.intValue()); } // else see if outage time was specified as day of month else { int intOTimeDay = (new Integer(oTimeDay)).intValue(); if (cal.get(Calendar.DAY_OF_MONTH) == intOTimeDay) inOutage = true; outCalBegin.set(Calendar.DAY_OF_MONTH, intOTimeDay); outCalEnd.set(Calendar.DAY_OF_MONTH, intOTimeDay); } } // if time of day was specified and did not match, continue if (oTimeDay != null && !inOutage) continue; // set time in out calendars setOutCalTime(outCalBegin, begins); setOutCalTime(outCalEnd, ends); // check if calendar passed is in the out cal range if (log.isDebugEnabled()) log.debug("isTimeInOutage: checking begin/end time...\n current: " + cal.getTime() + "\n begin: " + outCalBegin.getTime() + "\n end: " + outCalEnd.getTime()); // round these to the surrounding seconds since we can only specify // this to seconds // accuracy in the config file long outCalBeginTime = outCalBegin.getTime().getTime() / 1000 * 1000; long outCalEndTime = (outCalEnd.getTime().getTime() / 1000 + 1) * 1000; if (curCalTime >= outCalBeginTime && curCalTime < outCalEndTime) inOutage = true; else inOutage = false; } return inOutage; } /** * Return if current time is part of specified outage. * * @param outName * the outage name * * @return true if current time is in outage */ public synchronized boolean isCurTimeInOutage(String outName) { // get current time Calendar cal = new GregorianCalendar(); return isTimeInOutage(cal, outName); } /** * Return if current time is part of specified outage. * * @param out * the outage * * @return true if current time is in outage */ public synchronized boolean isCurTimeInOutage(Outage out) { // get current time Calendar cal = new GregorianCalendar(); return isTimeInOutage(cal, out); } public synchronized void addOutage(Outage newOutage) { m_config.addOutage(newOutage); } public synchronized void removeOutage(String outageName) { m_config.removeOutage(getOutage(outageName)); } public synchronized void removeOutage(Outage outageToRemove) { m_config.removeOutage(outageToRemove); } public synchronized void replaceOutage(Outage oldOutage, Outage newOutage) { int count = m_config.getOutageCount(); for (int i = 0; i < count; i++) { if (m_config.getOutage(i).equals(oldOutage)) { m_config.setOutage(i, newOutage); return; } } } /* * <p>Return the nodes for specified outage</p> * * @param name the outage that is to be looked up * * @return the nodes for the specified outage, null if not found */ public synchronized Node[] getNodeIds(String name) { Outage out = getOutage(name); if (out == null) return null; else return out.getNode(); } /** * <p> * Return if nodeid is part of specified outage * </p> * * @param lnodeid * the nodeid to be looked up * @param outName * the outage name * * @return the node is part of the specified outage */ public synchronized boolean isNodeIdInOutage(long lnodeid, String outName) { Outage out = getOutage(outName); if (out == null) return false; return isNodeIdInOutage(lnodeid, out); } public synchronized Calendar getEndOfOutage(String outName) { Outage out = getOutage(outName); if (out == null) return null; return getEndOfOutage(out); } /** * Return a calendar representing the end time of this outage, assuming it's * currently active (i.e. right now is within one of the time periods) * * FIXME: This code is almost identical to isTimeInOutage... We need to fix * it */ public synchronized Calendar getEndOfOutage(Outage out) { // FIXME: We need one that takes the time as a parm. This makes it more testable long curCalTime = System.currentTimeMillis(); Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(curCalTime); // check if day is part of outage boolean inOutage = false; Enumeration en = out.enumerateTime(); while (en.hasMoreElements() && !inOutage) { Calendar outCalBegin = new GregorianCalendar(); Calendar outCalEnd = new GregorianCalendar(); Time oTime = (Time) en.nextElement(); String oTimeDay = oTime.getDay(); String begins = oTime.getBegins(); String ends = oTime.getEnds(); if (oTimeDay != null) { // see if outage time was specified as sunday/monday.. Integer dayInMap = (Integer) m_dayOfWeekMap.get(oTimeDay); if (dayInMap != null) { // check if value specified matches current date if (cal.get(Calendar.DAY_OF_WEEK) == dayInMap.intValue()) inOutage = true; outCalBegin.set(Calendar.DAY_OF_WEEK, dayInMap.intValue()); outCalEnd.set(Calendar.DAY_OF_WEEK, dayInMap.intValue()); } // else see if outage time was specified as day of month else { int intOTimeDay = (new Integer(oTimeDay)).intValue(); if (cal.get(Calendar.DAY_OF_MONTH) == intOTimeDay) inOutage = true; outCalBegin.set(Calendar.DAY_OF_MONTH, intOTimeDay); outCalEnd.set(Calendar.DAY_OF_MONTH, intOTimeDay); } } // if time of day was specified and did not match, continue if (oTimeDay != null && !inOutage) { continue; } // set time in out calendars setOutCalTime(outCalBegin, begins); setOutCalTime(outCalEnd, ends); long outCalBeginTime = outCalBegin.getTime().getTime() / 1000 * 1000; long outCalEndTime = (outCalEnd.getTime().getTime() / 1000 + 1) * 1000; if (curCalTime >= outCalBeginTime && curCalTime < outCalEndTime) return outCalEnd; } return null; // Couldn't find a time period that matches } /** * <p> * Return if nodeid is part of specified outage * </p> * * @param lnodeid * the nodeid to be looked up * @param outName * the outage * * @return the node iis part of the specified outage */ public synchronized boolean isNodeIdInOutage(long lnodeid, Outage out) { if (out == null) return false; Enumeration en = out.enumerateNode(); while (en.hasMoreElements()) { Node onode = (Node) en.nextElement(); if ((long) onode.getId() == lnodeid) { return true; } } return false; } /** * Saves the current in-memory configuration to disk and reloads */ public synchronized void saveCurrent() throws MarshalException, IOException, ValidationException { // marshall to a string first, then write the string to the file. This // way the original config // isn't lost if the xml from the marshall is hosed. StringWriter stringWriter = new StringWriter(); Marshaller.marshal(m_config, stringWriter); String xmlString = stringWriter.toString(); if (xmlString != null) { saveXML(xmlString); } update(); } abstract protected void saveXML(String xmlString) throws IOException, MarshalException, ValidationException; abstract public void update() throws IOException, MarshalException, ValidationException;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -