001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.so6.core;
034:
035: import org.libresource.so6.core.engine.log.monitoring.TreeContext;
036: import org.libresource.so6.core.engine.util.XmlUtil;
037:
038: import java.util.Observable;
039: import java.util.logging.Level;
040: import java.util.logging.Logger;
041:
042: /**
043: * @author smack
044: */
045: public class StateMonitoring extends Observable {
046: private static StateMonitoring sm = null;
047: private TreeContext context;
048: private String globalComment;
049: private String localComment;
050: private int criticalPart;
051:
052: private StateMonitoring() {
053: context = new TreeContext();
054: globalComment = "";
055: localComment = "";
056: criticalPart = 0;
057: }
058:
059: public static StateMonitoring getInstance() {
060: if (sm == null) {
061: sm = new StateMonitoring();
062: }
063:
064: return sm;
065: }
066:
067: public TreeContext getContext() {
068: return context;
069: }
070:
071: public String getCurrentGlobalMessage() {
072: return globalComment;
073: }
074:
075: public String getCurrentLocalMessage() {
076: return localComment;
077: }
078:
079: public Logger getXMLMonitoringLogger() {
080: return Logger.getLogger("so6.monitoring.xml");
081: }
082:
083: public void setXMLMonitoringStartCriticalPart() {
084: criticalPart++;
085: setChanged();
086: notifyObservers();
087: StateMonitoring.getInstance().getXMLMonitoringLogger().log(
088: Level.SEVERE, "<CRITICAL_PART/>");
089: }
090:
091: public void setXMLMonitoringStartAction(String action) {
092: criticalPart = 0;
093: setChanged();
094: StateMonitoring.getInstance().getXMLMonitoringLogger().log(
095: Level.SEVERE, "<" + action + ">");
096: notifyObservers();
097: }
098:
099: public void setXMLMonitoringEndAction(String action) {
100: StateMonitoring.getInstance().getXMLMonitoringLogger().log(
101: Level.SEVERE, "</" + action + ">");
102: setChanged();
103: notifyObservers();
104: }
105:
106: public void setXMLMonitoringStartSubCall(int nbCall, String message) {
107: context.startPart(nbCall);
108:
109: if ((message != null) && (message.length() > 0)) {
110: getXMLMonitoringLogger().log(
111: Level.SEVERE,
112: "<SUBCALL nbCall=\"" + nbCall + "\" comment=\""
113: + XmlUtil.replaceInvalideXmlChar(message)
114: + "\">");
115: globalComment = message;
116: } else {
117: getXMLMonitoringLogger().log(Level.SEVERE,
118: "<SUBCALL nbCall=\"" + nbCall + "\">");
119: }
120:
121: setChanged();
122: notifyObservers();
123: }
124:
125: public void setXMLMonitoringEndSubCall() {
126: context.endPart();
127: getXMLMonitoringLogger().log(Level.SEVERE, "</SUBCALL>");
128: }
129:
130: public void setXMLMonitoringComment(String message) {
131: setXMLMonitoringComment(true, message);
132: }
133:
134: public void setXMLMonitoringComment(boolean global, String message) {
135: if (global) {
136: globalComment = message;
137: } else {
138: localComment = message;
139: }
140:
141: getXMLMonitoringLogger().log(
142: Level.SEVERE,
143: "<COMMENT global=\"" + global + "\">"
144: + XmlUtil.replaceInvalideXmlChar(message)
145: + "</COMMENT>");
146: setChanged();
147: notifyObservers();
148: }
149:
150: public void setXMLMonitoringState(long from, long to, long current,
151: String message) {
152: context.setLocalState(from, to, current);
153:
154: if ((message != null) && (message.length() > 0)) {
155: getXMLMonitoringLogger().log(
156: Level.SEVERE,
157: "<STATE from=\"" + from + "\" to=\"" + to
158: + "\" current=\"" + current
159: + "\" comment=\""
160: + XmlUtil.replaceInvalideXmlChar(message)
161: + "\"/>");
162: localComment = message;
163: } else {
164: getXMLMonitoringLogger().log(
165: Level.SEVERE,
166: "<STATE from=\"" + from + "\" to=\"" + to
167: + "\" current=\"" + current + "\"/>");
168: }
169:
170: setChanged();
171: notifyObservers();
172: }
173:
174: public int getCurrentCriticalPartNumber() {
175: return criticalPart;
176: }
177: }
|