Author: michiel Date: 2010-05-03 15:40:18 +0200 (Mon, 03 May 2010) New Revision: 42088
Modified: mmbase/trunk/bridge/src/main/java/org/mmbase/core/event/NodeEvent.java mmbase/trunk/core/src/main/java/org/mmbase/core/event/NodeEventHelper.java Log: moved 'map clean up code' from Helper to NodeEvent itself (will target MMB-1850 now) Modified: mmbase/trunk/bridge/src/main/java/org/mmbase/core/event/NodeEvent.java =================================================================== --- mmbase/trunk/bridge/src/main/java/org/mmbase/core/event/NodeEvent.java 2010-05-03 12:46:24 UTC (rev 42087) +++ mmbase/trunk/bridge/src/main/java/org/mmbase/core/event/NodeEvent.java 2010-05-03 13:40:18 UTC (rev 42088) @@ -34,21 +34,51 @@ */ public static final int TYPE_RELATION_CHANGE = 3; + private static final Map<String, Object> EMPTY = Collections.unmodifiableMap(new HashMap<String, Object>()); + private static final Object EMPTIED = null; + + /** + * Removes all non-serializable values, and all values we don't want to serialize (binaries, + * because they are too big). This is put in a new (to not reflect further changes) unmodifiable map and returned. + */ + private static Map<String, Object> values(final Map<String, Object> values) { + Set<String> toremove = new HashSet<String>(); + Map<String, Object> newMap = new HashMap<String, Object>(); + synchronized(values) { + for (Map.Entry<String, Object> entry : values.entrySet()) { + Object value = entry.getValue(); + if (value != null) { + if (value instanceof byte[]) { + toremove.add(entry.getKey()); + } else if (! (value instanceof java.io.Serializable)) { + log.warn("Found non serializable '" + entry.getKey() + "' in " + values); + toremove.add(entry.getKey()); + } + } + } + newMap.putAll(values); + } + for (String k : toremove) { + newMap.put(k, EMPTIED); + } + return Collections.unmodifiableMap(newMap); + } + + private final int nodeNumber; - private String builderName; + private final String builderName; private final Map<String, Object> oldValues; private final Map<String, Object> newValues; - private static final Map<String, Object> EMPTY = Collections.unmodifiableMap(new HashMap<String, Object>()); /** - *...@param machineName (MMBase) name of the server - *...@param builderName name of builder of node event is about - *...@param oldValues map with fields and their values that have been changed by the event. This may be <code>null</code> - *...@param newValues map with new values of changed fields - *...@param eventType the type of event - **/ + * @param machineName (MMBase) name of the server + * @param builderName name of builder of node event is about + * @param oldValues map with fields and their values that have been changed by the event. This may be <code>null</code> + * @param newValues map with new values of changed fields + * @param eventType the type of event + */ public NodeEvent(String machineName, String builderName, int nodeNumber, final Map<String, Object> oldValues, final Map<String, Object> newValues, int eventType ){ super(machineName, eventType); this.builderName = builderName; @@ -56,16 +86,12 @@ if (oldValues == null) { this.oldValues = EMPTY; } else { - synchronized(oldValues) { - this.oldValues = Collections.unmodifiableMap(new HashMap<String, Object>(oldValues)); - } + this.oldValues = values(oldValues); } if (newValues == null) { this.newValues = EMPTY; } else { - synchronized(newValues) { - this.newValues = Collections.unmodifiableMap(new HashMap<String, Object>(newValues)); - } + this.newValues = values(newValues); } } @@ -153,18 +179,6 @@ /** - * I think this method is not needed. - * @deprecated - */ - /* - public NodeEvent clone(String builderName) { - NodeEvent clone = (NodeEvent) super.clone(); - clone.builderName = builderName; - return clone; - } - */ - - /** * For conveneance: conversion of the new event type indication to the old * style * Modified: mmbase/trunk/core/src/main/java/org/mmbase/core/event/NodeEventHelper.java =================================================================== --- mmbase/trunk/core/src/main/java/org/mmbase/core/event/NodeEventHelper.java 2010-05-03 12:46:24 UTC (rev 42087) +++ mmbase/trunk/core/src/main/java/org/mmbase/core/event/NodeEventHelper.java 2010-05-03 13:40:18 UTC (rev 42088) @@ -76,40 +76,7 @@ return new NodeEvent(machineName, node.getBuilder().getTableName(), node.getNumber(), oldEventValues, newEventValues, eventType); } - /** - * Removes all non-serializable values, and all values we don't want to serialize (binaries, - * because they are too big). - */ - private static Map<String, Object> removeNonSerializingValues(Map<String, Object> oldEventValues) { - Set<String> toremove = null; - synchronized(oldEventValues) { - for (Map.Entry<String, Object> entry : oldEventValues.entrySet()) { - Object value = entry.getValue(); - if (value != null) { - if (value instanceof byte[]) { - if (toremove == null) toremove = new HashSet<String>(); - toremove.add(entry.getKey()); - } else if (! (value instanceof java.io.Serializable)) { - log.warn("Found non serializable '" + entry.getKey() + "' in " + oldEventValues); - if (toremove == null) toremove = new HashSet<String>(); - toremove.add(entry.getKey()); - } - } - } - } - if (toremove != null) { - Map<String, Object> newMap = new HashMap<String, Object>(); - newMap.putAll(oldEventValues); - for (String k : toremove) { - newMap.remove(k); - } - return Collections.unmodifiableMap(newMap); - } else { - return oldEventValues; - } - } - public static RelationEvent createRelationEventInstance(Relation node, int eventType, String machineName){ MMObjectNode coreNode = MMBase.getMMBase().getBuilder(node.getNodeManager().getName()).getNode(node.getNumber()); return createRelationEventInstance(coreNode, eventType, machineName); _______________________________________________ Cvs mailing list Cvs@lists.mmbase.org http://lists.mmbase.org/mailman/listinfo/cvs