Java tutorial
/* Copyright (C) 2009 NTT DATA Corporation 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, version 2. 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. */ package com.clustercontrol.notify.util; import javax.persistence.EntityExistsException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.clustercontrol.fault.NotifyNotFound; import com.clustercontrol.maintenance.util.HinemosPropertyUtil; import com.clustercontrol.notify.bean.OutputBasicInfo; import com.clustercontrol.notify.entity.MonitorStatusPK; import com.clustercontrol.notify.model.MonitorStatusEntity; public class MonitorResultStatusUpdater { /** ? */ private static Log m_log = LogFactory.getLog(MonitorResultStatusUpdater.class); // ??????getLock??? public static Long getCounter(MonitorStatusPK pk) throws NotifyNotFound { Long count = null; MonitorStatusEntity monitorStatus = MonitorStatusCache.get(pk); count = monitorStatus.getCounter(); if (count == null) { m_log.info("getCounter() counter is null. pk=" + pk); } return count; } /** * ?????????????????DB????????? * ????true? * ?????????????DB * ????false? * * @param facilityId ID * @param pluginId ID * @param monitorId ID * @param generateDate ?? * @param currentPriority ?????? * @return ???:true / :false */ private static boolean update(String facilityId, String pluginId, String monitorId, String subkey, Long generateDate, int currentPriority) { m_log.debug("update() facilityId = " + facilityId + ", pluginId = " + pluginId + ", monitorId = " + monitorId + ", subkey = " + subkey + ", generateDate = " + generateDate + ", currentPriority = " + currentPriority); MonitorStatusPK pk = new MonitorStatusPK(facilityId, pluginId, monitorId, subkey); MonitorStatusEntity monitorStatus = MonitorStatusCache.get(pk); if (monitorStatus == null) { m_log.debug("create new entity. " + pk); // ?? try { // ????1?? // ? monitorStatus = new MonitorStatusEntity(facilityId, pluginId, monitorId, subkey); // ?? monitorStatus.setPriority(currentPriority); monitorStatus.setLastUpdate(generateDate); monitorStatus.setCounter(1l); MonitorStatusCache.add(monitorStatus); return true; } catch (EntityExistsException e1) { m_log.info("update() : " + e1.getClass().getSimpleName() + ", " + e1.getMessage()); return true; } } // ???????? if (currentPriority != monitorStatus.getPriority()) { if (m_log.isDebugEnabled()) { m_log.debug("prioityChangeFlag = true. " + pk + " ," + monitorStatus.getPriority() + " to " + currentPriority); } // ?? monitorStatus.setPriority(currentPriority); // ???1? monitorStatus.setCounter(1l); MonitorStatusCache.update(monitorStatus); return true; } else { // ???????? // 50??????? } // ??? long oldCount = monitorStatus.getCounter(); // ???????????????? int maxInitialCount = HinemosPropertyUtil .getHinemosPropertyNum("notify.initial.count.max", Long.valueOf(10)).intValue(); // ?????????DB??update???? if (oldCount <= maxInitialCount) { monitorStatus.setCounter(oldCount + 1); monitorStatus.setLastUpdate(generateDate); MonitorStatusCache.update(monitorStatus); } return false; } public static boolean update(OutputBasicInfo output) { if (output.getSubKey() == null) { m_log.info("SubKey is null. PluginId = " + output.getPluginId() + ", MonitorId = " + output.getMonitorId() + ", FacilityId = " + output.getFacilityId()); output.setSubKey(""); } return update(output.getFacilityId(), output.getPluginId(), output.getMonitorId(), output.getSubKey(), output.getGenerationDate(), output.getPriority()); } }