Mercurial > dive4elements > river
changeset 3554:9b356ed24411
FLYSArtifact: Lowered logging output level from info to debug. Made some more debug outputs conditional.
flys-artifacts/trunk@5148 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sat, 28 Jul 2012 20:58:42 +0000 (2012-07-28) |
parents | 5da58c5c1517 |
children | b1912514e0f5 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java |
diffstat | 2 files changed, 127 insertions(+), 84 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Sat Jul 28 20:38:27 2012 +0000 +++ b/flys-artifacts/ChangeLog Sat Jul 28 20:58:42 2012 +0000 @@ -1,4 +1,10 @@ -2012-07-27 Sascha L. Teichmann <sascha.teichmann@intevation.de> +2012-07-28 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: + Lowered logging output level from info to debug. + Made some more debug outputs conditional. + +2012-07-28 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java: Some code simplifications.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Sat Jul 28 20:38:27 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Sat Jul 28 20:58:42 2012 +0000 @@ -58,7 +58,7 @@ public abstract class FLYSArtifact extends DefaultArtifact { /** The logger that is used in this artifact. */ - private static Logger logger = Logger.getLogger(FLYSArtifact.class); + private static Logger log = Logger.getLogger(FLYSArtifact.class); public static final String COMPUTING_CACHE = "computed.values"; @@ -134,8 +134,12 @@ StateEngine engine = (StateEngine) flysContext.get( FLYSContext.STATE_ENGINE_KEY); + boolean debug = log.isDebugEnabled(); + for (String stateId: stateIds) { - logger.debug("Append static data for state: " + stateId); + if (debug) { + log.debug("Append static data for state: " + stateId); + } DefaultState state = (DefaultState) engine.getState(stateId); ui.appendChild(state.describeStatic(this, doc, ui, context, uuid)); @@ -170,7 +174,11 @@ CallMeta callMeta, Document data) { - logger.debug("Setup this artifact with the uuid: " + identifier); + boolean debug = log.isDebugEnabled(); + + if (debug) { + log.debug("Setup this artifact with the uuid: " + identifier); + } super.setup(identifier, factory, context, callMeta, data); @@ -179,10 +187,13 @@ List<State> states = getStates(context); String name = getName(); - logger.debug("Set initial state for artifact '" + name + "'"); + + if (debug) { + log.debug("Set initial state for artifact '" + name + "'"); + } if (states == null) { - logger.error("No states found from which an initial " + log.error("No states found from which an initial " + "state could be picked."); } setCurrentState(states.get(0)); @@ -200,7 +211,7 @@ initialize(db.getRawArtifact(model), context, callMeta); } catch (ArtifactDatabaseException adbe) { - logger.error(adbe, adbe); + log.error(adbe, adbe); } } @@ -222,14 +233,14 @@ */ protected void importData(FLYSArtifact other, final String name) { if (other == null) { - logger.error("No other art. to import data " + name + " from."); + log.error("No other art. to import data " + name + " from."); return; } StateData sd = other.getData(name); if (sd == null) { - logger.warn("Other artifact has no data " + name + "."); + log.warn("Other artifact has no data " + name + "."); return; } @@ -345,7 +356,7 @@ index = Integer.parseInt(facetElement.getAttribute("index")); } catch (NumberFormatException nfe) { - logger.warn(nfe); + log.warn(nfe); index = 0; } facets.add(new DefaultFacet(index, fName, "")); @@ -370,7 +381,7 @@ */ @Override public Document feed(Document target, CallContext context) { - logger.info("FLYSArtifact.feed()"); + log.debug("FLYSArtifact.feed()"); Document doc = XMLUtils.newDocument(); @@ -410,9 +421,10 @@ */ @Override public Document describe(Document data, CallContext context) { - logger.debug("Describe: the current state is: " + getCurrentStateId()); - if (logger.isDebugEnabled()) { + if (log.isDebugEnabled()) { + log.debug( + "Describe: the current state is: " + getCurrentStateId()); dumpArtifact(); } @@ -529,7 +541,10 @@ String uuid) { List<Output> generated = getOutputs(context); - logger.debug("This Artifact has " + generated.size() + " Outputs."); + + if (log.isDebugEnabled()) { + log.debug("This Artifact has " + generated.size() + " Outputs."); + } ProtocolUtils.appendOutputModes(doc, outs, generated); } @@ -546,6 +561,9 @@ */ @Override public Document advance(Document target, CallContext context) { + + boolean debug = log.isDebugEnabled(); + Document doc = XMLUtils.newDocument(); XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( @@ -559,25 +577,33 @@ String targetState = XMLUtils.xpathString( target, XPATH_ADVANCE_TARGET, ArtifactNamespaceContext.INSTANCE); - logger.info("FLYSArtifact.advance() to '" + targetState + "'"); + if (debug) { + log.debug("FLYSArtifact.advance() to '" + targetState + "'"); + } if (!currentStateId.equals(targetState) && isStateReachable(targetState, context)) { - logger.info("Advance: Step forward"); + if (debug) { + log.debug("Advance: Step forward"); + } List<String> prev = getPreviousStateIds(); prev.add(currentStateId); setCurrentStateId(targetState); - logger.debug("Compute data for state: " + targetState); + if (debug) { + log.debug("Compute data for state: " + targetState); + } compute(context, ComputeType.ADVANCE, true); return describe(target, context); } else if (isPreviousState(targetState, context)) { - logger.info("Advance: Step back to"); + if (debug) { + log.debug("Advance: Step back to"); + } List<String> prevs = getPreviousStateIds(); int targetIdx = prevs.indexOf(targetState); @@ -587,7 +613,9 @@ for (int i = start; i >= targetIdx; i--) { String prev = prevs.get(i); - logger.debug("Remove state id '" + prev + "'"); + if (debug) { + log.debug("Remove state id '" + prev + "'"); + } prevs.remove(prev); facets.remove(prev); @@ -599,7 +627,7 @@ return describe(target, context); } - logger.warn("Advance: Cannot advance to '" + targetState + "'"); + log.warn("Advance: Cannot advance to '" + targetState + "'"); ec.addAttr(result, "type", OPERATION_FAILED, true); doc.appendChild(result); @@ -876,7 +904,7 @@ } } - logger.warn("Could not find facet: " + name + " at " + index); + log.warn("Could not find facet: " + name + " at " + index); return null; } @@ -904,8 +932,13 @@ throw new IllegalArgumentException("error_feed_no_data"); } + boolean debug = log.isDebugEnabled(); + int count = nodes.getLength(); - logger.debug("Try to save " + count + " data items."); + + if (debug) { + log.debug("Try to save " + count + " data items."); + } String uri = ArtifactNamespaceContext.NAMESPACE_URI; @@ -922,7 +955,9 @@ String value = node.getAttributeNS(uri, "value"); if (name.length() > 0 && value.length() > 0) { - logger.debug("Save data item for '" + name + "' : " + value); + if (debug) { + log.debug("Save data item for '" + name + "' : " + value); + } StateData model = engine.getStateData(getName(), name); @@ -934,8 +969,8 @@ name, current.transform(this, context, sd, name, value)); } else if (name.length() > 0 && value.length() == 0) { - if (removeData(name) != null) { - logger.debug("Removed data '" + name + "' successfully."); + if (removeData(name) != null && debug) { + log.debug("Removed data '" + name + "' successfully."); } } } @@ -956,7 +991,10 @@ * otherwise false. */ protected boolean isStateReachable(String stateId, Object context) { - logger.debug("Determine if the state '" + stateId + "' is reachable."); + + if (log.isDebugEnabled()) { + log.debug("Determine if the state '" + stateId + "' is reachable."); + } FLYSContext flysContext = FLYSUtils.getFlysContext(context); @@ -979,7 +1017,9 @@ * @param context The context object. */ protected boolean isPreviousState(String stateId, Object context) { - logger.debug("Determine if the state '" + stateId + "' is old."); + if (log.isDebugEnabled()) { + log.debug("Determine if the state '" + stateId + "' is old."); + } return getPreviousStateIds().contains(stateId); } @@ -1017,14 +1057,14 @@ */ protected List<Output> filterOutputs(List<Output> outs) { if (filterFacets == null || filterFacets.isEmpty()) { - logger.debug("No filter for Outputs."); + log.debug("No filter for Outputs."); return outs; } - boolean debug = logger.isDebugEnabled(); + boolean debug = log.isDebugEnabled(); if (debug) { - logger.debug( + log.debug( "Filter Facets with " + filterFacets.size() + " filters."); } @@ -1034,15 +1074,15 @@ String outName = out.getName(); if (debug) { - logger.debug(" filter Facets for Output: " + outName); + log.debug(" filter Facets for Output: " + outName); } List<Facet> fFacets = filterFacets.get(outName); if (fFacets != null) { if (debug) { - logger.debug("" + fFacets.size() + " filters for: " + outName); + log.debug("" + fFacets.size() + " filters for: " + outName); for (Facet tmp: fFacets) { - logger.debug(" filter = '" + tmp.getName() + "'"); + log.debug(" filter = '" + tmp.getName() + "'"); } } @@ -1059,7 +1099,7 @@ } if (debug) { - logger.debug( + log.debug( "Facets after filtering = " + resultFacets.size()); } @@ -1075,7 +1115,7 @@ } if (debug) { - logger.debug("All Facets after filtering = " + filtered.size()); + log.debug("All Facets after filtering = " + filtered.size()); } return filtered; @@ -1089,12 +1129,11 @@ * @return list of outputs */ public List<Output> getOutputs(Object context) { - if (logger.isDebugEnabled()) { - logger.debug("##### Get Outputs for: " + identifier() + " #####"); + if (log.isDebugEnabled()) { + log.debug("##### Get Outputs for: " + identifier() + " #####"); + dumpArtifact(); } - dumpArtifact(); - List<String> stateIds = getPreviousStateIds(); List<Output> generated = new ArrayList<Output>(); @@ -1135,20 +1174,20 @@ protected List<Output> getOutputForState(DefaultState state) { if (state == null) { - logger.error("state == null: This should not happen!"); + log.error("state == null: This should not happen!"); return new ArrayList<Output>(); } - boolean debug = logger.isDebugEnabled(); + boolean debug = log.isDebugEnabled(); if (debug) { - logger.debug("Find Outputs for State: " + state.getID()); + log.debug("Find Outputs for State: " + state.getID()); } List<Output> list = state.getOutputs(); if (list == null || list.size() == 0) { if (debug) { - logger.debug("-> No output modes for this state."); + log.debug("-> No output modes for this state."); } return new ArrayList<Output>(); } @@ -1159,7 +1198,7 @@ if (fs == null || fs.size() == 0) { if (debug) { - logger.debug("No facets found."); + log.debug("No facets found."); } return new ArrayList<Output>(); } @@ -1167,7 +1206,7 @@ List<Output> gen = generateOutputs(list, fs); if (debug) { - logger.debug("State '" + stateId + "' has " + gen.size() + " outs"); + log.debug("State '" + stateId + "' has " + gen.size() + " outs"); } return gen; @@ -1184,7 +1223,7 @@ protected List<Output> generateOutputs(List<Output> list, List<Facet> fs) { List<Output> generated = new ArrayList<Output>(); - boolean debug = logger.isDebugEnabled(); + boolean debug = log.isDebugEnabled(); for (Output out: list) { Output o = new DefaultOutput( @@ -1197,7 +1236,7 @@ for (Facet f: out.getFacets()) { if (outTypes.add(f.getName()) && debug) { - logger.debug("configured facet " + f); + log.debug("configured facet " + f); } } @@ -1207,7 +1246,7 @@ if (outTypes.contains(type)) { if (debug) { - logger.debug("Add facet " + f); + log.debug("Add facet " + f); } facetAdded = true; o.addFacet(f); @@ -1311,12 +1350,12 @@ if (cache != null) { net.sf.ehcache.Element element = cache.get(key); if (element != null) { - logger.debug("Got computation result from cache."); + log.debug("Got computation result from cache."); old = element.getValue(); } } else { - logger.debug("cache not configured."); + log.debug("cache not configured."); } Object res; @@ -1334,7 +1373,7 @@ } if (cache != null && old != res && res != null) { - logger.debug("Store computation result to cache."); + log.debug("Store computation result to cache."); net.sf.ehcache.Element element = new net.sf.ehcache.Element(key, res); cache.put(element); @@ -1359,58 +1398,56 @@ * Method to dump the artifacts state/data. */ protected void dumpArtifact() { - if (logger.isDebugEnabled()) { - logger.debug("++++++++++++++ DUMP ARTIFACT DATA +++++++++++++++++"); - // Include uuid, type, name - - logger.debug("------ DUMP DATA ------"); - Collection<StateData> allData = data.values(); - - for (StateData d: allData) { - String name = d.getName(); - String value = (String) d.getValue(); - - logger.debug("- " + name + ": " + value); - } + log.debug("++++++++++++++ DUMP ARTIFACT DATA +++++++++++++++++"); + // Include uuid, type, name - logger.debug("------ DUMP PREVIOUS STATES ------"); - List<String> stateIds = getPreviousStateIds(); - - for (String id: stateIds) { - logger.debug("- State: " + id); - } + log.debug("------ DUMP DATA ------"); + Collection<StateData> allData = data.values(); - logger.debug("CURRENT STATE: " + getCurrentStateId()); + for (StateData d: allData) { + String name = d.getName(); + String value = (String) d.getValue(); - debugFacets(); - dumpFilterFacets(); + log.debug("- " + name + ": " + value); + } - logger.debug("++++++++++++++ END ARTIFACT DUMP +++++++++++++++++"); + log.debug("------ DUMP PREVIOUS STATES ------"); + List<String> stateIds = getPreviousStateIds(); + + for (String id: stateIds) { + log.debug("- State: " + id); } + + log.debug("CURRENT STATE: " + getCurrentStateId()); + + debugFacets(); + dumpFilterFacets(); + + log.debug("++++++++++++++ END ARTIFACT DUMP +++++++++++++++++"); } protected void debugFacets() { - logger.debug("######### FACETS #########"); + log.debug("######### FACETS #########"); Set<Map.Entry<String, List<Facet>>> entries = facets.entrySet(); for (Map.Entry<String, List<Facet>> entry: entries) { String out = entry.getKey(); List<Facet> fs = entry.getValue(); for (Facet f: fs) { - logger.debug(" # " + out + " : " + f.getName()); + log.debug(" # " + out + " : " + f.getName()); } } - logger.debug("######## FACETS END ########"); + log.debug("######## FACETS END ########"); } protected void dumpFilterFacets() { - logger.debug("######## FILTER FACETS ########"); + log.debug("######## FILTER FACETS ########"); if (filterFacets == null || filterFacets.isEmpty()) { - logger.debug("No Filter Facets defined."); + log.debug("No Filter Facets defined."); return; } @@ -1419,14 +1456,14 @@ String out = entry.getKey(); List<Facet> filters = entry.getValue(); - logger.debug("There are " + filters.size() + " filters for: " +out); + log.debug("There are " + filters.size() + " filters for: " +out); for (Facet filter: filters) { - logger.debug(" filter: " + filter.getName()); + log.debug(" filter: " + filter.getName()); } } - logger.debug("######## FILTER FACETS END ########"); + log.debug("######## FILTER FACETS END ########"); } @@ -1454,8 +1491,8 @@ */ @Override public void endOfLife(Object context) { - if (logger.isDebugEnabled()) { - logger.debug("FLYSArtifact.endOfLife: " + identifier()); + if (log.isDebugEnabled()) { + log.debug("FLYSArtifact.endOfLife: " + identifier()); } ArrayList<String> ids = (ArrayList<String>) getPreviousStateIds();